Added page with the types (no details yet)
This commit is contained in:
parent
bdef76ed8a
commit
4c175d8c2c
16 changed files with 418 additions and 11 deletions
|
|
@ -12,7 +12,10 @@ void operator<<(TypCategory &s, const Pgsql::Value &v)
|
|||
case 'B':
|
||||
s = TypCategory::Boolean;
|
||||
break;
|
||||
case 'D':
|
||||
case 'C':
|
||||
s = TypCategory::Composite;
|
||||
break;
|
||||
case 'D':
|
||||
s = TypCategory::DateTime;
|
||||
break;
|
||||
case 'E':
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "TypeSelectionItemModel.h"
|
||||
//#include "CustomDataRole.h"
|
||||
#include "catalog/PgTypeContainer.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
|
@ -56,7 +57,7 @@ void TypeSelectionItemModel::setTypeList(std::shared_ptr<const PgTypeContainer>
|
|||
std::sort(m_types.begin(), m_types.end());
|
||||
}
|
||||
//emit dataChanged(this->createIndex(0, 0), this->createIndex(types->count(), 0), QVector<int>() << Qt::DisplayRole);
|
||||
endResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
// ----------------
|
||||
|
|
@ -82,6 +83,9 @@ int TypeModel::columnCount(const QModelIndex &/*parent*/) const
|
|||
|
||||
QVariant TypeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
// if (role == CustomDataTypeRole)
|
||||
// return getType(index.column());
|
||||
|
||||
if (index.isValid()) {
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
|
|
@ -91,15 +95,90 @@ QVariant TypeModel::data(const QModelIndex &index, int role) const
|
|||
switch (column) {
|
||||
case OidCol: return elem.oid();
|
||||
case NameCol: return elem.objectName();
|
||||
case NamespaceCol: return elem.nsName();
|
||||
case OwnerCol: return elem.ownerName();
|
||||
case CategoryCol: return TypCategoryString(elem.category);
|
||||
}
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QString TypeModel::TypCategoryString(TypCategory tc)
|
||||
{
|
||||
switch (tc) {
|
||||
case TypCategory::Array:
|
||||
return tr("array");
|
||||
case TypCategory::Boolean:
|
||||
return tr("boolean");
|
||||
case TypCategory::Composite:
|
||||
return tr("composite");
|
||||
case TypCategory::DateTime:
|
||||
return tr("datetime");
|
||||
case TypCategory::Enum:
|
||||
return tr("enum");
|
||||
case TypCategory::Geometric:
|
||||
return tr("geometric");
|
||||
case TypCategory::NetworkAddress:
|
||||
return tr("networkaddress");
|
||||
case TypCategory::Numeric:
|
||||
return tr("numeric");
|
||||
case TypCategory::Pseudo:
|
||||
return tr("pseude");
|
||||
case TypCategory::Range:
|
||||
return tr("range");
|
||||
case TypCategory::String:
|
||||
return tr("string");
|
||||
case TypCategory::Timespan:
|
||||
return tr("timespan");
|
||||
case TypCategory::UserDefined:
|
||||
return tr("user");
|
||||
case TypCategory::BitString:
|
||||
return tr("bitstring");
|
||||
case TypCategory::Unknown:
|
||||
return tr("unknown");
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
Oid TypeModel::getType(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case OidCol:
|
||||
return Pgsql::oid_oid;
|
||||
case NameCol:
|
||||
case NamespaceCol:
|
||||
case OwnerCol:
|
||||
case CategoryCol:
|
||||
return Pgsql::varchar_oid;
|
||||
}
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
void TypeModel::setTypeList(std::shared_ptr<const PgTypeContainer> types)
|
||||
{
|
||||
beginResetModel();
|
||||
m_types = types;
|
||||
endResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
PgType TypeModel::typ(int row) const
|
||||
{
|
||||
return m_types->getByIdx(row);
|
||||
}
|
||||
|
||||
QVariant TypeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case OidCol: return tr("Oid");
|
||||
case NameCol: return tr("Name");
|
||||
case NamespaceCol: return tr("Schema");
|
||||
case OwnerCol: return tr("Owner");
|
||||
case CategoryCol: return tr("Category");
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <QAbstractListModel>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "catalog/PgType.h"
|
||||
|
||||
class PgTypeContainer;
|
||||
|
||||
|
|
@ -28,19 +29,27 @@ public:
|
|||
enum e_Columns : int {
|
||||
OidCol,
|
||||
NameCol, //
|
||||
NamespaceCol,
|
||||
OwnerCol,
|
||||
CategoryCol,
|
||||
colCount
|
||||
};
|
||||
|
||||
explicit TypeModel(QObject *parent = 0);
|
||||
|
||||
void setTypeList(std::shared_ptr<const PgTypeContainer> types);
|
||||
PgType typ(int row) const;
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
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;
|
||||
|
||||
static QString TypCategoryString(TypCategory tc);
|
||||
Oid getType(int column) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -211,6 +211,48 @@ QString ConvertToMultiLineRawCppString(const QString &in)
|
|||
return out;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class Token {
|
||||
public:
|
||||
enum Type {
|
||||
Code,
|
||||
StringLiteral,
|
||||
SingleLineComment,
|
||||
MultiLineComment
|
||||
};
|
||||
|
||||
const Type type;
|
||||
/// Depends on type
|
||||
/// Code: literal copy of the matched code
|
||||
/// StringLiteral: the contents of the string literal, escapes have been unescaped
|
||||
/// *Comment, the text in the comment
|
||||
const QString data;
|
||||
|
||||
Token(Type type, QString data)
|
||||
: type(type)
|
||||
, data(data)
|
||||
{}
|
||||
};
|
||||
|
||||
/// Tokenizer to get SQL out of a piece of programming language code
|
||||
///
|
||||
/// It works by ignoring most input and only get's triggered by string literals
|
||||
/// and comments. It does return tokens for the code in between just so
|
||||
class ProgLangTokenizer {
|
||||
public:
|
||||
ProgLangTokenizer(const QString &in)
|
||||
: input(in)
|
||||
{}
|
||||
|
||||
private:
|
||||
const QString input;
|
||||
int position = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QString ConvertLangToSqlString(const QString &in)
|
||||
{
|
||||
// Assume mostly C++ for now but allow some other things like
|
||||
|
|
@ -232,6 +274,7 @@ QString ConvertLangToSqlString(const QString &in)
|
|||
WHITESPACE,
|
||||
PREFIX,
|
||||
IN_STRING,
|
||||
SingleLineComment,
|
||||
END,
|
||||
ERROR
|
||||
} state = WHITESPACE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue