Skip to content

Commit 1ebecbb

Browse files
committed
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 :(
1 parent b22a9cf commit 1ebecbb

File tree

5 files changed

+90
-30
lines changed

5 files changed

+90
-30
lines changed

src/FilterTableHeader.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) :
6363
setContextMenuPolicy(Qt::CustomContextMenu);
6464
}
6565

66-
void FilterTableHeader::generateFilters(int number)
66+
void FilterTableHeader::generateFilters(int number, bool showFirst)
6767
{
6868
// Delete all the current filter widgets
6969
for(int i=0;i < filterWidgets.size(); ++i)
@@ -74,7 +74,10 @@ void FilterTableHeader::generateFilters(int number)
7474
for(int i=0;i < number; ++i)
7575
{
7676
FilterLineEdit* l = new FilterLineEdit(this, &filterWidgets, i);
77-
l->setVisible(i>0); // This hides the first input widget which belongs to the hidden rowid column
77+
if(!showFirst && i == 0) // This hides the first input widget which belongs to the hidden rowid column
78+
l->setVisible(false);
79+
else
80+
l->setVisible(true);
7881
connect(l, SIGNAL(textChanged(QString)), this, SLOT(inputChanged(QString)));
7982
filterWidgets.push_back(l);
8083
}

src/FilterTableHeader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FilterTableHeader : public QHeaderView
1717
virtual QSize sizeHint() const;
1818

1919
public slots:
20-
void generateFilters(int number);
20+
void generateFilters(int number, bool showFirst = false);
2121
void adjustPositions();
2222
void clearFilters();
2323
void setFilter(int column, const QString& value);

src/MainWindow.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void MainWindow::init()
122122
ui->actionSqlSaveFilePopup->setMenu(popupSaveSqlFileMenu);
123123

124124
popupBrowseDataHeaderMenu = new QMenu(this);
125+
popupBrowseDataHeaderMenu->addAction(ui->actionShowRowidColumn);
125126
popupBrowseDataHeaderMenu->addAction(ui->actionBrowseTableEditDisplayFormat);
126127

127128
// Add menu item for log dock
@@ -366,16 +367,16 @@ void MainWindow::populateTable(const QString& tablename)
366367
else
367368
m_browseTableModel->setTable(tablename, v);
368369
}
369-
ui->dataTable->setColumnHidden(0, true);
370-
371-
// Update the filter row
372-
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount());
373370

374371
// Restore table settings
375372
if(storedDataFound)
376373
{
377374
// There is information stored for this table, so extract it and apply it
378375

376+
// Show rowid column. Needs to be done before the column widths setting because of the workaround in there and before the filter setting
377+
// because of the filter row generation.
378+
showRowidColumn(tableIt.value().showRowid);
379+
379380
// Column widths
380381
for(QMap<int, int>::ConstIterator widthIt=tableIt.value().columnWidths.constBegin();widthIt!=tableIt.value().columnWidths.constEnd();++widthIt)
381382
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
@@ -391,6 +392,9 @@ void MainWindow::populateTable(const QString& tablename)
391392
} else {
392393
// There aren't any information stored for this table yet, so use some default values
393394

395+
// Hide rowid column. Needs to be done before the column widths setting because of the workaround in there
396+
showRowidColumn(false);
397+
394398
// Column widths
395399
for(int i=1;i<m_browseTableModel->columnCount();i++)
396400
ui->dataTable->setColumnWidth(i, ui->dataTable->horizontalHeader()->defaultSectionSize());
@@ -1957,6 +1961,7 @@ bool MainWindow::loadProject(QString filename)
19571961
populateTable(ui->comboBrowseTable->currentText()); // Refresh view
19581962
ui->dataTable->sortByColumn(browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderIndex,
19591963
browseTableSettings[ui->comboBrowseTable->currentText()].sortOrderMode);
1964+
showRowidColumn(browseTableSettings[ui->comboBrowseTable->currentText()].showRowid);
19601965
xml.skipCurrentElement();
19611966
}
19621967
}
@@ -2287,3 +2292,23 @@ void MainWindow::editDataColumnDisplayFormat()
22872292
populateTable(current_table);
22882293
}
22892294
}
2295+
2296+
void MainWindow::showRowidColumn(bool show)
2297+
{
2298+
// FIXME: Workaround for actually getting the next line to work reliably
2299+
//ui->dataTable->setModel(0);
2300+
//ui->dataTable->setModel(m_browseTableModel);
2301+
2302+
// Show/hide rowid column
2303+
ui->dataTable->setColumnHidden(0, !show);
2304+
2305+
// Update checked status of the popup menu action
2306+
ui->actionShowRowidColumn->setChecked(show);
2307+
2308+
// Save settings for this table
2309+
QString current_table = ui->comboBrowseTable->currentText();
2310+
browseTableSettings[current_table].showRowid = show;
2311+
2312+
// Update the filter row
2313+
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount(), show);
2314+
}

