Reorganize files in pglablib

The enitities and containers of the catalog now go into catalog subfolder
Models go into model
This commit is contained in:
eelke 2018-12-16 10:17:59 +01:00
parent 56cbeea183
commit f0c1035378
121 changed files with 226 additions and 183 deletions

View file

@ -0,0 +1,6 @@
#include "CollationModel.h"
CollationModel::CollationModel()
{
}

View file

@ -0,0 +1,11 @@
#ifndef COLLATIONMODEL_H
#define COLLATIONMODEL_H
class CollationModel
{
public:
CollationModel();
};
#endif // COLLATIONMODEL_H

View file

@ -0,0 +1,6 @@
#include "CollationModelFactory.h"
CollationModelFactory::CollationModelFactory()
{
}

View file

@ -0,0 +1,11 @@
#ifndef COLLATIONMODELFACTORY_H
#define COLLATIONMODELFACTORY_H
class CollationModelFactory
{
public:
CollationModelFactory();
};
#endif // COLLATIONMODELFACTORY_H

View file

@ -0,0 +1,15 @@
#include "TypeModelFactory.h"
#include "TypeSelectionItemModel.h"
TypeModelFactory::TypeModelFactory(QObject *parent, std::shared_ptr<const PgTypeContainer> types)
: AbstractModelFactory(parent)
, m_types(types)
{}
QAbstractItemModel* TypeModelFactory::createModel(QObject *parent) const
{
auto model = new TypeModel(parent);
model->setTypeList(m_types);
return model;
}

View file

@ -0,0 +1,19 @@
#ifndef TYPESELECTIONITEMMODELFACTORY_H
#define TYPESELECTIONITEMMODELFACTORY_H
#include "AbstractModelFactory.h"
class PgTypeContainer;
class TypeModelFactory: public AbstractModelFactory {
Q_OBJECT
public:
TypeModelFactory(QObject *parent, std::shared_ptr<const PgTypeContainer> types);
virtual QAbstractItemModel* createModel(QObject *parent = nullptr) const override;
private:
std::shared_ptr<const PgTypeContainer> m_types;
};
#endif // TYPESELECTIONITEMMODELFACTORY_H

View file

@ -0,0 +1,103 @@
#include "TypeSelectionItemModel.h"
#include "catalog/PgTypeContainer.h"
#include <algorithm>
TypeSelectionItemModel::TypeSelectionItemModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int TypeSelectionItemModel::rowCount(const QModelIndex &/*parent*/) const
{
int result = static_cast<int>(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<size_t>(row)]; //tp.typname;
}
}
}
return result;
}
void TypeSelectionItemModel::setTypeList(std::shared_ptr<const PgTypeContainer> 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<int>() << Qt::DisplayRole);
endResetModel();
}
// ----------------
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.objectName();
}
}
}
return QVariant();
}
void TypeModel::setTypeList(std::shared_ptr<const PgTypeContainer> types)
{
beginResetModel();
m_types = types;
endResetModel();
}

View file

@ -0,0 +1,47 @@
#ifndef TYPESELECTIONITEMMODEL_H
#define TYPESELECTIONITEMMODEL_H
#include <QAbstractListModel>
#include <memory>
#include <vector>
class PgTypeContainer;
class TypeSelectionItemModel : public QAbstractListModel {
Q_OBJECT
public:
explicit TypeSelectionItemModel(QObject *parent = 0);
void setTypeList(std::shared_ptr<const PgTypeContainer> 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::vector<QString> 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<const PgTypeContainer> 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<const PgTypeContainer> m_types;
};
#endif // TYPESELECTIONITEMMODEL_H