Give the tables default sorting
This commit is contained in:
parent
0da493f1e4
commit
ddc163a0ee
10 changed files with 66 additions and 50 deletions
|
|
@ -6,10 +6,10 @@
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
#include "ResultTableModelUtil.h"
|
#include "ResultTableModelUtil.h"
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
//#include "PgLabItemDelegate.h"
|
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
#include "UserConfiguration.h"
|
#include "UserConfiguration.h"
|
||||||
#include "catalog/PgClass.h"
|
#include "catalog/PgClass.h"
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
@ -28,6 +28,7 @@ ColumnPage::ColumnPage(QWidget *parent)
|
||||||
m_sortFilterProxy->setSourceModel(m_columnModel);
|
m_sortFilterProxy->setSourceModel(m_columnModel);
|
||||||
m_tableView->setItemDelegateForColumn(ColumnTableModel::TypeCol, new QStyledItemDelegate(this));
|
m_tableView->setItemDelegateForColumn(ColumnTableModel::TypeCol, new QStyledItemDelegate(this));
|
||||||
m_tableView->setModel(m_sortFilterProxy);
|
m_tableView->setModel(m_sortFilterProxy);
|
||||||
|
m_tableView->horizontalHeader()->setSortIndicator(ColumnTableModel::AttnumCol, Qt::AscendingOrder);
|
||||||
m_tableView->setSortingEnabled(true);
|
m_tableView->setSortingEnabled(true);
|
||||||
// m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
// m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_sortFilterProxy->sort(ColumnTableModel::AttnumCol, Qt::AscendingOrder);
|
m_sortFilterProxy->sort(ColumnTableModel::AttnumCol, Qt::AscendingOrder);
|
||||||
|
|
|
||||||
|
|
@ -63,60 +63,60 @@ void TablesTableModel::refresh()
|
||||||
m_tables.push_back(e);
|
m_tables.push_back(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
doSort(1);
|
// doSort(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TablesTableModel::setSortOrder(int so)
|
//void TablesTableModel::setSortOrder(int so)
|
||||||
{
|
//{
|
||||||
beginResetModel();
|
// beginResetModel();
|
||||||
doSort(so);
|
// doSort(so);
|
||||||
endResetModel();
|
// endResetModel();
|
||||||
}
|
//}
|
||||||
|
|
||||||
namespace {
|
//namespace {
|
||||||
|
|
||||||
inline bool compareByName(PgClass l, PgClass r)
|
// inline bool compareByName(PgClass l, PgClass r)
|
||||||
{
|
// {
|
||||||
return l.objectName() < r.objectName()
|
// return l.objectName() < r.objectName()
|
||||||
|| (l.objectName() == r.objectName() && l.nsName() < r.nsName());
|
// || (l.objectName() == r.objectName() && l.nsName() < r.nsName());
|
||||||
}
|
// }
|
||||||
|
|
||||||
inline bool compareBySchema(PgClass l, PgClass r)
|
// inline bool compareBySchema(PgClass l, PgClass r)
|
||||||
{
|
// {
|
||||||
return l.nsName() < r.nsName()
|
// return l.nsName() < r.nsName()
|
||||||
|| (l.nsName() == r.nsName() && l.objectName() < r.objectName());
|
// || (l.nsName() == r.nsName() && l.objectName() < r.objectName());
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
void TablesTableModel::sort(int column, Qt::SortOrder order)
|
//void TablesTableModel::sort(int column, Qt::SortOrder order)
|
||||||
{
|
//{
|
||||||
if (column == NameCol) {
|
// if (column == NameCol) {
|
||||||
if (order == Qt::AscendingOrder)
|
// if (order == Qt::AscendingOrder)
|
||||||
std::sort(m_tables.begin(), m_tables.end(), compareByName);
|
// std::sort(m_tables.begin(), m_tables.end(), compareByName);
|
||||||
else
|
// else
|
||||||
std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareByName(l, r); });
|
// std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareByName(l, r); });
|
||||||
}
|
// }
|
||||||
else if (column == NamespaceCol) {
|
// else if (column == NamespaceCol) {
|
||||||
if (order == Qt::AscendingOrder)
|
// if (order == Qt::AscendingOrder)
|
||||||
std::sort(m_tables.begin(), m_tables.end(), compareBySchema);
|
// std::sort(m_tables.begin(), m_tables.end(), compareBySchema);
|
||||||
else
|
// else
|
||||||
std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareBySchema(l, r); });
|
// std::sort(m_tables.begin(), m_tables.end(), [] (auto l, auto r) { return !compareBySchema(l, r); });
|
||||||
}
|
// }
|
||||||
|
|
||||||
emit layoutChanged();
|
// emit layoutChanged();
|
||||||
}
|
//}
|
||||||
|
|
||||||
void TablesTableModel::doSort(int )
|
//void TablesTableModel::doSort(int )
|
||||||
{
|
//{
|
||||||
// if (so == 1)
|
//// if (so == 1)
|
||||||
// std::sort(m_tables.begin(), m_tables.end(),
|
//// std::sort(m_tables.begin(), m_tables.end(),
|
||||||
// [] (auto l, auto r) -> bool { return l.relnamespace_name < r.relnamespace_name
|
//// [] (auto l, auto r) -> bool { return l.relnamespace_name < r.relnamespace_name
|
||||||
// || (l.relnamespace_name == r.relnamespace_name && l.name < r.name); });
|
//// || (l.relnamespace_name == r.relnamespace_name && l.name < r.name); });
|
||||||
// else
|
//// else
|
||||||
// std::sort(m_tables.begin(), m_tables.end(),
|
//// std::sort(m_tables.begin(), m_tables.end(),
|
||||||
// [] (auto l, auto r) -> bool { return l.name < r.name; });
|
//// [] (auto l, auto r) -> bool { return l.name < r.name; });
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ public:
|
||||||
void setNamespaceFilter(NamespaceFilter nsf);
|
void setNamespaceFilter(NamespaceFilter nsf);
|
||||||
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
void setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat);
|
||||||
|
|
||||||
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
// virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
void setSortOrder(int so);
|
// void setSortOrder(int so);
|
||||||
|
|
||||||
// Header:
|
// Header:
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
|
|
@ -61,7 +61,7 @@ private:
|
||||||
Oid getType(int column) const;
|
Oid getType(int column) const;
|
||||||
QVariant getData(const QModelIndex &index) const;
|
QVariant getData(const QModelIndex &index) const;
|
||||||
// QString formatTableName(const PgClass &cls) const;
|
// QString formatTableName(const PgClass &cls) const;
|
||||||
void doSort(int so);
|
// void doSort(int so);
|
||||||
private slots:
|
private slots:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "CustomDataRole.h"
|
#include "CustomDataRole.h"
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
#include "catalog/PgProcContainer.h"
|
#include "catalog/PgProcContainer.h"
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "IconColumnDelegate.h"
|
#include "IconColumnDelegate.h"
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
||||||
CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
|
CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
|
||||||
|
|
@ -13,6 +14,8 @@ CatalogConstraintPage::CatalogConstraintPage(QWidget *parent)
|
||||||
m_sortFilterProxy->setSourceModel(m_constraintModel);
|
m_sortFilterProxy->setSourceModel(m_constraintModel);
|
||||||
|
|
||||||
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
||||||
|
m_tableView->horizontalHeader()->setSortIndicator(ConstraintModel::NameCol, Qt::AscendingOrder);
|
||||||
|
m_tableView->setSortingEnabled(true);
|
||||||
|
|
||||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||||
this, &CatalogConstraintPage::tableView_selectionChanged);
|
this, &CatalogConstraintPage::tableView_selectionChanged);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ CatalogFunctionsPage::CatalogFunctionsPage(QWidget *parent)
|
||||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||||
m_sortFilterProxy->setSourceModel(m_model);
|
m_sortFilterProxy->setSourceModel(m_model);
|
||||||
m_functionTable->setModel(m_sortFilterProxy);
|
m_functionTable->setModel(m_sortFilterProxy);
|
||||||
|
m_functionTable->horizontalHeader()->setSortIndicator(0, Qt::AscendingOrder);
|
||||||
m_functionTable->setSortingEnabled(true);
|
m_functionTable->setSortingEnabled(true);
|
||||||
m_functionTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
m_functionTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_functionTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_functionTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "IndexModel.h"
|
#include "IndexModel.h"
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include "IconColumnDelegate.h"
|
#include "IconColumnDelegate.h"
|
||||||
|
|
||||||
|
|
@ -13,6 +14,8 @@ CatalogIndexPage::CatalogIndexPage(QWidget *parent)
|
||||||
m_indexModel = new IndexModel(this);
|
m_indexModel = new IndexModel(this);
|
||||||
m_sortFilterProxy->setSourceModel(m_indexModel);
|
m_sortFilterProxy->setSourceModel(m_indexModel);
|
||||||
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this));
|
||||||
|
m_tableView->horizontalHeader()->setSortIndicator(IndexModel::NameCol, Qt::AscendingOrder);
|
||||||
|
m_tableView->setSortingEnabled(true);
|
||||||
|
|
||||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||||
this, &CatalogIndexPage::tableView_selectionChanged);
|
this, &CatalogIndexPage::tableView_selectionChanged);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "SequenceModel.h"
|
#include "SequenceModel.h"
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
|
#include <QHeaderView>
|
||||||
|
|
||||||
CatalogSequencesPage::CatalogSequencesPage(QWidget *parent)
|
CatalogSequencesPage::CatalogSequencesPage(QWidget *parent)
|
||||||
: QSplitter(Qt::Horizontal, parent)
|
: QSplitter(Qt::Horizontal, parent)
|
||||||
|
|
@ -22,6 +23,7 @@ CatalogSequencesPage::CatalogSequencesPage(QWidget *parent)
|
||||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||||
m_sortFilterProxy->setSourceModel(m_model);
|
m_sortFilterProxy->setSourceModel(m_model);
|
||||||
m_sequenceTable->setModel(m_sortFilterProxy);
|
m_sequenceTable->setModel(m_sortFilterProxy);
|
||||||
|
m_sequenceTable->horizontalHeader()->setSortIndicator(SequenceModel::NameCol, Qt::AscendingOrder);
|
||||||
m_sequenceTable->setSortingEnabled(true);
|
m_sequenceTable->setSortingEnabled(true);
|
||||||
m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
m_sequenceTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_sequenceTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_sequenceTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#include "widgets/CatalogIndexPage.h"
|
#include "widgets/CatalogIndexPage.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QHeaderView>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
|
|
@ -38,7 +39,8 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent)
|
||||||
m_tablesModel = new TablesTableModel(this);
|
m_tablesModel = new TablesTableModel(this);
|
||||||
m_tablesSortFilter = new QSortFilterProxyModel(this);
|
m_tablesSortFilter = new QSortFilterProxyModel(this);
|
||||||
m_tablesSortFilter->setSourceModel(m_tablesModel);
|
m_tablesSortFilter->setSourceModel(m_tablesModel);
|
||||||
m_tableView->setModel(m_tablesSortFilter);
|
m_tableView->setModel(m_tablesSortFilter);
|
||||||
|
m_tableView->horizontalHeader()->setSortIndicator(TablesTableModel::NameCol, Qt::AscendingOrder);
|
||||||
m_tableView->setSortingEnabled(true);
|
m_tableView->setSortingEnabled(true);
|
||||||
|
|
||||||
// - Columns page
|
// - Columns page
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
#include "PgLabTableView.h"
|
#include "PgLabTableView.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <QHeaderView>
|
||||||
|
|
||||||
CatalogTypesPage::CatalogTypesPage(QWidget *parent)
|
CatalogTypesPage::CatalogTypesPage(QWidget *parent)
|
||||||
: QSplitter(Qt::Horizontal, parent)
|
: QSplitter(Qt::Horizontal, parent)
|
||||||
|
|
@ -24,6 +25,7 @@ CatalogTypesPage::CatalogTypesPage(QWidget *parent)
|
||||||
m_sortFilterProxy = new CustomFilterSortModel(this);
|
m_sortFilterProxy = new CustomFilterSortModel(this);
|
||||||
m_sortFilterProxy->setSourceModel(m_model);
|
m_sortFilterProxy->setSourceModel(m_model);
|
||||||
m_typeTable->setModel(m_sortFilterProxy);
|
m_typeTable->setModel(m_sortFilterProxy);
|
||||||
|
m_typeTable->horizontalHeader()->setSortIndicator(TypeModel::NameCol, Qt::AscendingOrder);
|
||||||
m_typeTable->setSortingEnabled(true);
|
m_typeTable->setSortingEnabled(true);
|
||||||
m_typeTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
m_typeTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_typeTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_typeTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue