From 41ec2f6f840a766f89fa8d402c058a86f7386414 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Wed, 9 Jan 2013 01:20:30 +0100 Subject: [PATCH] Fix half a dozen bugs concerning the find dialog Fix bug that caused invalid rows in the result table view. This could happen because the rowid of the search result was used as the row number in the table widget, too. Every rowid, however, is basically a random number and to address the rows in the table widget you need continuos numbers. Fix bug that made it impossible to click on any column but the first one in the result table widget. Clicking on a column in the data column lead to wrong rows being highlighted because exactly that text was used that the user clicked on instead of taking the text of the first column of the row the user clicked on. Make it impossible for the user to edit the cells of the search result table widget. Editing these not just only makes no sense at all but can also lead to wrong rows being selected in the main window when the rowid in the first column was changed. Fix bug that caused the wrong row to be selected in the main window. When the table view in the find dialog is populated the rowid shown is increased by one for every search result. This is fair enough but then this modified row number needs to be changed back before selecting it. Not doing so leads to always selecting row right after the intendet one. Fix bug when searching for entries containing a number in some field. This was caused because the search string was changed to be surrounded by %-signs as you'd expect when doing a containing-search. However, the check wether we're searching for a number or not was done on the old string. So checking for a number was positive even though the program would actually search for a string. This way the string was not put into '...'-signs, leading to a malformed SQL statement. Clear all input widgets as well as the result table widget when (re)opening the find dialog. This may be less comfortable in some situations but at least is a bit more consequent because the column combo box was reset anyway. --- src/FindForm.cpp | 19 +++++++++++-------- src/FindForm.h | 1 + src/MainWindow.cpp | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/FindForm.cpp b/src/FindForm.cpp index f02634f7..04bcc730 100644 --- a/src/FindForm.cpp +++ b/src/FindForm.cpp @@ -36,11 +36,13 @@ void findForm::showResults(resultMap rmap) findTableWidget->clearContents(); findTableWidget->setSortingEnabled(false); resultMap::Iterator it; + int rowNum; findTableWidget->setRowCount(rmap.size()); - for ( it = rmap.begin(); it != rmap.end(); ++it ) { - QString firstline = it.value().section( '\n', 0,0 ); - findTableWidget->setItem( it.key(), 0, new QTableWidgetItem( QString::number(it.key() + 1) ) ); - findTableWidget->setItem( it.key(), 1, new QTableWidgetItem( firstline) ); + 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())); @@ -58,6 +60,9 @@ void findForm::resetFields(QStringList fieldlist) { findFieldCombobox->clear(); findFieldCombobox->addItems(fieldlist); + searchLine->setText(""); + findOperatorComboBox->setCurrentIndex(0); + findTableWidget->setRowCount(0); } void findForm::resetResults() @@ -70,8 +75,8 @@ void findForm::resetResults() void findForm::recordSelected( QTableWidgetItem * witem) { if (witem) { - int recNum = witem->text().toInt(); - emit showrecord(recNum); + int recNum = findTableWidget->item(witem->row(), 0)->text().toInt(); + emit showrecord(recNum - 1); } } @@ -79,5 +84,3 @@ void findForm::closeEvent( QCloseEvent * ) { emit goingAway(); } - - diff --git a/src/FindForm.h b/src/FindForm.h index facc7883..f8f12e2c 100644 --- a/src/FindForm.h +++ b/src/FindForm.h @@ -68,6 +68,7 @@ public: 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); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index abc66170..e1d06758 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -524,8 +524,8 @@ void MainWindow::lookfor( const QString & wfield, const QString & woperator, con statement.append(" "); //searchterm needs to be quoted if it is not a number bool ok = false; - wsearchterm.toDouble(&ok); - if (!ok) wsearchterm.toInt(&ok, 10); + finalsearchterm.toDouble(&ok); + if (!ok) finalsearchterm.toInt(&ok, 10); if (!ok) {//not a number, quote it char * formSQL = sqlite3_mprintf("%Q",(const char *) finalsearchterm.toUtf8()); statement.append(formSQL);