From e1405d53707fe8e2d59841f9539ff2f2d0077778 Mon Sep 17 00:00:00 2001 From: eelke Date: Mon, 15 Jan 2018 13:31:37 +0100 Subject: [PATCH] Use PgLabItemDelegate for indexes tab. --- pglab/IndexModel.cpp | 16 +++++++++++++--- pglab/IndexModel.h | 11 ++++++----- pglab/TablesPage.cpp | 4 +++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pglab/IndexModel.cpp b/pglab/IndexModel.cpp index 4667c4a..f61b9dc 100644 --- a/pglab/IndexModel.cpp +++ b/pglab/IndexModel.cpp @@ -15,17 +15,17 @@ void IndexModel::setData(std::shared_ptr cat, const PgC m_indexes = cat->indexes()->getIndexesForTable(table.oid); } -int IndexModel::rowCount(const QModelIndex &parent) const +int IndexModel::rowCount(const QModelIndex &/*parent*/) const { return m_indexes.size(); } -int IndexModel::columnCount(const QModelIndex &parent) const +int IndexModel::columnCount(const QModelIndex &/*parent*/) const { return colCount; } -Oid IndexModel::getType(int column) const +Oid IndexModel::getType(int /*column*/) const { return Pgsql::varchar_oid; } @@ -83,3 +83,13 @@ QVariant IndexModel::getData(const QModelIndex &index) const } return v; } + +QVariant IndexModel::data(const QModelIndex &index, int role) const +{ + QVariant v; + if (role == Qt::DisplayRole) + v = getData(index); + else if (role == Qt::UserRole) + v = getType(index.column()); + return v; +} diff --git a/pglab/IndexModel.h b/pglab/IndexModel.h index d312413..5ec5c3a 100644 --- a/pglab/IndexModel.h +++ b/pglab/IndexModel.h @@ -1,7 +1,7 @@ #ifndef INDEXMODEL_H #define INDEXMODEL_H -#include "BaseTableModel.h" +#include #include "PgClass.h" #include "PgIndex.h" #include @@ -10,10 +10,10 @@ class PgDatabaseCatalog; -class IndexModel: public BaseTableModel { +class IndexModel: public QAbstractTableModel { Q_OBJECT public: - using BaseTableModel::BaseTableModel; + using QAbstractTableModel::QAbstractTableModel; enum e_Columns : int { TypeCol, /// primary/unique/normal @@ -30,9 +30,10 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex &index, int role) const override; protected: - virtual Oid getType(int column) const override; - virtual QVariant getData(const QModelIndex &index) const override; + Oid getType(int column) const; + QVariant getData(const QModelIndex &index) const; private: std::shared_ptr m_catalog; diff --git a/pglab/TablesPage.cpp b/pglab/TablesPage.cpp index 40c5913..363b838 100644 --- a/pglab/TablesPage.cpp +++ b/pglab/TablesPage.cpp @@ -15,6 +15,7 @@ #include #include #include "MainWindow.h" +#include "PgLabItemDelegate.h" TablesPage::TablesPage(MainWindow *parent) : QWidget(parent) @@ -46,6 +47,7 @@ TablesPage::TablesPage(MainWindow *parent) SetTableViewDefault(ui->indexesTable); m_indexModel = new IndexModel(this); ui->indexesTable->setModel(m_indexModel); + ui->indexesTable->setItemDelegate(new PgLabItemDelegate(ui->indexesTable)); ui->indexesTable->setItemDelegateForColumn(0, delegate); m_namespaceFilterWidget = new NamespaceFilterWidget(this); @@ -109,7 +111,7 @@ void TablesPage::constraintsTable_currentRowChanged(const QModelIndex ¤t, } } -void TablesPage::constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) +void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/) { const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes(); boost::container::flat_set rijen;