#include "TypeSelectionItemModel.h" #include "PgTypeContainer.h" #include TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent) : QAbstractListModel(parent) { } int TypeSelectionItemModel::rowCount(const QModelIndex &/*parent*/) const { int result = static_cast(m_types.size()); // if (!parent.isValid()) { // } return result; } int TypeSelectionItemModel::columnCount(const QModelIndex &/*parent*/) const { int result = 2; // if (parent.isValid()) // result = 1; return result; } QVariant TypeSelectionItemModel::data(const QModelIndex &index, int role) const { QVariant result; if (index.isValid()) { int row = index.row(); int column = index.column(); if (role == Qt::DisplayRole) { //const PgType &tp = m_types->getByIdx(row); if (column == 0) { result = m_types[static_cast(row)]; //tp.typname; } } } return result; } void TypeSelectionItemModel::setTypeList(std::shared_ptr types) { beginResetModel(); m_types.clear(); for (const auto &e : *types) { if (e.category != TypCategory::Array && e.type != "c") { m_types.push_back(e.objectName()); } } std::sort(m_types.begin(), m_types.end()); //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.objectName(); } } } return QVariant(); } void TypeModel::setTypeList(std::shared_ptr types) { beginResetModel(); m_types = types; endResetModel(); }