Rewrite the find dialog using Qt Designer

Create a Qt Designer form file for the find dialog.

Simplify the find dialog code a little bit.

Add a new comparison operator '<>' in the find dialog.
This commit is contained in:
Martin Kleusberg
2013-01-09 15:45:24 +01:00
parent 95312a6cd3
commit 065cb3682a
8 changed files with 309 additions and 292 deletions

61
src/FindDialog.cpp Normal file
View File

@@ -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();
}

36
src/FindDialog.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef __FINDDIALOG_H__
#define __FINDDIALOG_H__
#include <QDialog>
#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

190
src/FindDialog.ui Normal file
View File

@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FindDialog</class>
<widget class="QDialog" name="FindDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>288</width>
<height>351</height>
</rect>
</property>
<property name="windowTitle">
<string>Find</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="comboColumn">
<property name="toolTip">
<string>Field to be searched</string>
</property>
<property name="whatsThis">
<string>Use this control to select the field to be searched in the current table</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboOperator">
<property name="toolTip">
<string>Search criteria: use 'contains' for partial matches</string>
</property>
<property name="whatsThis">
<string>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.</string>
</property>
<item>
<property name="text">
<string>=</string>
</property>
</item>
<item>
<property name="text">
<string>contains</string>
</property>
</item>
<item>
<property name="text">
<string>&gt;</string>
</property>
</item>
<item>
<property name="text">
<string>&gt;=</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;=</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;</string>
</property>
</item>
<item>
<property name="text">
<string>&lt;&gt;</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="editSearchString">
<property name="toolTip">
<string>Enter values or words to search</string>
</property>
<property name="whatsThis">
<string>This is a place to enter the word or number to be searched in the database</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonSearch">
<property name="toolTip">
<string>Perform the search</string>
</property>
<property name="whatsThis">
<string>This button starts the search process</string>
</property>
<property name="text">
<string>&amp;Search</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableResults">
<property name="whatsThis">
<string>Results of the search will appear in this area. Click on a result to select the corresponding record in the database</string>
</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>
<column>
<property name="text">
<string>Records</string>
</property>
</column>
<column>
<property name="text">
<string>Data</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QLabel" name="labelNumberResults">
<property name="text">
<string>Found: 0</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>comboColumn</tabstop>
<tabstop>comboOperator</tabstop>
<tabstop>editSearchString</tabstop>
<tabstop>buttonSearch</tabstop>
<tabstop>tableResults</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonSearch</sender>
<signal>clicked()</signal>
<receiver>FindDialog</receiver>
<slot>find()</slot>
<hints>
<hint type="sourcelabel">
<x>233</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>267</x>
<y>30</y>
</hint>
</hints>
</connection>
<connection>
<sender>tableResults</sender>
<signal>itemClicked(QTableWidgetItem*)</signal>
<receiver>FindDialog</receiver>
<slot>recordSelected(QTableWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>100</x>
<y>176</y>
</hint>
<hint type="destinationlabel">
<x>86</x>
<y>58</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>find()</slot>
<slot>recordSelected(QTableWidgetItem*)</slot>
</slots>
</ui>

View File

@@ -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();
}

View File

@@ -1,174 +0,0 @@
#ifndef FINDFORM_H
#define FINDFORM_H
#include <QTableWidget>
#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_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<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(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

View File

@@ -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()){

View File

@@ -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();

View File

@@ -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