Hide filters when table is empty

Additionally, the record set label wasn't been updated when a new record
is added or deleted.

See issue #2188 and (related) #2353
This commit is contained in:
mgrojo
2020-08-05 14:13:44 +02:00
parent 4f9e7c5d04
commit fc78fc2f3c
3 changed files with 17 additions and 0 deletions

View File

@@ -128,3 +128,13 @@ void FilterTableHeader::setFilter(size_t column, const QString& value)
if(column < filterWidgets.size())
filterWidgets.at(column)->setText(value);
}
void FilterTableHeader::setFiltersVisible(bool visible)
{
// Loop through all widgets
for(size_t i=0; i < filterWidgets.size(); ++i)
{
// Get the current widget, and set it visible or not
filterWidgets.at(i)->setVisible(visible);
}
}

View File

@@ -15,6 +15,7 @@ public:
explicit FilterTableHeader(QTableView* parent = nullptr);
QSize sizeHint() const override;
bool hasFilters() const {return (filterWidgets.size() > 0);}
void setFiltersVisible(bool visible);
public slots:
void generateFilters(size_t number, bool showFirst = false);

View File

@@ -689,6 +689,10 @@ void TableBrowser::updateRecordsetLabel()
(obj->type() == sqlb::Object::Table));
}
enableEditing(m_model->rowCountAvailable() != SqliteTableModel::RowCount::Unknown && is_table_or_unlocked_view);
// Show filters unless the table is empty
const bool filtersVisible = m_model->rowCount() > 0 || m_model->filterCount() != 0;
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->setFiltersVisible(filtersVisible);
}
sqlb::Query TableBrowser::buildQuery(const BrowseDataTableSettings& storedData, const sqlb::ObjectIdentifier& tablename) const
@@ -1198,6 +1202,7 @@ void TableBrowser::addRecord()
// User has to provide values acomplishing the constraints. Open Add Record Dialog.
insertValues();
}
updateRecordsetLabel();
}
void TableBrowser::insertValues()
@@ -1235,6 +1240,7 @@ void TableBrowser::deleteRecord()
} else {
QMessageBox::information( this, QApplication::applicationName(), tr("Please select a record first"));
}
updateRecordsetLabel();
}
void TableBrowser::navigatePrevious()