From a79357db87a331464377734c7c372e9b9707c3f3 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 7 Jan 2018 09:02:53 +0100 Subject: [PATCH] Tables are now sorted by not perfect yet. --- pglab/TablesTableModel.cpp | 16 ++++++++++++++++ pglab/TablesTableModel.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/pglab/TablesTableModel.cpp b/pglab/TablesTableModel.cpp index f15a10c..7675a85 100644 --- a/pglab/TablesTableModel.cpp +++ b/pglab/TablesTableModel.cpp @@ -34,9 +34,25 @@ void TablesTableModel::setCatalog(std::shared_ptr cat) } } + doSort(1); endResetModel(); } +void TablesTableModel::setSortOrder(int so) +{ + beginResetModel(); + doSort(so); + endResetModel(); +} + +void TablesTableModel::doSort(int so) +{ + if (so == 1) + std::sort(m_tables.begin(), m_tables.end(), + [] (auto l, auto r) -> bool { return l.relnamespace < r.relnamespace + || (l.relnamespace == r.relnamespace && l.name < r.name); }); +} + QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation, int role) const { diff --git a/pglab/TablesTableModel.h b/pglab/TablesTableModel.h index b0ddb41..5b83013 100644 --- a/pglab/TablesTableModel.h +++ b/pglab/TablesTableModel.h @@ -25,6 +25,8 @@ public: void setCatalog(std::shared_ptr cat); + void setSortOrder(int so); + // Header: QVariant headerData(int section, Qt::Orientation orientation, int role) const override; @@ -46,6 +48,7 @@ private: t_Tables m_tables; QString formatTableName(const PgClass &cls) const; + void doSort(int so); }; #endif // TABLESTABLEMODEL_H