Lot of code for generating code. Working on unit tests.

This commit is contained in:
eelke 2018-09-09 18:52:32 +02:00
parent da45929b12
commit 8f4845d4d2
42 changed files with 1089 additions and 267 deletions

View file

@ -1,6 +1,7 @@
#include "BaseTableModel.h"
#include "ResultTableModelUtil.h"
#include <QBrush>
#include "Pgsql_oids.h"
using namespace Pgsql;
@ -10,7 +11,7 @@ QVariant BaseTableModel::data(const QModelIndex &index, int role) const
Oid oid = getType(index.column());
if (role == Qt::DisplayRole) {
v = getData(index);
if (oid == BOOLOID) {
if (oid == bool_oid) {
v = FormatBoolForDisplay(v.toBool());
}
}
@ -18,7 +19,7 @@ QVariant BaseTableModel::data(const QModelIndex &index, int role) const
v = (int)GetDefaultAlignmentForType(oid);
}
else if (role == Qt::ForegroundRole) {
if (oid == BOOLOID) {
if (oid == bool_oid) {
QVariant d = getData(index);
if (d.type() == QVariant::Bool) {
v = QBrush(GetDefaultBoolColor(d.toBool()));

View file

@ -1,8 +0,0 @@
#include "CodeBuilderConfiguration.h"
#include "Pgsql_Result.h"
QString CodeBuilder::GenClassDefinition(const Pgsql::Result &/*result*/) const
{
return QString();
}

View file

@ -1,120 +0,0 @@
#pragma once
#include <QString>
#include <QStringBuilder>
#include <libpq-fe.h>
namespace Pgsql { class Result; }
/*
class PgAuthId {
public:
PgAuthId();
Oid oid = InvalidOid;
QString name;
bool super;
bool inherit;
bool createRole;
bool createDB;
bool canlogin;
bool replication;
bool bypassRls;
int connLimit;
QDateTime validUntil;*/
/** Defines how a database result fieldname should be converted into a variable
* name in the target language.
*
*/
class VarNameManglingRules {
public:
enum class CollisionHandling {
Restrict, ///< An error will be reported and no code generated
Fqn, ///< Turn into fully qualified name (table_column)
Number ///< A number will be appended to fields that have the same name
};
enum class CaseConversion {
AsIs,
Upper,
Lower
};
QString replaceSpaceWith; ///< default is empty string which means remove spaces
CollisionHandling CollisionHandling = CollisionHandling::Restrict;
CaseConversion caseConversion = CaseConversion::AsIs; ///< overall case conversion rule
CaseConversion caseFirstChar = CaseConversion::AsIs; ///< case of the first char
bool underscoreToCamel = false; ///< remove underscores and make first char after underscore uppercase
};
/**
*
*/
class LanguageConfig {
public:
/** Default template for declaring a variable of the correct type.
* exmaple: "{$type} {$varname};"
*/
QString varDeclTemplate;
VarNameManglingRules varNaming;
enum class VariableStrategy {
UseLocalVariables,
DeclareClass
};
QString classStartTemplate;
QString classEndTemplate;
QString classFieldTemplate;
};
/**
*
* There are some default fallbacks in place
* - smallint > integer
* - integer > bigint
* - int2 > smallint
* - int4 > integer
* - int8 > bigint
*
* - float > double
* - text > varchar
*/
class TypeConfig {
public:
/** The following template allows you to derive the variable name from the result fieldname.
*
* {$} in the suplied value will be replaced with the name of the result field.
*
* example: {$}
*/
QString varNameTemplate;
QString typeIdent;
QString varDeclTemplate; ///< Overrules the default template in the language config
// Mapping() = default;
// Mapping(Oid oid, QString lang_type_ident)
// : db_oid(oid), lang_type(lang_type_ident)
// {}
//
// bool operator < (const Mapping &rhs) const
// {
// return db_oid < rhs.db_oid;
// }
};
class TypeMappings {
public:
private:
};
class CodeBuilderConfiguration {
public:
};
class CodeBuilder {
public:
QString GenClassDefinition(const Pgsql::Result &result) const;
};

View file

@ -140,7 +140,7 @@ int ColumnTableModel::columnCount(const QModelIndex &/*parent*/) const
Oid ColumnTableModel::getType(int /*column*/) const
{
Oid oid = Pgsql::VARCHAROID;
Oid oid = Pgsql::varchar_oid;
// switch (column) {
// case TypeCol:
// case NameCol:

View file

@ -79,12 +79,12 @@ QVariant ConstraintModel::headerData(int section, Qt::Orientation orientation, i
return v;
}
int ConstraintModel::rowCount(const QModelIndex &parent) const
int ConstraintModel::rowCount(const QModelIndex &) const
{
return m_constraints.size();
}
int ConstraintModel::columnCount(const QModelIndex &parent) const
int ConstraintModel::columnCount(const QModelIndex &) const
{
return colCount;
}
@ -99,7 +99,7 @@ int ConstraintModel::columnCount(const QModelIndex &parent) const
// return v;
//}
Oid ConstraintModel::getType(int column) const
Oid ConstraintModel::getType(int ) const
{
Oid oid = Pgsql::varchar_oid;

View file

@ -84,10 +84,10 @@ Oid DatabasesTableModel::getType(int column) const
switch (column) {
case AllowConnCol:
case IsTemplateCol:
oid = BOOLOID;
oid = bool_oid;
break;
case ConnLimitCol:
oid = INT4OID;
oid = int4_oid;
break;
case AclCol:
case CollateCol:
@ -96,7 +96,7 @@ Oid DatabasesTableModel::getType(int column) const
case DbaCol:
case NameCol:
case TablespaceCol:
oid = VARCHAROID;
oid = varchar_oid;
break;
default:
oid = InvalidOid;

View file

@ -32,8 +32,8 @@ void IconColumnDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
}
QSize IconColumnDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
QSize IconColumnDelegate::sizeHint(const QStyleOptionViewItem &,
const QModelIndex &) const
{
return QSize(16, 16);
}

View file

@ -81,7 +81,7 @@ Oid RolesTableModel::getType(int column) const
Oid oid;
switch (column) {
case NameCol:
oid = VARCHAROID;
oid = varchar_oid;
break;
case ReplicationCol:
@ -91,15 +91,15 @@ Oid RolesTableModel::getType(int column) const
case CreateRoleCol:
case InheritCol:
case SuperCol:
oid = BOOLOID;
oid = bool_oid;
break;
case ConnlimitCol:
oid = INT4OID;
oid = int4_oid;
break;
case ValidUntilCol:
oid = TIMESTAMPOID;
oid = timestamp_oid;
break;
default:
oid = InvalidOid;

View file

@ -142,7 +142,7 @@ Oid TablesTableModel::getType(int column) const
case OptionsCol:
// case AclCol:
default:
oid = Pgsql::VARCHAROID;
oid = Pgsql::varchar_oid;
}
return oid;
}

View file

@ -54,7 +54,6 @@ SOURCES += main.cpp\
ConnectionList.cpp \
ProcessStdioWidget.cpp \
GlobalIoService.cpp \
CodeBuilderConfiguration.cpp \
ResultTableModelUtil.cpp \
BaseTableModel.cpp \
QueryParamListController.cpp \
@ -74,7 +73,7 @@ SOURCES += main.cpp\
EditorGutter.cpp \
CodeEditor.cpp \
PlgPage.cpp \
PropertyProxyModel.cpp
PropertyProxyModel.cpp
HEADERS += \
QueryResultModel.h \
@ -122,7 +121,7 @@ HEADERS += \
PlgPage.h \
AbstractCommand.h \
PropertyProxyModel.h \
CustomDataRole.h
CustomDataRole.h
FORMS += mainwindow.ui \
ConnectionManagerWindow.ui \