From 742fd0a4d3f599e5462ce9a7427ec7a9c083cea0 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 15 Dec 2018 20:27:40 +0100 Subject: [PATCH] SelectionEditorFactory + ItemModel + ItemModelFactory combination is working in new EditTableWidget (EditTableWidget is very much WIP) --- .gitignore | 1 + pglab/EditColumnTableModel.cpp | 132 ++++++++++++++++++ pglab/EditColumnTableModel.h | 64 +++++++++ pglab/EditTableWidget.cpp | 44 ++++++ pglab/EditTableWidget.h | 23 +++ pglab/MainWindow.cpp | 12 +- pglab/MainWindow.h | 1 + pglab/ParamTypeDelegate.cpp | 19 --- pglab/ParamTypeDelegate.h | 10 +- pglab/PgLabItemDelegate.cpp | 6 +- pglab/pglab.pro | 10 +- pglablib/SelectionEditorFactory.cpp | 25 ++-- pglablib/SqlFormattingUtils.cpp | 20 +++ pglablib/TypeModelFactory.cpp | 15 ++ ...nItemModelFactory.h => TypeModelFactory.h} | 4 +- pglablib/TypeSelectionItemModel.cpp | 64 ++++++--- pglablib/TypeSelectionItemModel.h | 22 +++ pglablib/TypeSelectionItemModelFactory.cpp | 15 -- pglablib/pglablib.pro | 12 +- 19 files changed, 419 insertions(+), 80 deletions(-) create mode 100644 pglab/EditColumnTableModel.cpp create mode 100644 pglab/EditColumnTableModel.h create mode 100644 pglab/EditTableWidget.cpp create mode 100644 pglab/EditTableWidget.h create mode 100644 pglablib/TypeModelFactory.cpp rename pglablib/{TypeSelectionItemModelFactory.h => TypeModelFactory.h} (69%) delete mode 100644 pglablib/TypeSelectionItemModelFactory.cpp diff --git a/.gitignore b/.gitignore index 66f9c96..010f368 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build/* DIST/ *.autosave srcdoc/ +pglabAll.pro.user.4.8-pre1 diff --git a/pglab/EditColumnTableModel.cpp b/pglab/EditColumnTableModel.cpp new file mode 100644 index 0000000..58c512a --- /dev/null +++ b/pglab/EditColumnTableModel.cpp @@ -0,0 +1,132 @@ +#include "EditColumnTableModel.h" + +EditColumnTableModel::EditColumnTableModel(QObject *parent) + : QAbstractTableModel(parent) +{ + m_data.push_back({}); +} + +QVariant EditColumnTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (role == Qt::DisplayRole) { + if (orientation == Qt::Horizontal) { + switch(section) { + case NameCol: return tr("Column name"); + case TypeCol: return tr("Type"); + case LengthCol: return tr("Length"); + case ScaleCol: return tr("Scale"); + case CollateCol: return tr("Collate"); + case NotNullCol: return tr("NN"); + case DefaultCol: return tr("Default"); + case PrimaryKeyCol: return tr("P"); + case UniqueCol: return tr("U"); + case CommentCol: return tr("Comment"); + } + } + } + return {}; +} + +int EditColumnTableModel::rowCount(const QModelIndex &) const +{ + return static_cast(m_data.size()); +} + +int EditColumnTableModel::columnCount(const QModelIndex &) const +{ + return colCount; +} + +QVariant EditColumnTableModel::data(const QModelIndex &index, int role) const +{ + size_t rij = static_cast(index.row()); + auto && d = m_data.at(rij); + if (role == Qt::EditRole || role == Qt::DisplayRole) { + switch (index.column()) { + case NameCol: return d.name; + case TypeCol: return d.type; + case LengthCol: return d.length; + case ScaleCol: return d.scale; + case CollateCol: return d.collate; + case NotNullCol: return d.notNull; + case DefaultCol: return d.def; + case PrimaryKeyCol: return d.primaryKey; + case UniqueCol: return d.unique; + case CommentCol: return d.comment; + } + } + return {}; +} + +Qt::ItemFlags EditColumnTableModel::flags(const QModelIndex &) const +{ + Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; + flags |= Qt::ItemIsEditable; + return flags; + +} + +bool EditColumnTableModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + size_t rij = static_cast(index.row()); + auto && d = m_data.at(rij); + if (role == Qt::EditRole || role == Qt::DisplayRole) { + const int col = index.column(); + if (col == NameCol) { + d.name = value.toString(); + return true; + } + else if (col == TypeCol) { + d.type = value.toInt(); + return true; + } + else if (col == LengthCol) { + d.length = value.toInt(); + return true; + } + else if (col == ScaleCol) { + d.scale = value.toInt(); + return true; + } + else if (col == CollateCol) { + d.collate = value.toInt(); + return true; + } + else if (col == NotNullCol) { + d.notNull = value.toBool(); + return true; + } + else if (col == DefaultCol) { + d.def = value.toString(); + return true; + } + else if (col == PrimaryKeyCol) { + d.primaryKey = value.toInt(); + return true; + } + else if (col == UniqueCol) { + d.notNull = value.toBool(); + return true; + } + else if (col == CommentCol) { + d.comment = value.toString(); + return true; + } + } + return false; +} + +bool EditColumnTableModel::removeRows(int row, int count, const QModelIndex &parent) +{ + return false; +} + +//bool EditColumnTableModel::submit() +//{ + +//} + +//void EditColumnTableModel::revert() +//{ + +//} diff --git a/pglab/EditColumnTableModel.h b/pglab/EditColumnTableModel.h new file mode 100644 index 0000000..c6abd99 --- /dev/null +++ b/pglab/EditColumnTableModel.h @@ -0,0 +1,64 @@ +#ifndef EDITCOLUMNTABLEMODEL_H +#define EDITCOLUMNTABLEMODEL_H + +#include +#include "Pgsql_oids.h" + + +class Column { +public: + QString name; + Oid type = InvalidOid; + int length = -1; // varchar, date/time, numeric (precision) + int scale = -1; // numeric scale + Oid collate = InvalidOid; + bool notNull = true; + QString def; + int primaryKey = 0; + bool unique = false; + QString comment; +}; + + +class EditColumnTableModel: public QAbstractTableModel { + Q_OBJECT +public: + enum Columns : int { + NameCol = 0, + TypeCol, + LengthCol, + ScaleCol, + CollateCol, + NotNullCol, + DefaultCol, + PrimaryKeyCol, + UniqueCol, + CommentCol, + + colCount + }; + + EditColumnTableModel(QObject *parent = nullptr); + + + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override; + virtual QVariant data(const QModelIndex &index, int role) const override; + + virtual Qt::ItemFlags flags(const QModelIndex &) const override; + virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override; + virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; + +public slots: +// virtual bool submit() override; +// virtual void revert() override; + +private: + using ColumnList = std::vector; + + ColumnList m_data; ///< Better call it data as columns would be confusing +}; + + +#endif // EDITCOLUMNTABLEMODEL_H diff --git a/pglab/EditTableWidget.cpp b/pglab/EditTableWidget.cpp new file mode 100644 index 0000000..c3a43d2 --- /dev/null +++ b/pglab/EditTableWidget.cpp @@ -0,0 +1,44 @@ +#include "EditTableWidget.h" +#include "EditColumnTableModel.h" +#include "PgLabItemDelegate.h" +#include +#include +#include "OpenDatabase.h" +#include "PgDatabaseCatalog.h" +#include "SelectionEditorFactory.h" +#include "TypeModelFactory.h" + +EditTableWidget::EditTableWidget(std::shared_ptr database, QWidget *parent) + : QWidget(parent) + , m_database(database) +{ + + + // Table + auto table = new QTableView(this); + // Dialogbutton + + auto mainLayout = new QVBoxLayout(this); + mainLayout->addWidget(table); + setLayout(mainLayout); + + auto model = new EditColumnTableModel(this); + table->setModel(model); + table->setItemDelegate(new PgLabItemDelegate(this)); + + auto types = database->catalog()->types(); + auto type_delegate = new PgLabItemDelegate(this); + type_delegate->setEditorFactory( + new SelectionEditorFactory(this, new TypeModelFactory(this, types), 0, 1) + ); + table->setItemDelegateForColumn(EditColumnTableModel::TypeCol, type_delegate); + + +// if (opendb) { +// m_typeDelegate.setTypeSelectionModel(opendb->typeSelectionModel()); +// } + +// paramTableView->setModel(&m_paramList); +// paramTableView->setItemDelegateForColumn(1, &m_typeDelegate); +} + diff --git a/pglab/EditTableWidget.h b/pglab/EditTableWidget.h new file mode 100644 index 0000000..05b5bf5 --- /dev/null +++ b/pglab/EditTableWidget.h @@ -0,0 +1,23 @@ +#ifndef EDITTABLEWIDGET_H +#define EDITTABLEWIDGET_H + +#include +#include +#include + +class OpenDatabase; + +class EditTableWidget : public QWidget { + Q_OBJECT +public: + explicit EditTableWidget(std::shared_ptr database, QWidget *parent = nullptr); + +signals: + +public slots: + +private: + std::shared_ptr m_database; +}; + +#endif // EDITTABLEWIDGET_H diff --git a/pglab/MainWindow.cpp b/pglab/MainWindow.cpp index 60bb636..5614b1b 100644 --- a/pglab/MainWindow.cpp +++ b/pglab/MainWindow.cpp @@ -20,6 +20,7 @@ #include "CrudTab.h" #include "WorkManager.h" #include "ScopeGuard.h" +#include "EditTableWidget.h" namespace pg = Pgsql; @@ -43,20 +44,22 @@ QueryTab* MainWindow::newSqlPage() { QueryTab *qt = new QueryTab(this); qt->setConfig(m_config, m_database->catalog()); -// ui->tabWidget->addTab(qt, "Tab"); -// ui->tabWidget->setCurrentWidget(qt); addPage(qt, "Tab"); qt->newdoc(); qt->focusEditor(); return qt; } +void MainWindow::newCreateTablePage() +{ + auto w = new EditTableWidget(m_database, this); + ui->tabWidget->addTab(w, "Create table"); +} + void MainWindow::newCrudPage(const PgClass &table) { CrudTab *ct = new CrudTab(this); ct->setConfig(m_database, table); -// ui->tabWidget->addTab(ct, table.name); -// ui->tabWidget->setCurrentWidget(ct); addPage(ct, table.objectName()); } @@ -110,6 +113,7 @@ void MainWindow::catalogLoaded() ui->tabWidget->addTab(functions_page, "Functions"); newSqlPage(); + newCreateTablePage(); } catch (std::runtime_error &ex) { QMessageBox::critical(this, "Error reading database", QString::fromUtf8(ex.what())); diff --git a/pglab/MainWindow.h b/pglab/MainWindow.h index 4fcfa60..33e4406 100644 --- a/pglab/MainWindow.h +++ b/pglab/MainWindow.h @@ -90,6 +90,7 @@ private: void closeEvent(QCloseEvent *event); void showEvent(QShowEvent *event); QueryTab *newSqlPage(); + void newCreateTablePage(); void catalogLoaded(); diff --git a/pglab/ParamTypeDelegate.cpp b/pglab/ParamTypeDelegate.cpp index 58d4af8..2083de8 100644 --- a/pglab/ParamTypeDelegate.cpp +++ b/pglab/ParamTypeDelegate.cpp @@ -26,24 +26,11 @@ QWidget *ParamTypeDelegate::createEditor(QWidget *parent, cmbbx->setModel(m_typeSelectionModel); w = cmbbx; -// ... -// m_ComboBox->setView(m_ColumnView); -// m_ComboBox->view()->setCornerWidget(new QSizeGrip(m_ColumnView)); -// m_ComboBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); -// ... - return w; } void ParamTypeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { -// if (index.data().canConvert()) { -// StarRating starRating = qvariant_cast(index.data()); -// StarEditor *starEditor = qobject_cast(editor); -// starEditor->setStarRating(starRating); -// } else { -// QStyledItemDelegate::setEditorData(editor, index); -// } if (index.column() == 1) { QComboBox *cmbbx = dynamic_cast(editor); if (cmbbx) { @@ -68,12 +55,6 @@ void ParamTypeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) void ParamTypeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { -// if (index.data().canConvert()) { -// StarEditor *starEditor = qobject_cast(editor); -// model->setData(index, QVariant::fromValue(starEditor->starRating())); -// } else { -// QStyledItemDelegate::setModelData(editor, model, index); -// } if (index.column() == 1) { QComboBox *cmbbx = dynamic_cast(editor); if (cmbbx) { diff --git a/pglab/ParamTypeDelegate.h b/pglab/ParamTypeDelegate.h index c6d463f..757803c 100644 --- a/pglab/ParamTypeDelegate.h +++ b/pglab/ParamTypeDelegate.h @@ -1,25 +1,27 @@ #ifndef PARAMTYPEDELEGATE_H #define PARAMTYPEDELEGATE_H -#include +//#include +#include "PgLabItemDelegate.h" class TypeSelectionItemModel; /** Item delegate for supplying a combobox for selected the parameter type in * the parameter list. */ -class ParamTypeDelegate : public QStyledItemDelegate { +class ParamTypeDelegate : public PgLabItemDelegate { Q_OBJECT public: ParamTypeDelegate(); - ~ParamTypeDelegate(); + ~ParamTypeDelegate() override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - void setTypeSelectionModel(TypeSelectionItemModel* model); void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + + void setTypeSelectionModel(TypeSelectionItemModel* model); private: TypeSelectionItemModel* m_typeSelectionModel = nullptr; diff --git a/pglab/PgLabItemDelegate.cpp b/pglab/PgLabItemDelegate.cpp index 85aa03e..743b34a 100644 --- a/pglab/PgLabItemDelegate.cpp +++ b/pglab/PgLabItemDelegate.cpp @@ -134,19 +134,23 @@ QWidget *PgLabItemDelegate::createEditor(QWidget *parent, const QStyleOptionView { if (m_editorFactory) return m_editorFactory->createEditor(parent, option, index); - return nullptr; + return QStyledItemDelegate::createEditor(parent, option, index); } void PgLabItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (m_editorFactory) m_editorFactory->setEditorData(editor, index); + else + QStyledItemDelegate::setEditorData(editor, index); } void PgLabItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if (m_editorFactory) m_editorFactory->setModelData(editor, model, index); + else + QStyledItemDelegate::setModelData(editor, model, index); } AbstractEditorFactory* PgLabItemDelegate::editorFactory() diff --git a/pglab/pglab.pro b/pglab/pglab.pro index b388352..0b7672a 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -37,7 +37,6 @@ SOURCES += main.cpp\ stopwatch.cpp \ TuplesResultWidget.cpp \ BackupDialog.cpp \ - TypeSelectionItemModel.cpp \ MasterController.cpp \ ParamTypeDelegate.cpp \ OpenDatabase.cpp \ @@ -80,7 +79,9 @@ PropertyProxyModel.cpp \ PasswordPromptDialog.cpp \ ProcTableModel.cpp \ FunctionsPage.cpp \ - ColumnPage.cpp + ColumnPage.cpp \ + EditTableWidget.cpp \ + EditColumnTableModel.cpp HEADERS += \ QueryResultModel.h \ @@ -93,7 +94,6 @@ HEADERS += \ stopwatch.h \ TuplesResultWidget.h \ BackupDialog.h \ - TypeSelectionItemModel.h \ MasterController.h \ ParamTypeDelegate.h \ OpenDatabase.h \ @@ -138,7 +138,9 @@ CustomDataRole.h \ PasswordPromptDialog.h \ ProcTableModel.h \ FunctionsPage.h \ - ColumnPage.h + ColumnPage.h \ + EditTableWidget.h \ + EditColumnTableModel.h FORMS += mainwindow.ui \ ConnectionManagerWindow.ui \ diff --git a/pglablib/SelectionEditorFactory.cpp b/pglablib/SelectionEditorFactory.cpp index 1b59448..ea4d98c 100644 --- a/pglablib/SelectionEditorFactory.cpp +++ b/pglablib/SelectionEditorFactory.cpp @@ -30,16 +30,15 @@ void SelectionEditorFactory::setEditorData(QWidget *editor, const QModelIndex &i QComboBox *cmbbx = dynamic_cast(editor); if (cmbbx) { auto data = index.data(); - if (data.canConvert()) { - auto selection_model = cmbbx->model(); - QModelIndexList indexes = selection_model->match( - selection_model->index(0, m_keyColumn), Qt::DisplayRole, data, 1, Qt::MatchFlags( Qt::MatchExactly )); - if (!indexes.empty()) { - cmbbx->setCurrentIndex(indexes.at(0).row()); - } - else { - cmbbx->setCurrentIndex(-1); - } + + auto list_model = cmbbx->model(); + QModelIndexList indexes = list_model->match( + list_model->index(0, m_keyColumn), Qt::DisplayRole, data, 1, Qt::MatchFlags( Qt::MatchExactly )); + if (!indexes.empty()) { + cmbbx->setCurrentIndex(indexes.at(0).row()); + } + else { + cmbbx->setCurrentIndex(-1); } } } @@ -50,9 +49,9 @@ void SelectionEditorFactory::setModelData(QWidget *editor, QAbstractItemModel *m if (cmbbx) { auto data = index.data(); if (data.canConvert()) { - auto selection_model = cmbbx->model(); - QVariant d = selection_model->data( - selection_model->index(cmbbx->currentIndex(), m_keyColumn)); + auto list_model = cmbbx->model(); + QVariant d = list_model->data( + list_model->index(cmbbx->currentIndex(), m_keyColumn)); model->setData(index, d); } } diff --git a/pglablib/SqlFormattingUtils.cpp b/pglablib/SqlFormattingUtils.cpp index 73633db..15c8936 100644 --- a/pglablib/SqlFormattingUtils.cpp +++ b/pglablib/SqlFormattingUtils.cpp @@ -411,3 +411,23 @@ QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstr } +//rolename=xxxx -- privileges granted to a role +// =xxxx -- privileges granted to PUBLIC + +// r -- SELECT ("read") +// w -- UPDATE ("write") +// a -- INSERT ("append") +// d -- DELETE +// D -- TRUNCATE +// x -- REFERENCES +// t -- TRIGGER +// X -- EXECUTE +// U -- USAGE +// C -- CREATE +// c -- CONNECT +// T -- TEMPORARY +// arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects) +// * -- grant option for preceding privilege + +// /yyyy -- role that granted this privilege + diff --git a/pglablib/TypeModelFactory.cpp b/pglablib/TypeModelFactory.cpp new file mode 100644 index 0000000..6a23cc3 --- /dev/null +++ b/pglablib/TypeModelFactory.cpp @@ -0,0 +1,15 @@ +#include "TypeModelFactory.h" +#include "TypeSelectionItemModel.h" + +TypeModelFactory::TypeModelFactory(QObject *parent, std::shared_ptr types) + : AbstractModelFactory(parent) + , m_types(types) +{} + + +QAbstractItemModel* TypeModelFactory::createModel(QObject *parent) const +{ + auto model = new TypeModel(parent); + model->setTypeList(m_types); + return model; +} diff --git a/pglablib/TypeSelectionItemModelFactory.h b/pglablib/TypeModelFactory.h similarity index 69% rename from pglablib/TypeSelectionItemModelFactory.h rename to pglablib/TypeModelFactory.h index 7e8d3a8..8a49ca0 100644 --- a/pglablib/TypeSelectionItemModelFactory.h +++ b/pglablib/TypeModelFactory.h @@ -6,10 +6,10 @@ class PgTypeContainer; void setTypeList(); -class TypeSelectionItemModelFactory: public AbstractModelFactory { +class TypeModelFactory: public AbstractModelFactory { Q_OBJECT public: - TypeSelectionItemModelFactory(QObject *parent, std::shared_ptr types); + TypeModelFactory(QObject *parent, std::shared_ptr types); virtual QAbstractItemModel* createModel(QObject *parent = nullptr) const override; diff --git a/pglablib/TypeSelectionItemModel.cpp b/pglablib/TypeSelectionItemModel.cpp index 8c895fe..adfe0d0 100644 --- a/pglablib/TypeSelectionItemModel.cpp +++ b/pglablib/TypeSelectionItemModel.cpp @@ -9,7 +9,7 @@ TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent) int TypeSelectionItemModel::rowCount(const QModelIndex &/*parent*/) const { - int result = m_types.size(); + int result = static_cast(m_types.size()); // if (!parent.isValid()) { // } @@ -18,7 +18,7 @@ int TypeSelectionItemModel::rowCount(const QModelIndex &/*parent*/) const int TypeSelectionItemModel::columnCount(const QModelIndex &/*parent*/) const { - int result = 1; + int result = 2; // if (parent.isValid()) // result = 1; @@ -35,21 +35,8 @@ QVariant TypeSelectionItemModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { //const PgType &tp = m_types->getByIdx(row); if (column == 0) { - result = m_types[row]; //tp.typname; + result = m_types[static_cast(row)]; //tp.typname; -// switch (row) { -// case 0: result = "integer"; break; -// case 1: result = "numeric"; break; -// case 2: result = "timestamp"; break; -// case 3: result = "timestamptz"; break; -// case 4: result = "float"; break; -// case 5: result = "double"; break; -// case 6: result = "date"; break; -// case 7: result = "varchar"; break; -// case 8: result = "varchar"; break; -// case 9: result = "varchar"; break; - -// } } } } @@ -69,3 +56,48 @@ void TypeSelectionItemModel::setTypeList(std::shared_ptr //emit dataChanged(this->createIndex(0, 0), this->createIndex(types->count(), 0), QVector() << Qt::DisplayRole); endResetModel(); } + +// ---------------- + + +TypeModel::TypeModel(QObject *parent) + : QAbstractListModel(parent) +{ +} + +int TypeModel::rowCount(const QModelIndex &/*parent*/) const +{ + if (m_types) + return static_cast(m_types->count()); + + return 0; +} + +int TypeModel::columnCount(const QModelIndex &/*parent*/) const +{ + return colCount; +} + +QVariant TypeModel::data(const QModelIndex &index, int role) const +{ + if (index.isValid()) { + int row = index.row(); + int column = index.column(); + if (role == Qt::DisplayRole) { + //const PgType &tp = m_types->getByIdx(row); + auto elem = m_types->getByIdx(row); + switch (column) { + case OidCol: return elem.oid; + case NameCol: return elem.name; + } + } + } + return QVariant(); +} + +void TypeModel::setTypeList(std::shared_ptr types) +{ + beginResetModel(); + m_types = types; + endResetModel(); +} diff --git a/pglablib/TypeSelectionItemModel.h b/pglablib/TypeSelectionItemModel.h index 6863484..c5e71fb 100644 --- a/pglablib/TypeSelectionItemModel.h +++ b/pglablib/TypeSelectionItemModel.h @@ -22,4 +22,26 @@ private: std::vector m_types; }; +class TypeModel : public QAbstractListModel { + Q_OBJECT +public: + enum e_Columns : int { + OidCol, + NameCol, // + colCount + }; + + explicit TypeModel(QObject *parent = 0); + + void setTypeList(std::shared_ptr types); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +private: + std::shared_ptr m_types; +}; + + #endif // TYPESELECTIONITEMMODEL_H diff --git a/pglablib/TypeSelectionItemModelFactory.cpp b/pglablib/TypeSelectionItemModelFactory.cpp deleted file mode 100644 index 330f41e..0000000 --- a/pglablib/TypeSelectionItemModelFactory.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "TypeSelectionItemModelFactory.h" -#include "TypeSelectionItemModel.h" - -TypeSelectionItemModelFactory::TypeSelectionItemModelFactory(QObject *parent, std::shared_ptr types) - : AbstractModelFactory(parent) - , m_types(types) -{} - - -QAbstractItemModel* TypeSelectionItemModelFactory::createModel(QObject *parent) const -{ - auto model = new TypeSelectionItemModel(parent); - model->setTypeList(m_types); - return model; -} diff --git a/pglablib/pglablib.pro b/pglablib/pglablib.pro index d2c76b9..bcf84ef 100644 --- a/pglablib/pglablib.pro +++ b/pglablib/pglablib.pro @@ -75,7 +75,10 @@ codebuilder/StructureTemplate.cpp \ PgCollation.cpp \ PgCollationContainer.cpp \ PgInherits.cpp \ - PgInheritsContainer.cpp + PgInheritsContainer.cpp \ + TypeSelectionItemModel.cpp \ + SelectionEditorFactory.cpp \ + TypeModelFactory.cpp HEADERS += \ Pglablib.h \ @@ -132,8 +135,13 @@ codebuilder/StructureTemplate.h \ PgNamespaceObject.h \ PgCollation.h \ PgCollationContainer.h \ + AbstractModelFactory.h \ + AbstractEditorFactory.h \ PgInherits.h \ - PgInheritsContainer.h + PgInheritsContainer.h \ + SelectionEditorFactory.h \ + TypeSelectionItemModel.h \ + TypeModelFactory.h unix { target.path = /usr/lib