diff --git a/pglab/ColumnPage.cpp b/pglab/ColumnPage.cpp index 730d89f..892322d 100644 --- a/pglab/ColumnPage.cpp +++ b/pglab/ColumnPage.cpp @@ -1,16 +1,18 @@ #include "ColumnPage.h" -#include "ResultTableModelUtil.h" -#include "UserConfiguration.h" -#include "PgLabTableView.h" -#include "catalog/PgClass.h" -#include "SqlCodePreview.h" + #include "ColumnTableModel.h" #include "CustomFilterSortModel.h" #include "CustomDataRole.h" -#include "PgLabItemDelegate.h" +#include "PgLabTableView.h" +#include "ResultTableModelUtil.h" +#include "SqlCodePreview.h" +//#include "PgLabItemDelegate.h" +#include "SqlFormattingUtils.h" +#include "UserConfiguration.h" +#include "catalog/PgClass.h" +#include #include #include -#include "SqlFormattingUtils.h" ColumnPage::ColumnPage(QWidget *parent) : QSplitter(Qt::Vertical, parent) @@ -21,7 +23,7 @@ ColumnPage::ColumnPage(QWidget *parent) addWidget(m_definitionView); m_columnModel = new ColumnTableModel(this); - m_sortFilterProxy = new CustomFilterSortModel(this); + m_sortFilterProxy = new QSortFilterProxyModel(this); m_sortFilterProxy->setSourceModel(m_columnModel); m_tableView->setModel(m_sortFilterProxy); m_tableView->setSortingEnabled(true); @@ -39,13 +41,9 @@ void ColumnPage::setData(std::shared_ptr cat, const std m_columnModel->setData(cat, cls); m_Class = cls; m_tableView->resizeColumnsToContents(); + m_definitionView->setPlainText(""); } -//void ColumnPage::setFilter(const std::optional &cls) -//{ -// m_sortFilterProxy->setOidFilterTable(cls ? cls->oid() : InvalidOid, FirstHiddenValue); -//} - void ColumnPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) { auto&& indexes = m_tableView->selectionModel()->selectedIndexes(); diff --git a/pglab/ColumnPage.h b/pglab/ColumnPage.h index 220ae2d..9f64236 100644 --- a/pglab/ColumnPage.h +++ b/pglab/ColumnPage.h @@ -11,7 +11,7 @@ class PgLabTableView; class SqlCodePreview; class PgDatabaseCatalog; class ColumnTableModel; -class CustomFilterSortModel; +class QSortFilterProxyModel; class QItemSelection; class QAbstractItemModel; @@ -31,7 +31,7 @@ private: PgLabTableView *m_tableView = nullptr; SqlCodePreview *m_definitionView = nullptr; ColumnTableModel *m_columnModel = nullptr; - CustomFilterSortModel *m_sortFilterProxy = nullptr; + QSortFilterProxyModel *m_sortFilterProxy = nullptr; std::shared_ptr m_catalog; std::optional m_Class; diff --git a/pglab/PgLabTableView.cpp b/pglab/PgLabTableView.cpp index a7dbd18..4ea321d 100644 --- a/pglab/PgLabTableView.cpp +++ b/pglab/PgLabTableView.cpp @@ -1,6 +1,7 @@ #include "PgLabTableView.h" #include "PgLabItemDelegate.h" #include +#include PgLabTableView::PgLabTableView(QWidget *parent) : QTableView(parent) @@ -9,7 +10,13 @@ PgLabTableView::PgLabTableView(QWidget *parent) setItemDelegate(new PgLabItemDelegate(this)); setWordWrap(false); + auto pal = palette(); + pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight)); + pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText)); + setPalette(pal); + auto vertical_header = verticalHeader(); vertical_header->setMinimumSectionSize(16); vertical_header->setDefaultSectionSize(20); } + diff --git a/pglab/PgLabTableView.h b/pglab/PgLabTableView.h index 9bc0c9d..6d7dfdc 100644 --- a/pglab/PgLabTableView.h +++ b/pglab/PgLabTableView.h @@ -3,10 +3,13 @@ #include +class QSortFilterProxyModel; + class PgLabTableView : public QTableView { Q_OBJECT public: explicit PgLabTableView(QWidget *parent = nullptr); + }; #endif // PGLABTABLEVIEW_H diff --git a/pglab/PropertiesPage.cpp b/pglab/PropertiesPage.cpp index e565e76..ce5a38d 100644 --- a/pglab/PropertiesPage.cpp +++ b/pglab/PropertiesPage.cpp @@ -3,14 +3,13 @@ #include "PropertyProxyModel.h" #include "ResultTableModelUtil.h" #include "SqlCodePreview.h" -#include +#include "PgLabTableView.h" + PropertiesPage::PropertiesPage(QWidget *parent) : QSplitter(parent) { - m_tableView = new QTableView(this); -// m_definitionView = new SqlCodePreview(this); + m_tableView = new PgLabTableView(this); addWidget(m_tableView); -// addWidget(m_definitionView); SetTableViewDefault(m_tableView); @@ -32,4 +31,5 @@ void PropertiesPage::setSourceModel(QAbstractItemModel *model) void PropertiesPage::setActiveRow(const QModelIndex &row) { m_propertyProxyModel->setActiveRow(row); + m_tableView->resizeColumnsToContents(); } diff --git a/pglab/PropertiesPage.h b/pglab/PropertiesPage.h index 5686d31..b4d3041 100644 --- a/pglab/PropertiesPage.h +++ b/pglab/PropertiesPage.h @@ -3,21 +3,19 @@ #include -class QTableView; class SqlCodePreview; class PgDatabaseCatalog; class PropertyProxyModel; +class PgLabTableView; class QAbstractItemModel; -class PropertiesPage : public QSplitter -{ +class PropertiesPage : public QSplitter { Q_OBJECT public: explicit PropertiesPage(QWidget *parent = nullptr); void setSourceModel(QAbstractItemModel *model); signals: - public slots: /** Updates the model (and view) to show the values for row * @@ -27,8 +25,7 @@ public slots: void setActiveRow(const QModelIndex &row); private: - QTableView *m_tableView = nullptr; -// SqlCodePreview *m_definitionView = nullptr; + PgLabTableView *m_tableView = nullptr; PropertyProxyModel *m_propertyProxyModel = nullptr; }; diff --git a/pglab/PropertyProxyModel.cpp b/pglab/PropertyProxyModel.cpp index 1448a3d..ba2332f 100644 --- a/pglab/PropertyProxyModel.cpp +++ b/pglab/PropertyProxyModel.cpp @@ -102,3 +102,8 @@ void PropertyProxyModel::setActiveRow(const QModelIndex &row) activeRow = row.isValid() ? row.row() : -1; emit dataChanged(index(0, valueColumn), index(rowCount(QModelIndex()), valueColumn), QVector() << Qt::DisplayRole); } + +Qt::ItemFlags PropertyProxyModel::flags(const QModelIndex &index) const +{ + return Qt::ItemIsSelectable | Qt::ItemIsEnabled; +} diff --git a/pglab/PropertyProxyModel.h b/pglab/PropertyProxyModel.h index 4d3ea9b..047a17e 100644 --- a/pglab/PropertyProxyModel.h +++ b/pglab/PropertyProxyModel.h @@ -7,14 +7,15 @@ class PropertyProxyModel : public QIdentityProxyModel { Q_OBJECT public: PropertyProxyModel(QObject * parent = nullptr); - QModelIndex mapToSource(const QModelIndex &proxyIndex) const; - QModelIndex mapFromSource(const QModelIndex &sourceIndex) const; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const; - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - QVariant data(const QModelIndex &proxyIndex, int role) const; + QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; + QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &child) const override; + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + QVariant data(const QModelIndex &proxyIndex, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; public Q_SLOTS: /** Updates the model (and view) to show the values for row diff --git a/pglab/widgets/CatalogFunctionsPage.cpp b/pglab/widgets/CatalogFunctionsPage.cpp index ead3533..bc650b8 100644 --- a/pglab/widgets/CatalogFunctionsPage.cpp +++ b/pglab/widgets/CatalogFunctionsPage.cpp @@ -57,6 +57,7 @@ void CatalogFunctionsPage::setCatalog(std::shared_ptr c { m_catalog = cat; m_model->setCatalog(cat); + m_functionTable->resizeColumnsToContents(); } void CatalogFunctionsPage::functionTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) diff --git a/pglab/widgets/CatalogIndexPage.cpp b/pglab/widgets/CatalogIndexPage.cpp index b41f1bb..99bc789 100644 --- a/pglab/widgets/CatalogIndexPage.cpp +++ b/pglab/widgets/CatalogIndexPage.cpp @@ -12,7 +12,6 @@ CatalogIndexPage::CatalogIndexPage(QWidget *parent) { m_indexModel = new IndexModel(this); m_sortFilterProxy->setSourceModel(m_indexModel); - m_tableView->setItemDelegateForColumn(0, new IconColumnDelegate(this)); connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged, diff --git a/pglab/widgets/CatalogSequencesPage.cpp b/pglab/widgets/CatalogSequencesPage.cpp index b6f9c44..ecf61b3 100644 --- a/pglab/widgets/CatalogSequencesPage.cpp +++ b/pglab/widgets/CatalogSequencesPage.cpp @@ -33,17 +33,13 @@ CatalogSequencesPage::CatalogSequencesPage(QWidget *parent) void CatalogSequencesPage::retranslateUi() { -// auto set_tabtext = [this] (QWidget *widget, QString translation) { -// m_detailTabs->setTabText(m_detailTabs->indexOf(widget), translation); -// }; - -// set_tabtext(m_definitionView, QApplication::translate("FunctionsPage", "SQL", nullptr)); } void CatalogSequencesPage::setCatalog(std::shared_ptr cat) { m_catalog = cat; m_model->setCatalog(cat); + m_sequenceTable->resizeColumnsToContents(); } void CatalogSequencesPage::sequenceTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) diff --git a/pglab/widgets/CatalogTablesPage.cpp b/pglab/widgets/CatalogTablesPage.cpp index 273008c..1d0aaaa 100644 --- a/pglab/widgets/CatalogTablesPage.cpp +++ b/pglab/widgets/CatalogTablesPage.cpp @@ -15,12 +15,15 @@ #include #include +#include #include CatalogTablesPage::CatalogTablesPage(QWidget *parent) : QSplitter(Qt::Horizontal, parent) { m_tableView = new PgLabTableView(this); + m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + m_tableView->setSelectionMode(QAbstractItemView::SingleSelection); m_detailsTabs = new QTabWidget(this); // Populate splitter @@ -29,7 +32,10 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent) // Setup model(s) m_tablesModel = new TablesTableModel(this); - m_tableView->setModel(m_tablesModel); + m_tablesSortFilter = new QSortFilterProxyModel(this); + m_tablesSortFilter->setSourceModel(m_tablesModel); + m_tableView->setModel(m_tablesSortFilter); + m_tableView->setSortingEnabled(true); // - Columns page m_columnsPage = new ColumnPage(this); @@ -70,7 +76,7 @@ CatalogTablesPage::CatalogTablesPage(QWidget *parent) this, &CatalogTablesPage::tableListTable_layoutChanged); } -void CatalogTablesPage::retranslateUi(bool all) +void CatalogTablesPage::retranslateUi(bool /*all*/) { auto set_tabtext = [this] (QWidget *widget, QString translation) { m_detailsTabs->setTabText(m_detailsTabs->indexOf(widget), translation); diff --git a/pglab/widgets/CatalogTablesPage.h b/pglab/widgets/CatalogTablesPage.h index 7860107..bc44413 100644 --- a/pglab/widgets/CatalogTablesPage.h +++ b/pglab/widgets/CatalogTablesPage.h @@ -16,6 +16,7 @@ class PgLabTableView; class PropertiesPage; class QTabWidget; class SqlCodePreview; +class QSortFilterProxyModel; class TablesTableModel; class TriggerPage; @@ -32,6 +33,7 @@ public: private: PgLabTableView *m_tableView = nullptr; TablesTableModel* m_tablesModel = nullptr; + QSortFilterProxyModel *m_tablesSortFilter = nullptr; // Details QTabWidget *m_detailsTabs = nullptr;