mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 18:40:13 -06:00
Rewrite the create index dialog
Use Qt Designer for the create index dialog. Change the layout of the create index dialog completely to be easier to use and more powerful. Rewrite most of the index creation code to be easier to understand and more flexible.
This commit is contained in:
97
src/CreateIndexDialog.cpp
Normal file
97
src/CreateIndexDialog.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "CreateIndexDialog.h"
|
||||
#include "ui_CreateIndexDialog.h"
|
||||
#include "sqlitedb.h"
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
CreateIndexDialog::CreateIndexDialog(DBBrowserDB* db, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
pdb(db),
|
||||
ui(new Ui::CreateIndexDialog)
|
||||
{
|
||||
// Create UI
|
||||
ui->setupUi(this);
|
||||
|
||||
// Fill table combobox
|
||||
QList<DBBrowserObject> tables = pdb->objMap.values("table");
|
||||
for(int i=0;i<tables.count();i++)
|
||||
ui->comboTableName->addItem(tables.at(i).getname());
|
||||
}
|
||||
|
||||
CreateIndexDialog::~CreateIndexDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CreateIndexDialog::tableChanged(QString new_table)
|
||||
{
|
||||
// And fill the table again
|
||||
QStringList fields = pdb->getTableFields(new_table);
|
||||
ui->tableIndexColumns->setRowCount(fields.size());
|
||||
for(int i=0;i<fields.size();i++)
|
||||
{
|
||||
// Put the name of the field in the first column
|
||||
QTableWidgetItem* name = new QTableWidgetItem(fields.at(i));
|
||||
name->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
ui->tableIndexColumns->setItem(i, 0, name);
|
||||
|
||||
// Put a checkbox to enable usage in the index of this field in the second column
|
||||
QTableWidgetItem* enabled = new QTableWidgetItem("");
|
||||
enabled->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||
enabled->setCheckState(Qt::Unchecked);
|
||||
ui->tableIndexColumns->setItem(i, 1, enabled);
|
||||
|
||||
// And put a combobox to select the order in which to index the field in the last column
|
||||
QComboBox* order = new QComboBox(this);
|
||||
order->addItem("ASC");
|
||||
order->addItem("DESC");
|
||||
ui->tableIndexColumns->setCellWidget(i, 2, order);
|
||||
}
|
||||
}
|
||||
|
||||
void CreateIndexDialog::checkInput()
|
||||
{
|
||||
ui->editIndexName->setText(ui->editIndexName->text().trimmed());
|
||||
|
||||
bool valid = true;
|
||||
if(ui->editIndexName->text().isEmpty() || ui->editIndexName->text().contains(" "))
|
||||
valid = false;
|
||||
|
||||
int num_columns = 0;
|
||||
for(int i=0;i<ui->tableIndexColumns->rowCount();i++)
|
||||
{
|
||||
if(ui->tableIndexColumns->item(i, 1) && ui->tableIndexColumns->item(i, 1)->data(Qt::CheckStateRole) == Qt::Checked)
|
||||
num_columns++;
|
||||
}
|
||||
if(num_columns == 0)
|
||||
valid = false;
|
||||
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
|
||||
}
|
||||
|
||||
void CreateIndexDialog::accept()
|
||||
{
|
||||
QString sql = QString("CREATE %1 INDEX `%2` ON `%3` (")
|
||||
.arg(ui->checkIndexUnique->isChecked() ? "UNIQUE" : "")
|
||||
.arg(ui->editIndexName->text())
|
||||
.arg(ui->comboTableName->currentText());
|
||||
|
||||
for(int i=0;i<ui->tableIndexColumns->rowCount();i++)
|
||||
{
|
||||
if(ui->tableIndexColumns->item(i, 1)->data(Qt::CheckStateRole) == Qt::Checked)
|
||||
{
|
||||
sql.append(QString("`%1` %2,")
|
||||
.arg(ui->tableIndexColumns->item(i, 0)->text())
|
||||
.arg(qobject_cast<QComboBox*>(ui->tableIndexColumns->cellWidget(i, 2))->currentText()));
|
||||
}
|
||||
}
|
||||
sql.remove(sql.count() - 1, 1); // Remove last comma
|
||||
sql.append(");");
|
||||
|
||||
if(pdb->executeSQL(sql))
|
||||
{
|
||||
QDialog::accept();
|
||||
} else {
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n").arg(pdb->lastErrorMessage));
|
||||
}
|
||||
}
|
||||
29
src/CreateIndexDialog.h
Normal file
29
src/CreateIndexDialog.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __CREATEINDEXDIALOG_H__
|
||||
#define __CREATEINDEXDIALOG_H__
|
||||
|
||||
#include <QDialog>
|
||||
class DBBrowserDB;
|
||||
|
||||
namespace Ui {
|
||||
class CreateIndexDialog;
|
||||
}
|
||||
|
||||
class CreateIndexDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CreateIndexDialog(DBBrowserDB* db, QWidget* parent = 0);
|
||||
~CreateIndexDialog();
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
void tableChanged(QString new_table);
|
||||
void checkInput();
|
||||
|
||||
private:
|
||||
DBBrowserDB* pdb;
|
||||
Ui::CreateIndexDialog* ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
226
src/CreateIndexDialog.ui
Normal file
226
src/CreateIndexDialog.ui
Normal file
@@ -0,0 +1,226 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CreateIndexDialog</class>
|
||||
<widget class="QDialog" name="CreateIndexDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>610</width>
|
||||
<height>342</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Create New Index</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/index_create</normaloff>:/icons/index_create</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelIndexName">
|
||||
<property name="text">
|
||||
<string>&Name</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>editIndexName</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="editIndexName"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="labelIndexColumns">
|
||||
<property name="text">
|
||||
<string>&Columns</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>tableIndexColumns</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QTableWidget" name="tableIndexColumns">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>250</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Column</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Use in Index</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Order</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="labelTableName">
|
||||
<property name="text">
|
||||
<string>&Table</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>comboTableName</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboTableName"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="labelIndexUnique">
|
||||
<property name="text">
|
||||
<string>&Unique</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>checkIndexUnique</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="checkIndexUnique">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>editIndexName</tabstop>
|
||||
<tabstop>comboTableName</tabstop>
|
||||
<tabstop>checkIndexUnique</tabstop>
|
||||
<tabstop>tableIndexColumns</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="icons/icons.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CreateIndexDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>252</x>
|
||||
<y>337</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CreateIndexDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>320</x>
|
||||
<y>337</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>comboTableName</sender>
|
||||
<signal>currentIndexChanged(QString)</signal>
|
||||
<receiver>CreateIndexDialog</receiver>
|
||||
<slot>tableChanged(QString)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>91</x>
|
||||
<y>43</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>236</x>
|
||||
<y>31</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>editIndexName</sender>
|
||||
<signal>textChanged(QString)</signal>
|
||||
<receiver>CreateIndexDialog</receiver>
|
||||
<slot>checkInput()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>429</x>
|
||||
<y>14</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>443</x>
|
||||
<y>39</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>tableIndexColumns</sender>
|
||||
<signal>cellChanged(int,int)</signal>
|
||||
<receiver>CreateIndexDialog</receiver>
|
||||
<slot>checkInput()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>443</x>
|
||||
<y>170</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>566</x>
|
||||
<y>40</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>tableChanged(QString)</slot>
|
||||
<slot>checkInput()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
@@ -1,104 +0,0 @@
|
||||
#include "CreateIndexForm.h"
|
||||
#include <QMessageBox>
|
||||
/*
|
||||
* Constructs a createIndexForm as a child of 'parent', with the
|
||||
* name 'name' and widget flags set to 'f'.
|
||||
*
|
||||
* The dialog will by default be modeless, unless you set 'modal' to
|
||||
* true to construct a modal dialog.
|
||||
*/
|
||||
createIndexForm::createIndexForm(QWidget* parent, Qt::WindowFlags fl)
|
||||
: QDialog(parent, fl)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroys the object and frees any allocated resources
|
||||
*/
|
||||
createIndexForm::~createIndexForm()
|
||||
{
|
||||
// no need to delete child widgets, Qt does it all for us
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the strings of the subwidgets using the current
|
||||
* language.
|
||||
*/
|
||||
void createIndexForm::languageChange()
|
||||
{
|
||||
retranslateUi(this);
|
||||
}
|
||||
|
||||
|
||||
void createIndexForm::tableSelected( const QString & entry )
|
||||
{
|
||||
objectMap::Iterator it;
|
||||
for ( it = mtablemap.begin(); it != mtablemap.end(); ++it ) {
|
||||
QString tname = it.value().getname() ;
|
||||
|
||||
//populate the fields with first table name
|
||||
if ((tname.compare(entry)==0)){
|
||||
comboFields->clear();
|
||||
fieldMap::Iterator fit;
|
||||
fieldMap fmap = it.value().fldmap;
|
||||
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
|
||||
comboFields->addItem( fit.value().getname() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void createIndexForm::confirmCreate()
|
||||
{
|
||||
bool ok = true;
|
||||
QString idxname = indexLineEdit->text();
|
||||
if (idxname.isEmpty()) {
|
||||
ok = false;
|
||||
QMessageBox::information( this, QApplication::applicationName(), "Please select a name for the index" );
|
||||
return;
|
||||
}
|
||||
if (idxname.contains(" ")>0) {
|
||||
ok = false;
|
||||
QMessageBox::warning( this, QApplication::applicationName(), "Spaces are not allowed in the index name" );
|
||||
return;
|
||||
}
|
||||
if (ok){
|
||||
createStatement = "CREATE ";
|
||||
if (comboUnique->currentIndex()==1){
|
||||
createStatement.append("UNIQUE ");
|
||||
}
|
||||
createStatement.append("INDEX `");
|
||||
createStatement.append(indexLineEdit->text());
|
||||
createStatement.append("` ON ");
|
||||
createStatement.append(comboTables->currentText());
|
||||
createStatement.append("(");
|
||||
createStatement.append(comboFields->currentText());
|
||||
createStatement.append(" ");
|
||||
if (comboOrder->currentIndex()==0){
|
||||
createStatement.append("ASC");
|
||||
} else {
|
||||
createStatement.append("DESC");
|
||||
}
|
||||
createStatement.append(");");
|
||||
accept();
|
||||
}
|
||||
}
|
||||
|
||||
void createIndexForm::populateTable(const QList<DBBrowserObject>& rmap)
|
||||
{
|
||||
QList<DBBrowserObject>::ConstIterator it;
|
||||
for ( it = rmap.begin(); it != rmap.end(); ++it ) {
|
||||
comboTables->addItem( (*it).getname() );
|
||||
|
||||
//populate the fields with first table name
|
||||
/*if (it==mtablemap.begin()){
|
||||
fieldMap::Iterator fit;
|
||||
fieldMap fmap = (*it).value().fldmap;
|
||||
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
|
||||
comboFields->addItem( fit.value().getname() );
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
#ifndef CREATEINDEXFORM_H
|
||||
#define CREATEINDEXFORM_H
|
||||
|
||||
#include <QGroupBox>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QSpacerItem>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include "sqlitedb.h"
|
||||
|
||||
class Ui_createIndexForm
|
||||
{
|
||||
public:
|
||||
QVBoxLayout *vboxLayout;
|
||||
QHBoxLayout *hboxLayout;
|
||||
QLabel *textLabel2;
|
||||
QLineEdit *indexLineEdit;
|
||||
QGroupBox *groupBox2;
|
||||
QGridLayout *gridLayout;
|
||||
QVBoxLayout *vboxLayout1;
|
||||
QComboBox *comboTables;
|
||||
QComboBox *comboFields;
|
||||
QComboBox *comboOrder;
|
||||
QComboBox *comboUnique;
|
||||
QVBoxLayout *vboxLayout2;
|
||||
QLabel *textLabel3;
|
||||
QLabel *textLabel4;
|
||||
QLabel *textLabel5;
|
||||
QLabel *textLabel6;
|
||||
QHBoxLayout *hboxLayout1;
|
||||
QSpacerItem *spacer8;
|
||||
QPushButton *buttonCreate;
|
||||
QPushButton *buttonCancel;
|
||||
|
||||
void setupUi(QDialog *createIndexForm)
|
||||
{
|
||||
if (createIndexForm->objectName().isEmpty())
|
||||
createIndexForm->setObjectName(QString::fromUtf8("createIndexForm"));
|
||||
createIndexForm->resize(300, 258);
|
||||
vboxLayout = new QVBoxLayout(createIndexForm);
|
||||
vboxLayout->setSpacing(6);
|
||||
vboxLayout->setContentsMargins(11, 11, 11, 11);
|
||||
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
|
||||
hboxLayout = new QHBoxLayout();
|
||||
hboxLayout->setSpacing(6);
|
||||
hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
|
||||
textLabel2 = new QLabel(createIndexForm);
|
||||
textLabel2->setObjectName(QString::fromUtf8("textLabel2"));
|
||||
textLabel2->setWordWrap(false);
|
||||
|
||||
hboxLayout->addWidget(textLabel2);
|
||||
|
||||
indexLineEdit = new QLineEdit(createIndexForm);
|
||||
indexLineEdit->setObjectName(QString::fromUtf8("indexLineEdit"));
|
||||
|
||||
hboxLayout->addWidget(indexLineEdit);
|
||||
|
||||
|
||||
vboxLayout->addLayout(hboxLayout);
|
||||
|
||||
groupBox2 = new QGroupBox(createIndexForm);
|
||||
groupBox2->setObjectName(QString::fromUtf8("groupBox2"));
|
||||
|
||||
gridLayout = new QGridLayout();
|
||||
groupBox2->setLayout(gridLayout);
|
||||
groupBox2->layout()->setSpacing(6);
|
||||
groupBox2->layout()->setContentsMargins(11, 11, 11, 11);
|
||||
|
||||
gridLayout->setAlignment(Qt::AlignTop);
|
||||
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
|
||||
vboxLayout1 = new QVBoxLayout();
|
||||
vboxLayout1->setSpacing(6);
|
||||
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
|
||||
comboTables = new QComboBox(groupBox2);
|
||||
comboTables->setObjectName(QString::fromUtf8("comboTables"));
|
||||
|
||||
vboxLayout1->addWidget(comboTables);
|
||||
|
||||
comboFields = new QComboBox(groupBox2);
|
||||
comboFields->setObjectName(QString::fromUtf8("comboFields"));
|
||||
|
||||
vboxLayout1->addWidget(comboFields);
|
||||
|
||||
comboOrder = new QComboBox(groupBox2);
|
||||
comboOrder->setObjectName(QString::fromUtf8("comboOrder"));
|
||||
|
||||
vboxLayout1->addWidget(comboOrder);
|
||||
|
||||
comboUnique = new QComboBox(groupBox2);
|
||||
comboUnique->setObjectName(QString::fromUtf8("comboUnique"));
|
||||
|
||||
vboxLayout1->addWidget(comboUnique);
|
||||
|
||||
|
||||
gridLayout->addLayout(vboxLayout1, 0, 1, 1, 1);
|
||||
|
||||
vboxLayout2 = new QVBoxLayout();
|
||||
vboxLayout2->setSpacing(6);
|
||||
vboxLayout2->setObjectName(QString::fromUtf8("vboxLayout2"));
|
||||
textLabel3 = new QLabel(groupBox2);
|
||||
textLabel3->setObjectName(QString::fromUtf8("textLabel3"));
|
||||
textLabel3->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
|
||||
textLabel3->setWordWrap(false);
|
||||
|
||||
vboxLayout2->addWidget(textLabel3);
|
||||
|
||||
textLabel4 = new QLabel(groupBox2);
|
||||
textLabel4->setObjectName(QString::fromUtf8("textLabel4"));
|
||||
textLabel4->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
|
||||
textLabel4->setWordWrap(false);
|
||||
|
||||
vboxLayout2->addWidget(textLabel4);
|
||||
|
||||
textLabel5 = new QLabel(groupBox2);
|
||||
textLabel5->setObjectName(QString::fromUtf8("textLabel5"));
|
||||
textLabel5->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
|
||||
textLabel5->setWordWrap(false);
|
||||
|
||||
vboxLayout2->addWidget(textLabel5);
|
||||
|
||||
textLabel6 = new QLabel(groupBox2);
|
||||
textLabel6->setObjectName(QString::fromUtf8("textLabel6"));
|
||||
textLabel6->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
|
||||
textLabel6->setWordWrap(false);
|
||||
|
||||
vboxLayout2->addWidget(textLabel6);
|
||||
|
||||
|
||||
gridLayout->addLayout(vboxLayout2, 0, 0, 1, 1);
|
||||
|
||||
|
||||
vboxLayout->addWidget(groupBox2);
|
||||
|
||||
hboxLayout1 = new QHBoxLayout();
|
||||
hboxLayout1->setSpacing(6);
|
||||
hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
|
||||
spacer8 = new QSpacerItem(51, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
hboxLayout1->addItem(spacer8);
|
||||
|
||||
buttonCreate = new QPushButton(createIndexForm);
|
||||
buttonCreate->setObjectName(QString::fromUtf8("buttonCreate"));
|
||||
|
||||
hboxLayout1->addWidget(buttonCreate);
|
||||
|
||||
buttonCancel = new QPushButton(createIndexForm);
|
||||
buttonCancel->setObjectName(QString::fromUtf8("buttonCancel"));
|
||||
buttonCancel->setDefault(true);
|
||||
|
||||
hboxLayout1->addWidget(buttonCancel);
|
||||
|
||||
|
||||
vboxLayout->addLayout(hboxLayout1);
|
||||
|
||||
|
||||
retranslateUi(createIndexForm);
|
||||
QObject::connect(buttonCreate, SIGNAL(clicked()), createIndexForm, SLOT(confirmCreate()));
|
||||
QObject::connect(buttonCancel, SIGNAL(clicked()), createIndexForm, SLOT(reject()));
|
||||
QObject::connect(comboTables, SIGNAL(activated(QString)), createIndexForm, SLOT(tableSelected(QString)));
|
||||
|
||||
QMetaObject::connectSlotsByName(createIndexForm);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QDialog *createIndexForm)
|
||||
{
|
||||
createIndexForm->setWindowTitle(QApplication::translate("createIndexForm", "Create Index", 0, QApplication::UnicodeUTF8));
|
||||
textLabel2->setText(QApplication::translate("createIndexForm", "Index name:", 0, QApplication::UnicodeUTF8));
|
||||
indexLineEdit->setText(QString());
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
indexLineEdit->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Enter the name for the new index", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
indexLineEdit->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This area contains the name of the index to be created", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
groupBox2->setTitle(QApplication::translate("createIndexForm", "Define properties:", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
comboTables->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Choose the table to index", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
comboTables->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This control is used to select the table to be indexed. Changing the selected table will automatically update the fields available in the control below", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
comboFields->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Choose the field to be indexed", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
comboFields->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This control specifies the field to be used as an index", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
comboOrder->clear();
|
||||
comboOrder->insertItems(0, QStringList()
|
||||
<< QApplication::translate("createIndexForm", "Ascending", 0, QApplication::UnicodeUTF8)
|
||||
<< QApplication::translate("createIndexForm", "Descending", 0, QApplication::UnicodeUTF8)
|
||||
);
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
comboOrder->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Choose the index order", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
comboOrder->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This option controls the ordering of the index. Ascending is the recommended ordering", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
comboUnique->clear();
|
||||
comboUnique->insertItems(0, QStringList()
|
||||
<< QApplication::translate("createIndexForm", "Allowed", 0, QApplication::UnicodeUTF8)
|
||||
<< QApplication::translate("createIndexForm", "Not allowed", 0, QApplication::UnicodeUTF8)
|
||||
);
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
comboUnique->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Allow duplicate values in the index field", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
#ifndef QT_NO_WHATSTHIS
|
||||
comboUnique->setProperty("whatsThis", QVariant(QApplication::translate("createIndexForm", "This control determines if the indexed field allows duplicate values to be inserted into the database. Attempting to insert a duplicate value in an indexed fiield that does not allow this option will generate an error", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_WHATSTHIS
|
||||
textLabel3->setText(QApplication::translate("createIndexForm", "Table to index:", 0, QApplication::UnicodeUTF8));
|
||||
textLabel4->setText(QApplication::translate("createIndexForm", "Field to index:", 0, QApplication::UnicodeUTF8));
|
||||
textLabel5->setText(QApplication::translate("createIndexForm", "Indexing order:", 0, QApplication::UnicodeUTF8));
|
||||
textLabel6->setText(QApplication::translate("createIndexForm", "Duplicate values:", 0, QApplication::UnicodeUTF8));
|
||||
buttonCreate->setText(QApplication::translate("createIndexForm", "Create", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
buttonCreate->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Create Index", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
buttonCancel->setText(QApplication::translate("createIndexForm", "Cancel", 0, QApplication::UnicodeUTF8));
|
||||
#ifndef QT_NO_TOOLTIP
|
||||
buttonCancel->setProperty("toolTip", QVariant(QApplication::translate("createIndexForm", "Cancel and close dialog box", 0, QApplication::UnicodeUTF8)));
|
||||
#endif // QT_NO_TOOLTIP
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class createIndexForm: public Ui_createIndexForm {};
|
||||
} // namespace Ui
|
||||
|
||||
class createIndexForm : public QDialog, public Ui::createIndexForm
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
createIndexForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window);
|
||||
~createIndexForm();
|
||||
|
||||
objectMap mtablemap;
|
||||
QString createStatement;
|
||||
|
||||
public slots:
|
||||
virtual void tableSelected( const QString & entry );
|
||||
virtual void confirmCreate();
|
||||
virtual void populateTable(const QList<DBBrowserObject> &rmap );
|
||||
|
||||
protected slots:
|
||||
virtual void languageChange();
|
||||
|
||||
};
|
||||
|
||||
#endif // CREATEINDEXFORM_H
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <QStandardItemModel>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QScrollBar>
|
||||
#include "CreateIndexForm.h"
|
||||
#include "CreateIndexDialog.h"
|
||||
#include "DialogAbout.h"
|
||||
#include "EditTableForm.h"
|
||||
#include "EditFieldForm.h"
|
||||
@@ -566,18 +566,11 @@ void MainWindow::createIndex()
|
||||
QMessageBox::information( this, QApplication::applicationName(), "There is no database opened. Please open or create a new database file." );
|
||||
return;
|
||||
}
|
||||
createIndexForm dialog(this);
|
||||
dialog.populateTable(db.objMap.values("table"));
|
||||
CreateIndexDialog dialog(&db, this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
if (!db.executeSQL(dialog.createStatement)){
|
||||
QString error = "Error: could not create the index. Message from database engine: ";
|
||||
error.append(db.lastErrorMessage);
|
||||
QMessageBox::warning( this, QApplication::applicationName(), error );
|
||||
} else {
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
}
|
||||
populateStructure();
|
||||
resetBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
src/src.pro
11
src/src.pro
@@ -14,7 +14,6 @@ HEADERS += \
|
||||
sqlitedb.h \
|
||||
sqlbrowser_util.h \
|
||||
SQLLogDock.h \
|
||||
CreateIndexForm.h \
|
||||
DialogAbout.h \
|
||||
EditFieldForm.h \
|
||||
EditForm.h \
|
||||
@@ -24,14 +23,14 @@ HEADERS += \
|
||||
ImportCSVForm.h \
|
||||
MainWindow.h \
|
||||
PreferencesForm.h \
|
||||
SQLiteSyntaxHighlighter.h
|
||||
SQLiteSyntaxHighlighter.h \
|
||||
CreateIndexDialog.h
|
||||
|
||||
SOURCES += \
|
||||
sqlitedb.cpp \
|
||||
sqlbrowser_util.c \
|
||||
SQLLogDock.cpp \
|
||||
main.cpp \
|
||||
CreateIndexForm.cpp \
|
||||
DialogAbout.cpp \
|
||||
EditFieldForm.cpp \
|
||||
EditForm.cpp \
|
||||
@@ -41,7 +40,8 @@ SOURCES += \
|
||||
ImportCSVForm.cpp \
|
||||
MainWindow.cpp \
|
||||
PreferencesForm.cpp \
|
||||
SQLiteSyntaxHighlighter.cpp
|
||||
SQLiteSyntaxHighlighter.cpp \
|
||||
CreateIndexDialog.cpp
|
||||
|
||||
QMAKE_CXXFLAGS += -DAPP_VERSION=\\\"`cd $$PWD;git log -n1 --format=%h_git`\\\"
|
||||
|
||||
@@ -67,4 +67,5 @@ FORMS += \
|
||||
EditFieldForm.ui \
|
||||
EditTableForm.ui \
|
||||
MainWindow.ui \
|
||||
PreferencesForm.ui
|
||||
PreferencesForm.ui \
|
||||
CreateIndexDialog.ui
|
||||
|
||||
Reference in New Issue
Block a user