mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-19 18:40:13 -06:00
Fix browse table settings not being reapplied correctly
We have already fixed the rowid column from appearing after almost every
action in the Browse Data tab, for example in commit
39302f5b60.
This didn't fix every issue related to this problem though. Hidden
columns are shown too and modified column widths are reset. Also this
happens for different actions, for example the column widths are also
reset when sorting the view or when changing the filters. All these
problems are hopefully fixed by this commit.
See issue #1475.
This commit is contained in:
@@ -601,33 +601,7 @@ void MainWindow::populateTable()
|
||||
m_browseTableModel->setTable(tablename, storedData.sortOrderIndex, storedData.sortOrderMode, v);
|
||||
|
||||
// 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(storedData.showRowid);
|
||||
|
||||
// Enable editing in general and (un)lock view editing depending on the settings
|
||||
unlockViewEditing(!storedData.unlockViewPk.isEmpty(), storedData.unlockViewPk);
|
||||
|
||||
// Column hidden status
|
||||
on_actionShowAllColumns_triggered();
|
||||
for(auto hiddenIt=storedData.hiddenColumns.constBegin();hiddenIt!=storedData.hiddenColumns.constEnd();++hiddenIt)
|
||||
hideColumns(hiddenIt.key(), hiddenIt.value());
|
||||
|
||||
// Column widths
|
||||
for(auto widthIt=storedData.columnWidths.constBegin();widthIt!=storedData.columnWidths.constEnd();++widthIt)
|
||||
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
|
||||
|
||||
// Sorting
|
||||
ui->dataTable->filterHeader()->setSortIndicator(storedData.sortOrderIndex, storedData.sortOrderMode);
|
||||
|
||||
// Filters
|
||||
FilterTableHeader* filterHeader = qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader());
|
||||
for(auto filterIt=storedData.filterValues.constBegin();filterIt!=storedData.filterValues.constEnd();++filterIt)
|
||||
filterHeader->setFilter(filterIt.key(), filterIt.value());
|
||||
|
||||
// Encoding
|
||||
m_browseTableModel->setEncoding(storedData.encoding);
|
||||
applyBrowseTableSettings(storedData);
|
||||
|
||||
setRecordsetLabel();
|
||||
|
||||
@@ -653,6 +627,39 @@ void MainWindow::populateTable()
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void MainWindow::applyBrowseTableSettings(const BrowseDataTableSettings& storedData, bool skipFilters)
|
||||
{
|
||||
// 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(storedData.showRowid, skipFilters);
|
||||
|
||||
// Enable editing in general and (un)lock view editing depending on the settings
|
||||
unlockViewEditing(!storedData.unlockViewPk.isEmpty(), storedData.unlockViewPk);
|
||||
|
||||
// Column hidden status
|
||||
on_actionShowAllColumns_triggered();
|
||||
for(auto hiddenIt=storedData.hiddenColumns.constBegin();hiddenIt!=storedData.hiddenColumns.constEnd();++hiddenIt)
|
||||
hideColumns(hiddenIt.key(), hiddenIt.value());
|
||||
|
||||
// Column widths
|
||||
for(auto widthIt=storedData.columnWidths.constBegin();widthIt!=storedData.columnWidths.constEnd();++widthIt)
|
||||
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
|
||||
|
||||
// Sorting
|
||||
ui->dataTable->filterHeader()->setSortIndicator(storedData.sortOrderIndex, storedData.sortOrderMode);
|
||||
|
||||
// Filters
|
||||
if(!skipFilters)
|
||||
{
|
||||
FilterTableHeader* filterHeader = qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader());
|
||||
for(auto filterIt=storedData.filterValues.constBegin();filterIt!=storedData.filterValues.constEnd();++filterIt)
|
||||
filterHeader->setFilter(filterIt.key(), filterIt.value());
|
||||
}
|
||||
|
||||
// Encoding
|
||||
m_browseTableModel->setEncoding(storedData.encoding);
|
||||
}
|
||||
|
||||
bool MainWindow::fileClose()
|
||||
{
|
||||
// Close the database but stop the closing process here if the user pressed the cancel button in there
|
||||
@@ -1824,9 +1831,8 @@ void MainWindow::browseTableHeaderClicked(int logicalindex)
|
||||
|
||||
attachPlot(ui->dataTable, m_browseTableModel, &browseTableSettings[currentlyBrowsedTableName()]);
|
||||
|
||||
// This seems to be necessary as a workaround for newer Qt versions. Otherwise the rowid column is always shown after changing the data view.
|
||||
bool showRowid = browseTableSettings[currentlyBrowsedTableName()].showRowid;
|
||||
ui->dataTable->setColumnHidden(0, !showRowid);
|
||||
// Reapply the view settings. This seems to be necessary as a workaround for newer Qt versions.
|
||||
applyBrowseTableSettings(settings);
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent*)
|
||||
@@ -2666,12 +2672,12 @@ void MainWindow::fileAttach()
|
||||
void MainWindow::updateFilter(int column, const QString& value)
|
||||
{
|
||||
m_browseTableModel->updateFilter(column, value);
|
||||
browseTableSettings[currentlyBrowsedTableName()].filterValues[column] = value;
|
||||
BrowseDataTableSettings& settings = browseTableSettings[currentlyBrowsedTableName()];
|
||||
settings.filterValues[column] = value;
|
||||
setRecordsetLabel();
|
||||
|
||||
// This seems to be necessary as a workaround for newer Qt versions. Otherwise the rowid column is always shown after changing the data view.
|
||||
bool showRowid = browseTableSettings[currentlyBrowsedTableName()].showRowid;
|
||||
ui->dataTable->setColumnHidden(0, !showRowid);
|
||||
// Reapply the view settings. This seems to be necessary as a workaround for newer Qt versions.
|
||||
applyBrowseTableSettings(settings, true);
|
||||
}
|
||||
|
||||
void MainWindow::editEncryption()
|
||||
@@ -2890,7 +2896,7 @@ void MainWindow::editDataColumnDisplayFormat()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showRowidColumn(bool show)
|
||||
void MainWindow::showRowidColumn(bool show, bool skipFilters)
|
||||
{
|
||||
// Block all signals from the horizontal header. Otherwise the QHeaderView::sectionResized signal causes us trouble
|
||||
ui->dataTable->horizontalHeader()->blockSignals(true);
|
||||
@@ -2915,7 +2921,8 @@ void MainWindow::showRowidColumn(bool show)
|
||||
browseTableSettings[current_table].showRowid = show;
|
||||
|
||||
// Update the filter row
|
||||
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount(), show);
|
||||
if(!skipFilters)
|
||||
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount(), show);
|
||||
|
||||
// Re-enable signals
|
||||
ui->dataTable->horizontalHeader()->blockSignals(false);
|
||||
@@ -3040,11 +3047,11 @@ void MainWindow::unlockViewEditing(bool unlock, QString pk)
|
||||
ui->actionUnlockViewEditing->blockSignals(false);
|
||||
|
||||
// Save settings for this table
|
||||
browseTableSettings[currentTable].unlockViewPk = pk;
|
||||
BrowseDataTableSettings& settings = browseTableSettings[currentTable];
|
||||
settings.unlockViewPk = pk;
|
||||
|
||||
// This seems to be necessary as a workaround for newer Qt versions. Otherwise the rowid column is always shown after changing the data view.
|
||||
bool showRowid = browseTableSettings[currentlyBrowsedTableName()].showRowid;
|
||||
ui->dataTable->setColumnHidden(0, !showRowid);
|
||||
// Reapply the view settings. This seems to be necessary as a workaround for newer Qt versions.
|
||||
applyBrowseTableSettings(settings);
|
||||
}
|
||||
|
||||
sqlb::ObjectIdentifier MainWindow::currentlyBrowsedTableName() const
|
||||
|
||||
@@ -193,6 +193,8 @@ private:
|
||||
|
||||
StatementType getQueryType(const QString& query) const;
|
||||
|
||||
void applyBrowseTableSettings(const BrowseDataTableSettings& storedData, bool skipFilters = false);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
@@ -277,7 +279,7 @@ private slots:
|
||||
void showDataColumnPopupMenu(const QPoint& pos);
|
||||
void showRecordPopupMenu(const QPoint& pos);
|
||||
void editDataColumnDisplayFormat();
|
||||
void showRowidColumn(bool show);
|
||||
void showRowidColumn(bool show, bool skipFilters = false);
|
||||
void browseDataSetTableEncoding(bool forAllTables = false);
|
||||
void browseDataSetDefaultTableEncoding();
|
||||
void fileOpenReadOnly();
|
||||
|
||||
Reference in New Issue
Block a user