From f623a62036102e9e9c75f551d304fa3d7da99f54 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Tue, 1 Jan 2013 15:32:50 +0100 Subject: [PATCH] Always show all rows in table view of browse tab Always show all rows of the current table in the browse tab of the main window instead of limiting it to a 1000 per page. Change the functionality of the buttons and inputs to change the page accordingly. Limiting the number of rows to a 1000 was probably done for performance reasons but is a killer in terms of usability. And as we'll probably move sooner or later to a model-view architecture that loads data on demand, the performance when opening large tables will be more than restored anyway. --- src/mainwindow.cpp | 116 ++++++++++++++------------------------------- src/mainwindow.h | 4 +- src/mainwindow.ui | 2 +- 3 files changed, 38 insertions(+), 84 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4a88f343..683061b3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "createtableform.h" #include "createindexform.h" #include "deletetableform.h" @@ -66,6 +67,7 @@ void MainWindow::setupUi() // Connect some more signals and slots connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int))); connect(ui->sqlLogAction, SIGNAL(toggled(bool)), logWin, SLOT(setVisible(bool))); + connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel())); } /* @@ -96,17 +98,13 @@ MainWindow::~MainWindow() void MainWindow::init() { - findWin = 0; editWin = 0; clipboard = QApplication::clipboard(); - recsPerView = 1000; - recAtTop = 0; gotoValidator = new QIntValidator(0, 0, this); ui->editGoto->setValidator(gotoValidator); - gotoValidator->setRange ( 0, 0); resetBrowser(); this->setWindowTitle(QApplication::applicationName()); this->setWindowIcon( QPixmap( g_applicationIconName ) ); @@ -274,7 +272,6 @@ void MainWindow::populateTable( const QString & tablename, bool keepColumnWidths } if (mustreset){ - recAtTop = 0; updateTableView(0, keepColumnWidths); if (findWin) findWin->resetFields(db.getTableFields(db.curBrowseTableName)); } else { @@ -293,7 +290,6 @@ void MainWindow::populateTable( const QString & tablename, bool keepColumnWidths void MainWindow::resetBrowser() { - recAtTop = 0; QString sCurrentTable = ui->comboBrowseTable->currentText(); ui->comboBrowseTable->clear(); QStringList tab = db.getTableNames(); @@ -355,8 +351,7 @@ void MainWindow::addRecord() if (db.addRecord()){ populateTable(db.curBrowseTableName); //added record will be the last one in view - recAtTop = ((db.getRecordCount()-1)/recsPerView)*recsPerView; - updateTableView(db.getRecordCount()-recAtTop-1); + updateTableView(db.getRecordCount()-1); }else{ QMessageBox::information( this, QApplication::applicationName(), "Error adding record, make sure a table is selected.\n\n" @@ -371,7 +366,7 @@ void MainWindow::deleteRecord() { if (ui->dataTable->currentRow()!=-1){ int lastselected = ui->dataTable->currentRow(); - db.deleteRecord(ui->dataTable->currentRow()+recAtTop); + db.deleteRecord(ui->dataTable->currentRow()); populateTable(db.curBrowseTableName); int nextselected = lastselected ; if (nextselected > db.getRecordCount()){ @@ -405,42 +400,29 @@ QString wrapText(const QString& text) void MainWindow::updateTableView(int lineToSelect, bool keepColumnWidths) { - // qDebug("line to select value is %d, rowAttop = %d",lineToSelect, recAtTop); QApplication::setOverrideCursor( Qt::WaitCursor ); - ui->dataTable->setRowCount(0); + ui->dataTable->setRowCount(db.getRecordCount()); ui->dataTable->setColumnCount( db.browseFields.count() ); ui->dataTable->setHorizontalHeaderLabels(db.browseFields); rowList tab = db.browseRecs; int maxRecs = db.getRecordCount(); - int recsThisView = maxRecs - recAtTop; + gotoValidator->setRange(0, maxRecs); - if (recsThisView>recsPerView) - recsThisView = recsPerView; - - // qDebug("recsthisview= %d\n",recsThisView); - - ui->dataTable->setRowCount(recsThisView); - - if ( recsThisView > 0 ) { + if ( maxRecs > 0 ) { int rowNum = 0; int colNum = 0; - //int dcols =0; QString rowLabel; - for (int i = recAtTop; i < tab.size(); ++i) - //for ( int = tab.at(recAtTop); rt !=tab.end(); ++rt ) + for (int i = 0; i < tab.size(); ++i) { - rowLabel.setNum(recAtTop+rowNum+1); + rowLabel.setNum(rowNum+1); ui->dataTable->setVerticalHeaderItem(rowNum, new QTableWidgetItem( rowLabel )); colNum = 0; QStringList& rt = tab[i]; for (int e = 1; e < rt.size(); ++e) - //for ( QStringList::Iterator it = (*rt).begin(); it != (*rt).end(); ++it ) { - //skip first one (the rowid) - // if (it!=(*rt).begin()){ QString& content = rt[e]; QTableWidgetItem* item = new QTableWidgetItem(content); @@ -448,12 +430,10 @@ void MainWindow::updateTableView(int lineToSelect, bool keepColumnWidths) item->setToolTip(wrapText(content)); ui->dataTable->setItem( rowNum, colNum, item); colNum++; - //} } rowNum++; - if (rowNum==recsThisView) break; + if (rowNum==maxRecs) break; } - } if(!keepColumnWidths) { @@ -464,9 +444,7 @@ void MainWindow::updateTableView(int lineToSelect, bool keepColumnWidths) ui->dataTable->setColumnWidth(i, 400); } } - //dataTable->clearSelection(true); if (lineToSelect!=-1){ - //qDebug("inside selection"); selectTableLine(lineToSelect); } setRecordsetLabel(); @@ -483,22 +461,19 @@ void MainWindow::selectTableLine(int lineToSelect) void MainWindow::navigatePrevious() { - int nextFirstRec = recAtTop - recsPerView; - if (nextFirstRec >= 0 ) { - recAtTop = nextFirstRec; - updateTableView(-1); - } + int curRow = ui->dataTable->currentRow(); + curRow -= 100; + if(curRow < 0) curRow = 0; + updateTableView(curRow); } void MainWindow::navigateNext() { - int nextFirstRec = recAtTop + recsPerView; - //qDebug("called navigatenext, nextFirstRec=%d\n",nextFirstRec); - if (nextFirstRec < db.getRecordCount() ) { - recAtTop = nextFirstRec; - updateTableView(-1); - } + int curRow = ui->dataTable->currentRow(); + curRow += 100; + if(curRow >= ui->dataTable->rowCount()) curRow = ui->dataTable->rowCount()-1; + updateTableView(curRow); } @@ -510,43 +485,19 @@ void MainWindow::navigateGoto() if (dec==0) dec=1; if (dec>db.getRecordCount()) dec = db.getRecordCount(); - recAtTop = ((dec-1)/recsPerView)*recsPerView; - updateTableView(dec-recAtTop-1); + updateTableView(dec-1); ui->editGoto->setText(QString::number(dec,10)); } void MainWindow::setRecordsetLabel() { - if (db.getRecordCount()==0){ - ui->labelRecordset->setText("0 - 0 of 0"); - } else { - QString label = QString::number(recAtTop+1,10); - label.append(" - "); - int lastrec = db.getRecordCount(); - int lastthisview = recAtTop+recsPerView; - if (lastthisview > lastrec) lastthisview = lastrec; - label.append(QString::number(lastthisview,10)); - label.append(" of "); - label.append(QString::number(db.getRecordCount(),10)); - ui->labelRecordset->setText(label); - } - gotoValidator->setRange ( 0, db.getRecordCount()); + int from = ui->dataTable->verticalHeader()->visualIndexAt(0) + 1; + int to = ui->dataTable->verticalHeader()->visualIndexAt(ui->dataTable->height()) - 1; + int total = ui->dataTable->rowCount(); + if(to == -2) + to = total; - if (db.getRecordCount()>1000){ - if (recAtTop>=1000) { - ui->buttonPrevious->setEnabled(TRUE); - } else { - ui->buttonPrevious->setEnabled(FALSE); - } - if (db.getRecordCount()>=(recAtTop+1000)) { - ui->buttonNext->setEnabled(TRUE); - } else { - ui->buttonNext->setEnabled(FALSE); - } - } else { - ui->buttonNext->setEnabled(FALSE); - ui->buttonPrevious->setEnabled(FALSE); - } + ui->labelRecordset->setText(QString("%1 - %2 of %3").arg(from).arg(to).arg(total)); } void MainWindow::browseFind(bool open) @@ -627,8 +578,7 @@ void MainWindow::lookfor( const QString & wfield, const QString & woperator, con void MainWindow::showrecord( int dec ) { - recAtTop = ((dec-1)/recsPerView)*recsPerView; - updateTableView(dec-recAtTop-1); + updateTableView(dec); } void MainWindow::createTable() @@ -890,7 +840,7 @@ void MainWindow::updateRecordText(int row, int col, QString newtext) QTableWidgetItem* item = new QTableWidgetItem(cv); item->setToolTip( wrapText(cv) ); - ui->dataTable->setItem( row - recAtTop, col, item); + ui->dataTable->setItem(row, col, item); } @@ -903,7 +853,7 @@ void MainWindow::editWinAway() { editWin->hide(); activateWindow(); - ui->dataTable->setRangeSelected( QTableWidgetSelectionRange(editWin->curRow - recAtTop, editWin->curCol, editWin->curRow- recAtTop, editWin->curCol), true); + ui->dataTable->setRangeSelected( QTableWidgetSelectionRange(editWin->curRow, editWin->curCol, editWin->curRow, editWin->curCol), true); } @@ -927,7 +877,7 @@ void MainWindow::doubleClickTable( int row, int col ) return; } - int realRow = row + recAtTop; + int realRow = row; editText(realRow , col); } @@ -1426,7 +1376,8 @@ void MainWindow::activateFields(bool enable) ui->editModifyTableAction->setEnabled(enable); ui->editCreateIndexAction->setEnabled(enable); ui->editDeleteIndexAction->setEnabled(enable); - + ui->buttonNext->setEnabled(enable); + ui->buttonPrevious->setEnabled(enable); ui->executeQueryButton->setEnabled(enable); } @@ -1441,3 +1392,8 @@ void MainWindow::browseTableHeaderClicked(int logicalindex) // we might try to select the last selected item ui->dataTable->setCurrentCell(0, logicalindex); } + +void MainWindow::resizeEvent(QResizeEvent*) +{ + setRecordsetLabel(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 28cb2960..ac73089e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -48,8 +48,6 @@ public: editForm * editWin; QClipboard * clipboard; findForm * findWin; - int recAtTop; - int recsPerView; QIntValidator * gotoValidator; QString defaultlocation; @@ -122,9 +120,9 @@ public slots: protected: DBBrowserDB db; -protected: void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); + void resizeEvent(QResizeEvent *event); protected slots: virtual void deleteTablePopup(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 5b3a2188..20869f66 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -267,7 +267,7 @@ Type a record number in this area and click the Go to: button to display the record in the database view - 0 + 1