Skip to content

Commit 5e1169b

Browse files
committed
MainWindow: Keep column widths for each table in Browse Data tab
Store the column widths of the table view widget for each table/view individually and restore them when changing back to the table/view.
1 parent 2aaf734 commit 5e1169b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/MainWindow.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void MainWindow::init()
116116
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), this, SLOT(setRecordsetLabel()));
117117
connect(ui->dataTable->filterHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
118118
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
119+
connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(updateBrowseDataColumnWidth(int,int,int)));
119120
connect(editWin, SIGNAL(goingAway()), this, SLOT(editWinAway()));
120121
connect(editWin, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
121122
connect(ui->dbTreeWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changeTreeSelection()));
@@ -293,6 +294,19 @@ void MainWindow::populateTable( const QString & tablename)
293294
m_browseTableModel->setTable(tablename);
294295
ui->dataTable->setColumnHidden(0, true);
295296

297+
// Restore column widths
298+
QMap<QString, QMap<int, int> >::ConstIterator colWidthsIt;
299+
if((colWidthsIt = browseTableColumnWidths.constFind(tablename)) != browseTableColumnWidths.constEnd())
300+
{
301+
// There are some column widths stored for this table
302+
for(QMap<int, int>::ConstIterator it=colWidthsIt.value().constBegin();it!=colWidthsIt.value().constEnd();++it)
303+
ui->dataTable->setColumnWidth(it.key(), it.value());
304+
} else {
305+
// There aren't any column widths stored for this table yet, so set default widths
306+
for(int i=1;i<m_browseTableModel->columnCount();i++)
307+
ui->dataTable->setColumnWidth(i, ui->dataTable->horizontalHeader()->defaultSectionSize());
308+
}
309+
296310
// Reset sorting
297311
curBrowseOrderByIndex = 0;
298312
curBrowseOrderByMode = Qt::AscendingOrder;
@@ -367,6 +381,9 @@ void MainWindow::fileClose()
367381
m_browseTableModel = new SqliteTableModel(this, &db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
368382
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), m_browseTableModel, SLOT(updateFilter(int,QString)));
369383

384+
// Remove all stored column widths for the browse data table
385+
browseTableColumnWidths.clear();
386+
370387
// Manually update the recordset label inside the Browse tab now
371388
setRecordsetLabel();
372389

@@ -1662,3 +1679,8 @@ void MainWindow::on_actionWebsite_triggered()
16621679
{
16631680
QDesktopServices::openUrl(QUrl("http://sqlitebrowser.org"));
16641681
}
1682+
1683+
void MainWindow::updateBrowseDataColumnWidth(int section, int /*old_size*/, int new_size)
1684+
{
1685+
browseTableColumnWidths[ui->comboBrowseTable->currentText()][section] = new_size;
1686+
}

src/MainWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <QMainWindow>
88
#include <QStandardItemModel>
9+
#include <QMap>
910

1011
class QDragEnterEvent;
1112
class EditDialog;
@@ -84,6 +85,7 @@ class MainWindow : public QMainWindow
8485

8586
int curBrowseOrderByIndex;
8687
Qt::SortOrder curBrowseOrderByMode;
88+
QMap<QString, QMap<int, int> > browseTableColumnWidths;
8789

8890
EditDialog* editWin;
8991
QIntValidator* gotoValidator;
@@ -171,6 +173,7 @@ private slots:
171173
void on_actionWiki_triggered();
172174
void on_actionBug_report_triggered();
173175
void on_actionWebsite_triggered();
176+
void updateBrowseDataColumnWidth(int section, int /*old_size*/, int new_size);
174177
};
175178

176179
#endif

0 commit comments

Comments
 (0)