Skip to content

Commit

Permalink
MainWindow: Keep column widths for each table in Browse Data tab
Browse files Browse the repository at this point in the history
Store the column widths of the table view widget for each table/view
individually and restore them when changing back to the table/view.
  • Loading branch information
MKleusberg committed Jun 1, 2014
1 parent 2aaf734 commit 5e1169b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void MainWindow::init()
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), this, SLOT(setRecordsetLabel()));
connect(ui->dataTable->filterHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(updateBrowseDataColumnWidth(int,int,int)));
connect(editWin, SIGNAL(goingAway()), this, SLOT(editWinAway()));
connect(editWin, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
connect(ui->dbTreeWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changeTreeSelection()));
Expand Down Expand Up @@ -293,6 +294,19 @@ void MainWindow::populateTable( const QString & tablename)
m_browseTableModel->setTable(tablename);
ui->dataTable->setColumnHidden(0, true);

// Restore column widths
QMap<QString, QMap<int, int> >::ConstIterator colWidthsIt;
if((colWidthsIt = browseTableColumnWidths.constFind(tablename)) != browseTableColumnWidths.constEnd())
{
// There are some column widths stored for this table
for(QMap<int, int>::ConstIterator it=colWidthsIt.value().constBegin();it!=colWidthsIt.value().constEnd();++it)
ui->dataTable->setColumnWidth(it.key(), it.value());
} else {
// There aren't any column widths stored for this table yet, so set default widths
for(int i=1;i<m_browseTableModel->columnCount();i++)
ui->dataTable->setColumnWidth(i, ui->dataTable->horizontalHeader()->defaultSectionSize());
}

// Reset sorting
curBrowseOrderByIndex = 0;
curBrowseOrderByMode = Qt::AscendingOrder;
Expand Down Expand Up @@ -367,6 +381,9 @@ void MainWindow::fileClose()
m_browseTableModel = new SqliteTableModel(this, &db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt());
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), m_browseTableModel, SLOT(updateFilter(int,QString)));

// Remove all stored column widths for the browse data table
browseTableColumnWidths.clear();

// Manually update the recordset label inside the Browse tab now
setRecordsetLabel();

Expand Down Expand Up @@ -1662,3 +1679,8 @@ void MainWindow::on_actionWebsite_triggered()
{
QDesktopServices::openUrl(QUrl("http://sqlitebrowser.org"));
}

void MainWindow::updateBrowseDataColumnWidth(int section, int /*old_size*/, int new_size)
{
browseTableColumnWidths[ui->comboBrowseTable->currentText()][section] = new_size;
}
3 changes: 3 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QMainWindow>
#include <QStandardItemModel>
#include <QMap>

class QDragEnterEvent;
class EditDialog;
Expand Down Expand Up @@ -84,6 +85,7 @@ class MainWindow : public QMainWindow

int curBrowseOrderByIndex;
Qt::SortOrder curBrowseOrderByMode;
QMap<QString, QMap<int, int> > browseTableColumnWidths;

EditDialog* editWin;
QIntValidator* gotoValidator;
Expand Down Expand Up @@ -171,6 +173,7 @@ private slots:
void on_actionWiki_triggered();
void on_actionBug_report_triggered();
void on_actionWebsite_triggered();
void updateBrowseDataColumnWidth(int section, int /*old_size*/, int new_size);
};

#endif

0 comments on commit 5e1169b

Please sign in to comment.