The list of tables can now be sorted by either name,schema or schema,name by clicking on the column headers.
This commit is contained in:
parent
5b20f900fc
commit
ec8c3ff5ec
3 changed files with 45 additions and 8 deletions
|
|
@ -45,15 +45,49 @@ void TablesTableModel::setSortOrder(int so)
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
void TablesTableModel::doSort(int so)
|
||||
namespace {
|
||||
|
||||
inline bool compareByName(PgClass l, PgClass r)
|
||||
{
|
||||
return l.name < r.name
|
||||
|| (l.name == r.name && l.relnamespace_name < r.relnamespace_name);
|
||||
}
|
||||
|
||||
inline bool compareBySchema(PgClass l, PgClass r)
|
||||
{
|
||||
return l.relnamespace_name < r.relnamespace_name
|
||||
|| (l.relnamespace_name == r.relnamespace_name && l.name < r.name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TablesTableModel::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if (so == 1)
|
||||
std::sort(m_tables.begin(), m_tables.end(),
|
||||
[] (auto l, auto r) -> bool { return l.relnamespace_name < r.relnamespace_name
|
||||
|| (l.relnamespace_name == r.relnamespace_name && l.name < r.name); });
|
||||
else
|
||||
std::sort(m_tables.begin(), m_tables.end(),
|
||||
[] (auto l, auto r) -> bool { return l.name < r.name; });
|
||||
if (column == NameCol) {
|
||||
if (order == Qt::AscendingOrder)
|
||||
std::sort(m_tables.begin(), m_tables.end(), compareByName);
|
||||
else
|
||||
std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareByName(l, r); });
|
||||
}
|
||||
else if (column == NamespaceCol) {
|
||||
if (order == Qt::AscendingOrder)
|
||||
std::sort(m_tables.begin(), m_tables.end(), compareBySchema);
|
||||
else
|
||||
std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareBySchema(l, r); });
|
||||
}
|
||||
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void TablesTableModel::doSort(int )
|
||||
{
|
||||
// if (so == 1)
|
||||
// std::sort(m_tables.begin(), m_tables.end(),
|
||||
// [] (auto l, auto r) -> bool { return l.relnamespace_name < r.relnamespace_name
|
||||
// || (l.relnamespace_name == r.relnamespace_name && l.name < r.name); });
|
||||
// else
|
||||
// std::sort(m_tables.begin(), m_tables.end(),
|
||||
// [] (auto l, auto r) -> bool { return l.name < r.name; });
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue