diff --git a/src/FindDialog.cpp b/src/FindDialog.cpp new file mode 100644 index 00000000..897282b7 --- /dev/null +++ b/src/FindDialog.cpp @@ -0,0 +1,61 @@ +#include "FindDialog.h" +#include "ui_FindDialog.h" + +FindDialog::FindDialog(QWidget* parent) + : QDialog(parent), + ui(new Ui::FindDialog) +{ + ui->setupUi(this); +} + +FindDialog::~FindDialog() +{ + delete ui; +} + +void FindDialog::showResults(resultMap rmap) +{ + ui->tableResults->setSortingEnabled(false); + ui->tableResults->clearContents(); + resultMap::Iterator it; + int rowNum; + ui->tableResults->setRowCount(rmap.size()); + for(it=rmap.begin(),rowNum=0;it!=rmap.end();++it,rowNum++) + { + QString firstline = it.value().section('\n', 0, 0); + ui->tableResults->setItem(rowNum, 0, new QTableWidgetItem(QString::number(it.key() + 1))); + ui->tableResults->setItem(rowNum, 1, new QTableWidgetItem(firstline)); + } + QString results = tr("Found: %1").arg(ui->tableResults->rowCount()); + ui->labelNumberResults->setText(results); + ui->tableResults->setSortingEnabled(true); +} + +void FindDialog::find() +{ + emit lookfor(ui->comboColumn->currentText(), ui->comboOperator->currentText(), ui->editSearchString->text()); +} + +void FindDialog::resetFields(QStringList fieldlist) +{ + ui->comboColumn->clear(); + ui->comboColumn->addItems(fieldlist); + ui->editSearchString->setText(""); + ui->comboOperator->setCurrentIndex(0); + ui->tableResults->clearContents(); + ui->labelNumberResults->setText("Found: 0"); +} + +void FindDialog::recordSelected(QTableWidgetItem* witem) +{ + if(witem) + { + int recNum = ui->tableResults->item(witem->row(), 0)->text().toInt(); + emit showrecord(recNum - 1); + } +} + +void FindDialog::closeEvent(QCloseEvent*) +{ + emit goingAway(); +} diff --git a/src/FindDialog.h b/src/FindDialog.h new file mode 100644 index 00000000..84e44352 --- /dev/null +++ b/src/FindDialog.h @@ -0,0 +1,36 @@ +#ifndef __FINDDIALOG_H__ +#define __FINDDIALOG_H__ + +#include +#include "sqlitedb.h" +class QTableWidgetItem; + +namespace Ui { +class FindDialog; +} + +class FindDialog : public QDialog +{ + Q_OBJECT + +public: + FindDialog(QWidget* parent = 0); + ~FindDialog(); + +public slots: + virtual void showResults(resultMap rmap); + virtual void find(); + virtual void resetFields(QStringList fieldlist = QStringList()); + virtual void recordSelected(QTableWidgetItem* witem); + virtual void closeEvent(QCloseEvent*); + +signals: + void lookfor(const QString&, const QString&, const QString&); + void showrecord(int); + void goingAway(); + +private: + Ui::FindDialog* ui; +}; + +#endif diff --git a/src/FindDialog.ui b/src/FindDialog.ui new file mode 100644 index 00000000..f8ea3885 --- /dev/null +++ b/src/FindDialog.ui @@ -0,0 +1,190 @@ + + + FindDialog + + + + 0 + 0 + 288 + 351 + + + + Find + + + + + + + + Field to be searched + + + Use this control to select the field to be searched in the current table + + + + + + + Search criteria: use 'contains' for partial matches + + + This control is used to select the search criteria used to look for the search term in the database. Use '=' or 'contains' to find words, and the comparison symbols to filter numeric data. + + + + = + + + + + contains + + + + + > + + + + + >= + + + + + <= + + + + + < + + + + + <> + + + + + + + + + + + + Enter values or words to search + + + This is a place to enter the word or number to be searched in the database + + + + + + + Perform the search + + + This button starts the search process + + + &Search + + + true + + + + + + + + + Results of the search will appear in this area. Click on a result to select the corresponding record in the database + + + QAbstractItemView::NoEditTriggers + + + false + + + true + + + QAbstractItemView::NoSelection + + + + Records + + + + + Data + + + + + + + + Found: 0 + + + + + + + comboColumn + comboOperator + editSearchString + buttonSearch + tableResults + + + + + buttonSearch + clicked() + FindDialog + find() + + + 233 + 45 + + + 267 + 30 + + + + + tableResults + itemClicked(QTableWidgetItem*) + FindDialog + recordSelected(QTableWidgetItem*) + + + 100 + 176 + + + 86 + 58 + + + + + + find() + recordSelected(QTableWidgetItem*) + + diff --git a/src/FindForm.cpp b/src/FindForm.cpp deleted file mode 100644 index 04bcc730..00000000 --- a/src/FindForm.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "FindForm.h" - -/* - * Constructs a findForm 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. - */ -findForm::findForm(QWidget* parent, Qt::WindowFlags fl) - : QDialog(parent, fl) -{ - setupUi(this); - -} - -/* - * Destroys the object and frees any allocated resources - */ -findForm::~findForm() -{ - // no need to delete child widgets, Qt does it all for us -} - -/* - * Sets the strings of the subwidgets using the current - * language. - */ -void findForm::languageChange() -{ - retranslateUi(this); -} - -void findForm::showResults(resultMap rmap) -{ - findTableWidget->clearContents(); - findTableWidget->setSortingEnabled(false); - resultMap::Iterator it; - int rowNum; - findTableWidget->setRowCount(rmap.size()); - for(it=rmap.begin(),rowNum=0;it!=rmap.end();++it,rowNum++) - { - QString firstline = it.value().section('\n', 0, 0); - findTableWidget->setItem(rowNum, 0, new QTableWidgetItem(QString::number(it.key() + 1))); - findTableWidget->setItem(rowNum, 1, new QTableWidgetItem(firstline)); - } - QString results = "Found: "; - results.append(QString::number(findTableWidget->rowCount())); - resultsLabel->setText(results); - findTableWidget->setSortingEnabled(true); -} - - -void findForm::find() -{ - emit lookfor( findFieldCombobox->currentText(), findOperatorComboBox->currentText(),searchLine->text() ); -} - -void findForm::resetFields(QStringList fieldlist) -{ - findFieldCombobox->clear(); - findFieldCombobox->addItems(fieldlist); - searchLine->setText(""); - findOperatorComboBox->setCurrentIndex(0); - findTableWidget->setRowCount(0); -} - -void findForm::resetResults() -{ - findTableWidget->clearContents(); - resultsLabel->setText("Found: 0"); -} - - -void findForm::recordSelected( QTableWidgetItem * witem) -{ - if (witem) { - int recNum = findTableWidget->item(witem->row(), 0)->text().toInt(); - emit showrecord(recNum - 1); - } -} - -void findForm::closeEvent( QCloseEvent * ) -{ - emit goingAway(); -} diff --git a/src/FindForm.h b/src/FindForm.h deleted file mode 100644 index f8f12e2c..00000000 --- a/src/FindForm.h +++ /dev/null @@ -1,174 +0,0 @@ -#ifndef FINDFORM_H -#define FINDFORM_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sqlitedb.h" - -class Ui_findForm -{ -public: - QVBoxLayout *vboxLayout; - QGridLayout *gridLayout; - QPushButton *searchButton; - QComboBox *findFieldCombobox; - QLineEdit *searchLine; - QComboBox *findOperatorComboBox; - QTableWidget *findTableWidget; - QHBoxLayout *hboxLayout; - QLabel *resultsLabel; - QSpacerItem *spacer10; - - void setupUi(QDialog *findForm) - { - if (findForm->objectName().isEmpty()) - findForm->setObjectName(QString::fromUtf8("findForm")); - findForm->resize(239, 319); - vboxLayout = new QVBoxLayout(findForm); - vboxLayout->setSpacing(6); - vboxLayout->setContentsMargins(11, 11, 11, 11); - vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); - gridLayout = new QGridLayout(); - gridLayout->setSpacing(6); - gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - searchButton = new QPushButton(findForm); - searchButton->setObjectName(QString::fromUtf8("searchButton")); - - gridLayout->addWidget(searchButton, 1, 2, 1, 1); - - findFieldCombobox = new QComboBox(findForm); - findFieldCombobox->setObjectName(QString::fromUtf8("findFieldCombobox")); - - gridLayout->addWidget(findFieldCombobox, 0, 0, 1, 1); - - searchLine = new QLineEdit(findForm); - searchLine->setObjectName(QString::fromUtf8("searchLine")); - - gridLayout->addWidget(searchLine, 1, 0, 1, 2); - - findOperatorComboBox = new QComboBox(findForm); - findOperatorComboBox->setObjectName(QString::fromUtf8("findOperatorComboBox")); - - gridLayout->addWidget(findOperatorComboBox, 0, 1, 1, 2); - - - vboxLayout->addLayout(gridLayout); - - findTableWidget = new QTableWidget(findForm); - findTableWidget->setColumnCount(2); - findTableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem( QObject::tr("Record") )); - findTableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem( QObject::tr("Data") )); - findTableWidget->setObjectName(QString::fromUtf8("findListView")); - findTableWidget->setMidLineWidth(30); - findTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); - //findTableWidget->setResizePolicy(Q3ScrollView::Manual); - //findTableWidget->setResizeMode(Q3ListView::LastColumn); - - vboxLayout->addWidget(findTableWidget); - - hboxLayout = new QHBoxLayout(); - hboxLayout->setSpacing(6); - hboxLayout->setObjectName(QString::fromUtf8("hboxLayout")); - resultsLabel = new QLabel(findForm); - resultsLabel->setObjectName(QString::fromUtf8("resultsLabel")); - QSizePolicy sizePolicy(static_cast(7), static_cast(5)); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(resultsLabel->sizePolicy().hasHeightForWidth()); - resultsLabel->setSizePolicy(sizePolicy); - resultsLabel->setWordWrap(false); - - hboxLayout->addWidget(resultsLabel); - - spacer10 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - - hboxLayout->addItem(spacer10); - - - vboxLayout->addLayout(hboxLayout); - - - retranslateUi(findForm); - QObject::connect(searchButton, SIGNAL(clicked()), findForm, SLOT(find())); - QObject::connect(findTableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), findForm, SLOT(recordSelected(QTableWidgetItem*))); - - QMetaObject::connectSlotsByName(findForm); - } // setupUi - - void retranslateUi(QDialog *findForm) - { - findForm->setWindowTitle(QObject::tr("Find")); - searchButton->setText(QObject::tr("Search")); - searchButton->setProperty("toolTip", QVariant(QObject::tr("Perform the search"))); - searchButton->setProperty("whatsThis", QVariant(QObject::tr("This button starts the search process"))); - - findFieldCombobox->clear(); - findFieldCombobox->insertItems(0, QStringList() - << QObject::tr("user") - ); - findFieldCombobox->setProperty("toolTip", QVariant(QObject::tr("Field to be searched"))); - findFieldCombobox->setProperty("whatsThis", QVariant(QObject::tr("Use this control to select the field to be searched in the current table"))); - - searchLine->setProperty("toolTip", QVariant(QObject::tr("Enter values or words to search"))); - searchLine->setProperty("whatsThis", QVariant(QObject::tr("This is a place to enter the word or number to be searched in the database"))); - - findOperatorComboBox->clear(); - findOperatorComboBox->insertItems(0, QStringList() - << QObject::tr("=") - << QObject::tr("contains") - << QObject::tr(">") - << QObject::tr(">=") - << QObject::tr("<=") - << QObject::tr("<") - ); - findOperatorComboBox->setProperty("toolTip", QVariant(QObject::tr("Search criteria: use 'contains' for partial matches"))); - findOperatorComboBox->setProperty("whatsThis", QVariant(QObject::tr("This control is used to select the search criteria used to look for the search term in the database. Use '=' or 'contains' to find words, and the comparison symbols to filter numeric data."))); - - findTableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem( QObject::tr("Record") )); - findTableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem( QObject::tr("Data") )); - findTableWidget->setProperty("whatsThis", QVariant(QObject::tr("Results of the search will appear in this area. Click on a result to select the corresponding record in the database"))); - - resultsLabel->setText(QObject::tr("Found:")); - } // retranslateUi - -}; - -namespace Ui { - class findForm: public Ui_findForm {}; -} // namespace Ui - -class findForm : public QDialog, public Ui::findForm -{ - Q_OBJECT - -public: - findForm(QWidget* parent = 0, Qt::WindowFlags fl = Qt::Window); - ~findForm(); - -public slots: - virtual void showResults( resultMap rmap ); - virtual void find(); - virtual void resetFields( QStringList fieldlist ); - virtual void resetResults(); - virtual void recordSelected( QTableWidgetItem * witem ); - virtual void closeEvent( QCloseEvent * ); - -signals: - void lookfor(const QString&, const QString&, const QString&); - void showrecord(int); - void goingAway(); - -protected slots: - virtual void languageChange(); - -}; - -#endif // FINDFORM_H diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 515fbe93..ec0e39e4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -19,7 +19,7 @@ #include "ExportTableCSVForm.h" #include "PreferencesDialog.h" #include "EditForm.h" -#include "FindForm.h" +#include "FindDialog.h" #include "SQLLogDock.h" #include "SQLiteSyntaxHighlighter.h" @@ -237,10 +237,8 @@ void MainWindow::populateTable( const QString & tablename, bool keepColumnWidths ui->dataTable->setRowCount( 0 ); ui->dataTable->setColumnCount( 0 ); QApplication::restoreOverrideCursor(); - if (findWin){ + if(findWin) findWin->resetFields(db.getTableFields("")); - findWin->resetResults(); - } return; } @@ -257,13 +255,10 @@ void MainWindow::populateTable( const QString & tablename, bool keepColumnWidths updateTableView(-1, keepColumnWidths); } //got to keep findWin in synch - if (findWin){ - findWin->resetResults(); - } - if (editWin) - { + if(findWin) + findWin->resetFields(); + if(editWin) editWin->reset(); - } QApplication::restoreOverrideCursor(); } @@ -484,20 +479,20 @@ void MainWindow::setRecordsetLabel() void MainWindow::browseFind(bool open) { - if (open){ - if ( ! findWin ) { - findWin= new findForm( this ); - connect( findWin, SIGNAL( lookfor(const QString&, const QString&, const QString&) ), - this, SLOT( lookfor(const QString&, const QString&, const QString&) ) ); - connect( findWin, SIGNAL( showrecord(int) ),this, SLOT( showrecord(int) ) ); - connect( findWin, SIGNAL( goingAway() ),this, SLOT( browseFindAway() ) ); + if(open) + { + if(!findWin) + { + findWin = new FindDialog(this); + connect(findWin, SIGNAL(lookfor(const QString&, const QString&, const QString&)), this, SLOT(lookfor(const QString&, const QString&, const QString&))); + connect(findWin, SIGNAL(showrecord(int)),this, SLOT(updateTableView(int))); + connect(findWin, SIGNAL(goingAway()),this, SLOT(browseFindAway())); } findWin->resetFields(db.getTableFields(db.curBrowseTableName)); findWin->show(); } else { - if (findWin){ + if(findWin) findWin->hide(); - } } } @@ -557,11 +552,6 @@ void MainWindow::lookfor( const QString & wfield, const QString & woperator, con QApplication::restoreOverrideCursor(); } -void MainWindow::showrecord( int dec ) -{ - updateTableView(dec); -} - void MainWindow::createTable() { if (!db.isOpen()){ diff --git a/src/MainWindow.h b/src/MainWindow.h index 02ee0815..1e5c3010 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -10,7 +10,7 @@ class QDragEnterEvent; class SQLLogDock; class editForm; -class findForm; +class FindDialog; class SQLiteSyntaxHighlighter; class QStandardItemModel; class QIntValidator; @@ -47,7 +47,7 @@ public: editForm * editWin; QClipboard * clipboard; - findForm * findWin; + FindDialog* findWin; QIntValidator * gotoValidator; QString defaultlocation; @@ -87,7 +87,6 @@ public slots: virtual void browseFindAway(); virtual void browseRefresh(); virtual void lookfor( const QString & wfield, const QString & woperator, const QString & wsearchterm ); - virtual void showrecord( int dec ); virtual void createTable(); virtual void createIndex(); virtual void compact(); diff --git a/src/src.pro b/src/src.pro index 871426f7..3792f709 100644 --- a/src/src.pro +++ b/src/src.pro @@ -16,7 +16,6 @@ HEADERS += \ SQLLogDock.h \ EditForm.h \ ExportTableCSVForm.h \ - FindForm.h \ ImportCSVForm.h \ MainWindow.h \ SQLiteSyntaxHighlighter.h \ @@ -24,7 +23,8 @@ HEADERS += \ EditFieldDialog.h \ AboutDialog.h \ EditTableDialog.h \ - PreferencesDialog.h + PreferencesDialog.h \ + FindDialog.h SOURCES += \ sqlitedb.cpp \ @@ -33,7 +33,6 @@ SOURCES += \ main.cpp \ EditForm.cpp \ ExportTableCSVForm.cpp \ - FindForm.cpp \ ImportCSVForm.cpp \ MainWindow.cpp \ SQLiteSyntaxHighlighter.cpp \ @@ -41,7 +40,8 @@ SOURCES += \ EditFieldDialog.cpp \ EditTableDialog.cpp \ PreferencesDialog.cpp \ - AboutDialog.cpp + AboutDialog.cpp \ + FindDialog.cpp QMAKE_CXXFLAGS += -DAPP_VERSION=\\\"`cd $$PWD;git log -n1 --format=%h_git`\\\" @@ -68,4 +68,5 @@ FORMS += \ AboutDialog.ui \ EditFieldDialog.ui \ EditTableDialog.ui \ - PreferencesDialog.ui + PreferencesDialog.ui \ + FindDialog.ui