mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Make hidden columns persistent
With this commit the main window keeps track of the hidden columns and re-hides them when the table is selected again. It also saves the hidden status to the project file and restores it from there.
This commit is contained in:
@@ -476,6 +476,9 @@ void MainWindow::populateTable()
|
||||
// Hide rowid column. Needs to be done before the column widths setting because of the workaround in there
|
||||
showRowidColumn(false);
|
||||
|
||||
// Unhide all columns by default
|
||||
on_actionShowAllColumns_triggered();
|
||||
|
||||
// Enable editing in general, but lock view editing
|
||||
unlockViewEditing(false);
|
||||
|
||||
@@ -526,6 +529,11 @@ void MainWindow::populateTable()
|
||||
// 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());
|
||||
@@ -2543,48 +2551,51 @@ sqlb::ObjectIdentifier MainWindow::currentlyBrowsedTableName() const
|
||||
// table name without the schema bit in front of it.
|
||||
}
|
||||
|
||||
void MainWindow::on_actionHideColumns_triggered()
|
||||
void MainWindow::hideColumns(int column, bool hide)
|
||||
{
|
||||
int myCol = -1;
|
||||
if(ui->dataTable->selectedCols().size() == 0)
|
||||
{
|
||||
myCol = ui->actionBrowseTableEditDisplayFormat->property("clicked_column").toInt();
|
||||
}
|
||||
sqlb::ObjectIdentifier tableName = currentlyBrowsedTableName();
|
||||
|
||||
foreach(int col, ui->dataTable->selectedCols())
|
||||
{
|
||||
ui->dataTable->hideColumn(col);
|
||||
}
|
||||
if(myCol != -1)
|
||||
ui->dataTable->hideColumn(myCol);
|
||||
// Select columns to (un)hide
|
||||
QSet<int> columns;
|
||||
if(column == -1)
|
||||
{
|
||||
if(ui->dataTable->selectedCols().size() == 0)
|
||||
columns.insert(ui->actionBrowseTableEditDisplayFormat->property("clicked_column").toInt());
|
||||
else
|
||||
columns += ui->dataTable->selectedCols();
|
||||
} else {
|
||||
columns.insert(column);
|
||||
}
|
||||
|
||||
// check to see if all the columns are hidden
|
||||
// (Un)hide requested column(s)
|
||||
foreach(int col, columns)
|
||||
{
|
||||
ui->dataTable->setColumnHidden(col, hide);
|
||||
if(!hide)
|
||||
ui->dataTable->setColumnWidth(col, ui->dataTable->horizontalHeader()->defaultSectionSize());
|
||||
browseTableSettings[tableName].hiddenColumns[col] = hide;
|
||||
}
|
||||
|
||||
bool allHidden = true;
|
||||
for(int col = 1; col < ui->dataTable->model()->columnCount(); col++)
|
||||
{
|
||||
if(!ui->dataTable->isColumnHidden(col))
|
||||
{
|
||||
allHidden = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// check to see if all the columns are hidden
|
||||
bool allHidden = true;
|
||||
for(int col = 1; col < ui->dataTable->model()->columnCount(); col++)
|
||||
{
|
||||
if(!ui->dataTable->isColumnHidden(col))
|
||||
{
|
||||
allHidden = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(allHidden && ui->dataTable->model()->columnCount() > 1)
|
||||
{
|
||||
ui->dataTable->showColumn(1);
|
||||
ui->dataTable->resizeColumnToContents(1);
|
||||
}
|
||||
if(allHidden && ui->dataTable->model()->columnCount() > 1)
|
||||
hideColumns(1, false);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionShowAllColumns_triggered()
|
||||
{
|
||||
for(int col = 1; col < ui->dataTable->model()->columnCount(); col++)
|
||||
{
|
||||
if(ui->dataTable->isColumnHidden(col))
|
||||
{
|
||||
ui->dataTable->showColumn(col);
|
||||
ui->dataTable->resizeColumnToContents(col);
|
||||
}
|
||||
}
|
||||
for(int col = 1; col < ui->dataTable->model()->columnCount(); col++)
|
||||
{
|
||||
if(ui->dataTable->isColumnHidden(col))
|
||||
hideColumns(col, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ struct BrowseDataTableSettings
|
||||
QString plotXAxis;
|
||||
QMap<QString, PlotDock::PlotSettings> plotYAxes;
|
||||
QString unlockViewPk;
|
||||
QMap<int, bool> hiddenColumns;
|
||||
|
||||
BrowseDataTableSettings() :
|
||||
sortOrderIndex(0),
|
||||
@@ -54,6 +55,7 @@ struct BrowseDataTableSettings
|
||||
stream << object.plotXAxis;
|
||||
stream << object.plotYAxes;
|
||||
stream << object.unlockViewPk;
|
||||
stream << object.hiddenColumns;
|
||||
|
||||
return stream;
|
||||
}
|
||||
@@ -74,11 +76,15 @@ struct BrowseDataTableSettings
|
||||
// those cases, check for the end of the stream here.
|
||||
if(stream.atEnd())
|
||||
return stream;
|
||||
|
||||
stream >> object.plotXAxis;
|
||||
stream >> object.plotYAxes;
|
||||
stream >> object.unlockViewPk;
|
||||
|
||||
// Project files from versions before 3.11.0 didn't have these fields
|
||||
if(stream.atEnd())
|
||||
return stream;
|
||||
stream >> object.hiddenColumns;
|
||||
|
||||
return stream;
|
||||
}
|
||||
};
|
||||
@@ -259,7 +265,7 @@ private slots:
|
||||
void browseDataSetDefaultTableEncoding();
|
||||
void fileOpenReadOnly();
|
||||
void unlockViewEditing(bool unlock, QString pk = QString());
|
||||
void on_actionHideColumns_triggered();
|
||||
void hideColumns(int column = -1, bool hide = true);
|
||||
void on_actionShowAllColumns_triggered();
|
||||
};
|
||||
|
||||
|
||||
@@ -371,8 +371,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>668</width>
|
||||
<height>462</height>
|
||||
<width>605</width>
|
||||
<height>568</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
@@ -859,7 +859,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1037</width>
|
||||
<height>21</height>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="fileMenu">
|
||||
@@ -2921,6 +2921,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionHideColumns</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>hideColumns()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>518</x>
|
||||
<y>314</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>fileOpen()</slot>
|
||||
@@ -2988,5 +3004,6 @@
|
||||
<slot>saveSqlResultsAsCsv()</slot>
|
||||
<slot>saveSqlResultsAsView()</slot>
|
||||
<slot>changeSqlTab(int)</slot>
|
||||
<slot>hideColumns()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user