Introduced new library for pglab code which I want to unit test.
Not everything can go into core because that would result in circular dependencies between core and pgsql.
This commit is contained in:
parent
b8505ce451
commit
ad9ed1b698
10 changed files with 98 additions and 21 deletions
|
|
@ -1,37 +0,0 @@
|
|||
#include "ParamListJson.h"
|
||||
|
||||
Json::Value ParamToJson(const Param ¶m)
|
||||
{
|
||||
Json::Value v;
|
||||
v["type"] = param.type.toUtf8().data();
|
||||
v["value"] = param.value.toUtf8().data();
|
||||
return v;
|
||||
}
|
||||
|
||||
Param ParamFromJson(const Json::Value &json)
|
||||
{
|
||||
Param p;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Json::Value ParamListToJson(const t_ParamList &list)
|
||||
{
|
||||
Json::Value root;
|
||||
for (const auto ¶m : list) {
|
||||
root.append(ParamToJson(param));
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
t_ParamList ParamListFromJson(const Json::Value &json)
|
||||
{
|
||||
t_ParamList result;
|
||||
if (json.isArray()) {
|
||||
result.reserve(json.size());
|
||||
for (auto &e : json) {
|
||||
result.push_back(ParamFromJson(e));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#ifndef PARAMLISTJSON_H
|
||||
#define PARAMLISTJSON_H
|
||||
|
||||
#include "json/json.h"
|
||||
#include "ParamListModel.h"
|
||||
|
||||
Json::Value ParamListToJson(const t_ParamList &list);
|
||||
|
||||
#endif // PARAMLISTJSON_H
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
#include "ParamListModel.h"
|
||||
|
||||
ParamListModel::ParamListModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant ParamListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
// FIXME: Implement me!
|
||||
QVariant result;
|
||||
if (orientation == Qt::Horizontal) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case ColValue:
|
||||
result = tr("Value");
|
||||
break;
|
||||
case ColType:
|
||||
result = tr("Type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (orientation == Qt::Vertical) {
|
||||
if (role == Qt::DisplayRole) {
|
||||
result = tr("$%1").arg(section + 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//bool ParamListModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
//{
|
||||
// if (value != headerData(section, orientation, role)) {
|
||||
// // FIXME: Implement me!
|
||||
// emit headerDataChanged(orientation, section, section);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
|
||||
int ParamListModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_paramList.size();
|
||||
}
|
||||
|
||||
int ParamListModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
return ColumnCount;
|
||||
}
|
||||
|
||||
QVariant ParamListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QVariant result;
|
||||
if (index.isValid()) {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
if (role == Qt::DisplayRole) {
|
||||
const auto& record = m_paramList[row];
|
||||
switch (col) {
|
||||
case ColValue: // value column
|
||||
result = record.value; // tr("val, %1").arg(row);
|
||||
break;
|
||||
case ColType: // type column
|
||||
result = record.type; // tr("type, %1").arg(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ParamListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (data(index, role) != value) {
|
||||
if (role == Qt::EditRole) {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
auto& record = m_paramList[row];
|
||||
switch (col) {
|
||||
case ColValue:
|
||||
record.value = value.toString();
|
||||
break;
|
||||
case ColType:
|
||||
record.type = value.toString();
|
||||
break;
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QVector<int>() << role);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags ParamListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
bool ParamListModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
auto iter = m_paramList.begin() + row;
|
||||
m_paramList.insert(iter, count, Param());
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
//bool ParamListModel::insertColumns(int column, int count, const QModelIndex &parent)
|
||||
//{
|
||||
// beginInsertColumns(parent, column, column + count - 1);
|
||||
// // FIXME: Implement me!
|
||||
// endInsertColumns();
|
||||
//}
|
||||
|
||||
bool ParamListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
auto iter = m_paramList.begin() + row;
|
||||
m_paramList.erase(iter, iter + count);
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
//bool ParamListModel::removeColumns(int column, int count, const QModelIndex &parent)
|
||||
//{
|
||||
// beginRemoveColumns(parent, column, column + count - 1);
|
||||
// // FIXME: Implement me!
|
||||
// endRemoveColumns();
|
||||
//}
|
||||
|
||||
const t_ParamList& ParamListModel::GetParams() const
|
||||
{
|
||||
return m_paramList;
|
||||
}
|
||||
|
||||
void ParamListModel::SetParams(t_ParamList params)
|
||||
{
|
||||
m_paramList = std::move(params);
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
#ifndef PARAMLISTMODEL_H
|
||||
#define PARAMLISTMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <vector>
|
||||
#include "Pgsql_declare.h"
|
||||
|
||||
class Param {
|
||||
public:
|
||||
QString value; ///< the value of the parameter (currently this is passed directly)
|
||||
QString type; ///< the type of the parameter
|
||||
|
||||
Param() = default;
|
||||
Param(const QString &v, const QString t)
|
||||
: value(v), type(t)
|
||||
{}
|
||||
};
|
||||
using t_ParamList = std::vector<Param>;
|
||||
|
||||
|
||||
class ParamListModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
enum e_Column {
|
||||
ColValue = 0,
|
||||
ColType,
|
||||
ColumnCount // Keep last not a column just the count
|
||||
};
|
||||
|
||||
explicit ParamListModel(QObject *parent = 0);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
// bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
// Basic functionality:
|
||||
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;
|
||||
|
||||
// Editable:
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
// auto begin() const { return m_paramList.begin(); }
|
||||
// auto end() const { return m_paramList.end(); }
|
||||
const t_ParamList& GetParams() const;
|
||||
void SetParams(t_ParamList params);
|
||||
private:
|
||||
|
||||
t_ParamList m_paramList;
|
||||
};
|
||||
|
||||
#endif // PARAMLISTMODEL_H
|
||||
|
|
@ -36,9 +36,7 @@ SOURCES += my_boost_assert_handler.cpp \
|
|||
BackupFormatModel.cpp \
|
||||
QueuedBackgroundTask.cpp \
|
||||
ExplainTreeModelItem.cpp \
|
||||
jsoncpp.cpp \
|
||||
ParamListJson.cpp \
|
||||
ParamListModel.cpp
|
||||
jsoncpp.cpp
|
||||
|
||||
HEADERS += PasswordManager.h \
|
||||
SqlLexer.h \
|
||||
|
|
@ -48,26 +46,9 @@ HEADERS += PasswordManager.h \
|
|||
QueuedBackgroundTask.h \
|
||||
Expected.h \
|
||||
ExplainTreeModelItem.h \
|
||||
ParamListJson.h \
|
||||
ParamListModel.h \
|
||||
json/json.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
INSTALLS += target
|
||||
}
|
||||
|
||||
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../pgsql/release/ -lpgsql
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../pgsql/debug/ -lpgsql
|
||||
else:unix:!macx: LIBS += -L$$OUT_PWD/../pgsql/ -lpgsql
|
||||
|
||||
INCLUDEPATH += $$PWD/../pgsql
|
||||
DEPENDPATH += $$PWD/../pgsql
|
||||
|
||||
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/release/libpgsql.a
|
||||
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/debug/libpgsql.a
|
||||
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/release/pgsql.lib
|
||||
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/debug/pgsql.lib
|
||||
else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../pgsql/libpgsql.a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue