From 1ebecbbc9d3a6896b3944654da5551cf4b510e72 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 11 Sep 2015 13:30:24 +0200 Subject: [PATCH] Add option for showing the rowid column See issue #408. This isn't working reliably yet on my system: If you enable the fix restoring the previous settings when going back to a table doesn't work and if you disable it that very way is the only way to change the option. Don't know what's going on there :( --- src/FilterTableHeader.cpp | 7 ++-- src/FilterTableHeader.h | 2 +- src/MainWindow.cpp | 33 ++++++++++++++--- src/MainWindow.h | 4 +++ src/MainWindow.ui | 74 +++++++++++++++++++++++++++------------ 5 files changed, 90 insertions(+), 30 deletions(-) diff --git a/src/FilterTableHeader.cpp b/src/FilterTableHeader.cpp index b7957adc..b3aee5a4 100644 --- a/src/FilterTableHeader.cpp +++ b/src/FilterTableHeader.cpp @@ -63,7 +63,7 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) : setContextMenuPolicy(Qt::CustomContextMenu); } -void FilterTableHeader::generateFilters(int number) +void FilterTableHeader::generateFilters(int number, bool showFirst) { // Delete all the current filter widgets for(int i=0;i < filterWidgets.size(); ++i) @@ -74,7 +74,10 @@ void FilterTableHeader::generateFilters(int number) for(int i=0;i < number; ++i) { FilterLineEdit* l = new FilterLineEdit(this, &filterWidgets, i); - l->setVisible(i>0); // This hides the first input widget which belongs to the hidden rowid column + if(!showFirst && i == 0) // This hides the first input widget which belongs to the hidden rowid column + l->setVisible(false); + else + l->setVisible(true); connect(l, SIGNAL(textChanged(QString)), this, SLOT(inputChanged(QString))); filterWidgets.push_back(l); } diff --git a/src/FilterTableHeader.h b/src/FilterTableHeader.h index b5edd00e..8e170ba3 100644 --- a/src/FilterTableHeader.h +++ b/src/FilterTableHeader.h @@ -17,7 +17,7 @@ public: virtual QSize sizeHint() const; public slots: - void generateFilters(int number); + void generateFilters(int number, bool showFirst = false); void adjustPositions(); void clearFilters(); void setFilter(int column, const QString& value); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index b85997f5..fe2e27ae 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -122,6 +122,7 @@ void MainWindow::init() ui->actionSqlSaveFilePopup->setMenu(popupSaveSqlFileMenu); popupBrowseDataHeaderMenu = new QMenu(this); + popupBrowseDataHeaderMenu->addAction(ui->actionShowRowidColumn); popupBrowseDataHeaderMenu->addAction(ui->actionBrowseTableEditDisplayFormat); // Add menu item for log dock @@ -366,16 +367,16 @@ void MainWindow::populateTable(const QString& tablename) else m_browseTableModel->setTable(tablename, v); } - ui->dataTable->setColumnHidden(0, true); - - // Update the filter row - qobject_cast(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount()); // Restore table settings if(storedDataFound) { // There is information stored for this table, so extract it and apply it + // Show rowid column. Needs to be done before the column widths setting because of the workaround in there and before the filter setting + // because of the filter row generation. + showRowidColumn(tableIt.value().showRowid); + // Column widths for(QMap::ConstIterator widthIt=tableIt.value().columnWidths.constBegin();widthIt!=tableIt.value().columnWidths.constEnd();++widthIt) ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value()); @@ -391,6 +392,9 @@ void MainWindow::populateTable(const QString& tablename) } else { // There aren't any information stored for this table yet, so use some default values + // Hide rowid column. Needs to be done before the column widths setting because of the workaround in there + showRowidColumn(false); + // Column widths for(int i=1;icolumnCount();i++) ui->dataTable->setColumnWidth(i, ui->dataTable->horizontalHeader()->defaultSectionSize()); @@ -1957,6 +1961,7 @@ bool MainWindow::loadProject(QString filename) populateTable(ui->comboBrowseTable->currentText()); // Refresh view ui->dataTable->sortByColumn(browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderIndex, browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderMode); + showRowidColumn(browseTableSettings[ui->comboBrowseTable->currentText()].showRowid); xml.skipCurrentElement(); } } @@ -2287,3 +2292,23 @@ void MainWindow::editDataColumnDisplayFormat() populateTable(current_table); } } + +void MainWindow::showRowidColumn(bool show) +{ + // FIXME: Workaround for actually getting the next line to work reliably + //ui->dataTable->setModel(0); + //ui->dataTable->setModel(m_browseTableModel); + + // Show/hide rowid column + ui->dataTable->setColumnHidden(0, !show); + + // Update checked status of the popup menu action + ui->actionShowRowidColumn->setChecked(show); + + // Save settings for this table + QString current_table = ui->comboBrowseTable->currentText(); + browseTableSettings[current_table].showRowid = show; + + // Update the filter row + qobject_cast(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount(), show); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 924b7f6d..e9f02313 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -39,6 +39,7 @@ public: QMap columnWidths; QMap filterValues; QMap displayFormats; + bool showRowid; friend QDataStream& operator<<(QDataStream& stream, const MainWindow::BrowseDataTableSettings& object) { @@ -47,6 +48,7 @@ public: stream << object.columnWidths; stream << object.filterValues; stream << object.displayFormats; + stream << object.showRowid; return stream; } @@ -59,6 +61,7 @@ public: stream >> object.columnWidths; stream >> object.filterValues; stream >> object.displayFormats; + stream >> object.showRowid; return stream; } @@ -214,6 +217,7 @@ private slots: void on_comboPointShape_currentIndexChanged(int index); void showDataColumnPopupMenu(const QPoint& pos); void editDataColumnDisplayFormat(); + void showRowidColumn(bool show); }; #endif diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 6e4fbc6f..cf00550b 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -324,8 +324,8 @@ 0 0 - 509 - 458 + 514 + 579 @@ -810,7 +810,7 @@ 0 0 1037 - 19 + 29 @@ -908,7 +908,7 @@ QDockWidget::AllDockWidgetFeatures - SQL Log + SQL &Log 2 @@ -920,7 +920,7 @@ - &Show SQL submitted by + Show S&QL submitted by comboLogSubmittedBy @@ -1000,7 +1000,7 @@ QDockWidget::AllDockWidgetFeatures - Plot + &Plot 2 @@ -1254,7 +1254,7 @@ - DB Schema + DB Sche&ma 2 @@ -1339,7 +1339,7 @@ :/icons/db_revert:/icons/db_revert - Revert Changes + &Revert Changes Revert database to last saved state @@ -1357,7 +1357,7 @@ :/icons/db_save:/icons/db_save - Write Changes + &Write Changes Write changes to the database file @@ -1374,7 +1374,7 @@ false - Compact Database + Compact &Database Compact the database file, removing space wasted by deleted records @@ -1399,7 +1399,7 @@ - Database from SQL file... + &Database from SQL file... Import data from an .sql dump text file into a new or existing database. @@ -1410,7 +1410,7 @@ - Table from CSV file... + &Table from CSV file... Open a wizard that lets you import data from a comma separated text file into a database table. @@ -1421,7 +1421,7 @@ - Database to SQL file... + &Database to SQL file... Export a database to a .sql dump text file. @@ -1432,7 +1432,7 @@ - Table(s) as CSV file... + &Table(s) as CSV file... Export a database table as a comma separated text file. @@ -1450,7 +1450,7 @@ :/icons/table_create:/icons/table_create - Create Table... + &Create Table... Open the Create Table wizard, where it is possible to define the name and fields for a new table in the database @@ -1465,7 +1465,7 @@ :/icons/table_delete:/icons/table_delete - Delete Table... + &Delete Table... Delete Table @@ -1483,7 +1483,7 @@ :/icons/table_modify:/icons/table_modify - Modify Table... + &Modify Table... Open the Modify Table wizard, where it is possible to rename an existing table. It is also possible to add or delete fields form a table, as well as modify field names and types. @@ -1498,7 +1498,7 @@ :/icons/index_create:/icons/index_create - Create Index... + Create &Index... Open the Create Index wizard, where it is possible to define a new index on an existing database table. @@ -1539,7 +1539,7 @@ :/icons/whatis:/icons/whatis - What's This? + W&hat's This? Shift+F1 @@ -1612,7 +1612,7 @@ :/icons/load_extension:/icons/load_extension - Load extension + &Load extension @@ -1674,7 +1674,7 @@ :/icons/project_save:/icons/project_save - Save Project + Sa&ve Project Save the current session to a file @@ -1689,7 +1689,7 @@ :/icons/project_open:/icons/project_open - Open Project + Open &Project Load a working session from a file @@ -1712,7 +1712,7 @@ :/icons/encryption:/icons/encryption - Set Encryption + &Set Encryption @@ -1768,6 +1768,17 @@ Edit the display format of the data in this column + + + true + + + Show rowid column + + + Toggle the visibility of the rowid column + + @@ -2707,6 +2718,22 @@ + + actionShowRowidColumn + triggered(bool) + MainWindow + showRowidColumn(bool) + + + -1 + -1 + + + 518 + 314 + + + fileOpen() @@ -2764,5 +2791,6 @@ copyCurrentCreateStatement() jumpToRow(QString,QString,QByteArray) editDataColumnDisplayFormat() + showRowidColumn(bool)