2017-08-23 13:27:23 +02:00
|
|
|
|
#include "TypeSelectionItemModel.h"
|
2017-02-04 11:55:49 +01:00
|
|
|
|
#include "PgTypeContainer.h"
|
2017-02-20 06:44:15 +01:00
|
|
|
|
#include <algorithm>
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent)
|
|
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-16 21:41:46 +01:00
|
|
|
|
int TypeSelectionItemModel::rowCount(const QModelIndex &/*parent*/) const
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2018-12-15 20:27:40 +01:00
|
|
|
|
int result = static_cast<int>(m_types.size());
|
2017-02-01 18:01:02 +01:00
|
|
|
|
// if (!parent.isValid()) {
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-16 21:41:46 +01:00
|
|
|
|
int TypeSelectionItemModel::columnCount(const QModelIndex &/*parent*/) const
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2018-12-15 20:27:40 +01:00
|
|
|
|
int result = 2;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
// 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) {
|
2017-02-20 06:44:15 +01:00
|
|
|
|
//const PgType &tp = m_types->getByIdx(row);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
if (column == 0) {
|
2018-12-15 20:27:40 +01:00
|
|
|
|
result = m_types[static_cast<size_t>(row)]; //tp.typname;
|
|
|
|
|
|
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2017-02-04 11:55:49 +01:00
|
|
|
|
|
2017-12-09 20:21:22 +01:00
|
|
|
|
void TypeSelectionItemModel::setTypeList(std::shared_ptr<const PgTypeContainer> types)
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
beginResetModel();
|
2017-02-20 06:44:15 +01:00
|
|
|
|
m_types.clear();
|
|
|
|
|
|
for (const auto &e : *types) {
|
2017-12-12 20:13:53 +01:00
|
|
|
|
if (e.category != TypCategory::Array && e.type != "c") {
|
|
|
|
|
|
m_types.push_back(e.name);
|
2017-02-20 06:44:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
std::sort(m_types.begin(), m_types.end());
|
2017-02-04 11:55:49 +01:00
|
|
|
|
//emit dataChanged(this->createIndex(0, 0), this->createIndex(types->count(), 0), QVector<int>() << Qt::DisplayRole);
|
|
|
|
|
|
endResetModel();
|
|
|
|
|
|
}
|
2018-12-15 20:27:40 +01:00
|
|
|
|
|
|
|
|
|
|
// ----------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TypeModel::TypeModel(QObject *parent)
|
|
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TypeModel::rowCount(const QModelIndex &/*parent*/) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_types)
|
|
|
|
|
|
return static_cast<int>(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<const PgTypeContainer> types)
|
|
|
|
|
|
{
|
|
|
|
|
|
beginResetModel();
|
|
|
|
|
|
m_types = types;
|
|
|
|
|
|
endResetModel();
|
|
|
|
|
|
}
|