Skip to content

Commit

Permalink
Merge pull request sqlitebrowser#309 from schdub/issue305
Browse files Browse the repository at this point in the history
enhancement: preserve field filters when switching tab
  • Loading branch information
justinclift committed May 15, 2015
2 parents dd333ce + b5c1c7b commit 7cfef55
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/FilterTableHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void FilterTableHeader::generateFilters(int number, bool bKeepValues)
FilterLineEdit* l = new FilterLineEdit(this, &filterWidgets, i);
l->setVisible(i>0); // This hides the first input widget which belongs to the hidden rowid column
connect(l, SIGNAL(textChanged(QString)), this, SLOT(inputChanged(QString)));
if(bKeepValues && !oldvalues[i].isEmpty()) // restore old values
if(bKeepValues && oldvalues.size() > i && !oldvalues[i].isEmpty()) // restore old values
l->setText(oldvalues[i]);
filterWidgets.push_back(l);
}
Expand Down Expand Up @@ -123,3 +123,9 @@ void FilterTableHeader::inputChanged(const QString& new_value)
// Just get the column number and the new value and send them to anybody interested in filter changes
emit filterChanged(sender()->property("column").toInt(), new_value);
}

void FilterTableHeader::clearFilters()
{
foreach (FilterLineEdit* filterLineEdit, filterWidgets)
filterLineEdit->clear();
}
1 change: 1 addition & 0 deletions src/FilterTableHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FilterTableHeader : public QHeaderView
public slots:
void generateFilters(int number, bool bKeepValues = false);
void adjustPositions();
void clearFilters();

signals:
void filterChanged(int column, QString value);
Expand Down
8 changes: 7 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void MainWindow::resetBrowser()
curBrowseOrderByIndex = 0;
curBrowseOrderByMode = Qt::AscendingOrder;
m_browseTableModel->sort(curBrowseOrderByIndex, curBrowseOrderByMode);
populateTable(ui->comboBrowseTable->currentText());
populateTable(ui->comboBrowseTable->currentText(), true);
}

void MainWindow::fileClose()
Expand Down Expand Up @@ -1106,6 +1106,7 @@ void MainWindow::activateFields(bool enable)
ui->actionSqlSaveFile->setEnabled(enable);
ui->actionSaveProject->setEnabled(enable);
ui->actionEncryption->setEnabled(enable);
ui->buttonClearFilters->setEnabled(enable);
}

void MainWindow::browseTableHeaderClicked(int logicalindex)
Expand Down Expand Up @@ -2089,3 +2090,8 @@ void MainWindow::switchToBrowseDataTab()
ui->comboBrowseTable->setCurrentIndex(ui->comboBrowseTable->findText(tableToBrowse));
populateTable(tableToBrowse);
}

void MainWindow::on_buttonClearFilters_clicked()
{
ui->dataTable->filterHeader()->clearFilters();
}
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private slots:
void updateFilter(int column, const QString& value);
void editEncryption();
void switchToBrowseDataTab();
void on_buttonClearFilters_clicked();
};

#endif
20 changes: 17 additions & 3 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="buttonClearFilters">
<property name="toolTip">
<string>Clear all filters</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/clear_filters</normaloff>:/icons/clear_filters</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -310,8 +324,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>575</width>
<height>458</height>
<width>311</width>
<height>531</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -796,7 +810,7 @@
<x>0</x>
<y>0</y>
<width>1000</width>
<height>19</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="fileMenu">
Expand Down
Binary file added src/icons/clear_filters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
<file alias="document_open">document-open.png</file>
<file alias="function">chart_curve.png</file>
<file alias="keyword">cog.png</file>
<file alias="clear_filters">clear_filters.png</file>
</qresource>
</RCC>

0 comments on commit 7cfef55

Please sign in to comment.