src/MainWindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MainWindow : public QMainWindow
3939
QMap<int, int> columnWidths;
4040
QMap<int, QString> filterValues;
4141
QMap<int, QString> displayFormats;
42+
bool showRowid;
4243

4344
friend QDataStream& operator<<(QDataStream& stream, const MainWindow::BrowseDataTableSettings& object)
4445
{
@@ -47,6 +48,7 @@ class MainWindow : public QMainWindow
4748
stream << object.columnWidths;
4849
stream << object.filterValues;
4950
stream << object.displayFormats;
51+
stream << object.showRowid;
5052

5153
return stream;
5254
}
@@ -59,6 +61,7 @@ class MainWindow : public QMainWindow
5961
stream >> object.columnWidths;
6062
stream >> object.filterValues;
6163
stream >> object.displayFormats;
64+
stream >> object.showRowid;
6265

6366
return stream;
6467
}
@@ -214,6 +217,7 @@ private slots:
214217
void on_comboPointShape_currentIndexChanged(int index);
215218
void showDataColumnPopupMenu(const QPoint& pos);
216219
void editDataColumnDisplayFormat();
220+
void showRowidColumn(bool show);
217221
};
218222

219223
#endif

src/MainWindow.ui

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@
324324
<rect>
325325
<x>0</x>
326326
<y>0</y>
327-
<width>509</width>
328-
<height>458</height>
327+
<width>514</width>
328+
<height>579</height>
329329
</rect>
330330
</property>
331331
<layout class="QFormLayout" name="formLayout">
@@ -810,7 +810,7 @@
810810
<x>0</x>
811811
<y>0</y>
812812
<width>1037</width>
813-
<height>19</height>
813+
<height>29</height>
814814
</rect>
815815
</property>
816816
<widget class="QMenu" name="fileMenu">
@@ -908,7 +908,7 @@
908908
<set>QDockWidget::AllDockWidgetFeatures</set>
909909
</property>
910910
<property name="windowTitle">
911-
<string>SQL Log</string>
911+
<string>SQL &amp;Log</string>
912912
</property>
913913
<attribute name="dockWidgetArea">
914914
<number>2</number>
@@ -920,7 +920,7 @@
920920
<item>
921921
<widget class="QLabel" name="labelLogSubmittedBy">
922922
<property name="text">
923-
<string>&amp;Show SQL submitted by</string>
923+
<string>Show S&amp;QL submitted by</string>
924924
</property>
925925
<property name="buddy">
926926
<cstring>comboLogSubmittedBy</cstring>
@@ -1000,7 +1000,7 @@
10001000
<set>QDockWidget::AllDockWidgetFeatures</set>
10011001
</property>
10021002
<property name="windowTitle">
1003-
<string>Plot</string>
1003+
<string>&amp;Plot</string>
10041004
</property>
10051005
<attribute name="dockWidgetArea">
10061006
<number>2</number>
@@ -1254,7 +1254,7 @@
12541254
</widget>
12551255
<widget class="QDockWidget" name="dockSchema">
12561256
<property name="windowTitle">
1257-
<string>DB Schema</string>
1257+
<string>DB Sche&amp;ma</string>
12581258
</property>
12591259
<attribute name="dockWidgetArea">
12601260
<number>2</number>
@@ -1339,7 +1339,7 @@
13391339
<normaloff>:/icons/db_revert</normaloff>:/icons/db_revert</iconset>
13401340
</property>
13411341
<property name="text">
1342-
<string>Revert Changes</string>
1342+
<string>&amp;Revert Changes</string>
13431343
</property>
13441344
<property name="toolTip">
13451345
<string>Revert database to last saved state</string>
@@ -1357,7 +1357,7 @@
13571357
<normaloff>:/icons/db_save</normaloff>:/icons/db_save</iconset>
13581358
</property>
13591359
<property name="text">
1360-
<string>Write Changes</string>
1360+
<string>&amp;Write Changes</string>
13611361
</property>
13621362
<property name="toolTip">
13631363
<string>Write changes to the database file</string>
@@ -1374,7 +1374,7 @@
13741374
<bool>false</bool>
13751375
</property>
13761376
<property name="text">
1377-
<string>Compact Database</string>
1377+
<string>Compact &amp;Database</string>
13781378
</property>
13791379
<property name="toolTip">
13801380
<string>Compact the database file, removing space wasted by deleted records</string>
@@ -1399,7 +1399,7 @@
13991399
</action>
14001400
<action name="fileImportSQLAction">
14011401
<property name="text">
1402-
<string>Database from SQL file...</string>
1402+
<string>&amp;Database from SQL file...</string>
14031403
</property>
14041404
<property name="toolTip">
14051405
<string>Import data from an .sql dump text file into a new or existing database.</string>
@@ -1410,7 +1410,7 @@
14101410
</action>
14111411
<action name="fileImportCSVAction">
14121412
<property name="text">
1413-
<string>Table from CSV file...</string>
1413+
<string>&amp;Table from CSV file...</string>
14141414
</property>
14151415
<property name="toolTip">
14161416
<string>Open a wizard that lets you import data from a comma separated text file into a database table.</string>
@@ -1421,7 +1421,7 @@
14211421
</action>
14221422
<action name="fileExportSQLAction">
14231423
<property name="text">
1424-
<string>Database to SQL file...</string>
1424+
<string>&amp;Database to SQL file...</string>
14251425
</property>
14261426
<property name="toolTip">
14271427
<string>Export a database to a .sql dump text file.</string>
@@ -1432,7 +1432,7 @@
14321432
</action>
14331433
<action name="fileExportCSVAction">
14341434
<property name="text">
1435-
<string>Table(s) as CSV file...</string>
1435+
<string>&amp;Table(s) as CSV file...</string>
14361436
</property>
14371437
<property name="toolTip">
14381438
<string>Export a database table as a comma separated text file.</string>
@@ -1450,7 +1450,7 @@
14501450
<normaloff>:/icons/table_create</normaloff>:/icons/table_create</iconset>
14511451
</property>
14521452
<property name="text">
1453-
<string>Create Table...</string>
1453+
<string>&amp;Create Table...</string>
14541454
</property>
14551455
<property name="whatsThis">
14561456
<string>Open the Create Table wizard, where it is possible to define the name and fields for a new table in the database</string>
@@ -1465,7 +1465,7 @@
14651465
<normaloff>:/icons/table_delete</normaloff>:/icons/table_delete</iconset>
14661466
</property>
14671467
<property name="text">
1468-
<string>Delete Table...</string>
1468+
<string>&amp;Delete Table...</string>
14691469
</property>
14701470
<property name="toolTip">
14711471
<string>Delete Table</string>
@@ -1483,7 +1483,7 @@
14831483
<normaloff>:/icons/table_modify</normaloff>:/icons/table_modify</iconset>
14841484
</property>
14851485
<property name="text">
1486-
<string>Modify Table...</string>
1486+
<string>&amp;Modify Table...</string>
14871487
</property>
14881488
<property name="whatsThis">
14891489
<string>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.</string>
@@ -1498,7 +1498,7 @@
14981498
<normaloff>:/icons/index_create</normaloff>:/icons/index_create</iconset>
14991499
</property>
15001500
<property name="text">
1501-
<string>Create Index...</string>
1501+
<string>Create &amp;Index...</string>
15021502
</property>
15031503
<property name="whatsThis">
15041504
<string>Open the Create Index wizard, where it is possible to define a new index on an existing database table.</string>
@@ -1539,7 +1539,7 @@
15391539
<normaloff>:/icons/whatis</normaloff>:/icons/whatis</iconset>
15401540
</property>
15411541
<property name="text">
1542-
<string>What's This?</string>
1542+
<string>W&amp;hat's This?</string>
15431543
</property>
15441544
<property name="shortcut">
15451545
<string>Shift+F1</string>
@@ -1612,7 +1612,7 @@
16121612
<normaloff>:/icons/load_extension</normaloff>:/icons/load_extension</iconset>
16131613
</property>
16141614
<property name="text">
1615-
<string>Load extension</string>
1615+
<string>&amp;Load extension</string>
16161616
</property>
16171617
</action>
16181618
<action name="actionSqlExecuteLine">
@@ -1674,7 +1674,7 @@
16741674
<normaloff>:/icons/project_save</normaloff>:/icons/project_save</iconset>
16751675
</property>
16761676
<property name="text">
1677-
<string>Save Project</string>
1677+
<string>Sa&amp;ve Project</string>
16781678
</property>
16791679
<property name="toolTip">
16801680
<string>Save the current session to a file</string>
@@ -1689,7 +1689,7 @@
16891689
<normaloff>:/icons/project_open</normaloff>:/icons/project_open</iconset>
16901690
</property>
16911691
<property name="text">
1692-
<string>Open Project</string>
1692+
<string>Open &amp;Project</string>
16931693
</property>
16941694
<property name="toolTip">
16951695
<string>Load a working session from a file</string>
@@ -1712,7 +1712,7 @@
17121712
<normaloff>:/icons/encryption</normaloff>:/icons/encryption</iconset>
17131713
</property>
17141714
<property name="text">
1715-
<string>Set Encryption</string>
1715+
<string>&amp;Set Encryption</string>
17161716
</property>
17171717
</action>
17181718
<action name="actionSqlSaveFileAs">
@@ -1768,6 +1768,17 @@
17681768
<string>Edit the display format of the data in this column</string>
17691769
</property>
17701770
</action>
1771+
<action name="actionShowRowidColumn">
1772+
<property name="checkable">
1773+
<bool>true</bool>
1774+
</property>
1775+
<property name="text">
1776+
<string>Show rowid column</string>
1777+
</property>
1778+
<property name="toolTip">
1779+
<string>Toggle the visibility of the rowid column</string>
1780+
</property>
1781+
</action>
17711782
</widget>
17721783
<customwidgets>
17731784
<customwidget>
@@ -2707,6 +2718,22 @@
27072718
</hint>
27082719
</hints>
27092720
</connection>
2721+
<connection>
2722+
<sender>actionShowRowidColumn</sender>
2723+
<signal>triggered(bool)</signal>
2724+
<receiver>MainWindow</receiver>
2725+
<slot>showRowidColumn(bool)</slot>
2726+
<hints>
2727+
<hint type="sourcelabel">
2728+
<x>-1</x>
2729+
<y>-1</y>
2730+
</hint>
2731+
<hint type="destinationlabel">
2732+
<x>518</x>
2733+
<y>314</y>
2734+
</hint>
2735+
</hints>
2736+
</connection>
27102737
</connections>
27112738
<slots>
27122739
<slot>fileOpen()</slot>
@@ -2764,5 +2791,6 @@
27642791
<slot>copyCurrentCreateStatement()</slot>
27652792
<slot>jumpToRow(QString,QString,QByteArray)</slot>
27662793
<slot>editDataColumnDisplayFormat()</slot>
2794+
<slot>showRowidColumn(bool)</slot>
27672795
</slots>
27682796
</ui>

0 commit comments

Comments
 (0)