From 4ac87f285b18efeca6976254ee4fb744997c9452 Mon Sep 17 00:00:00 2001 From: eelke Date: Sun, 10 Apr 2022 06:51:25 +0200 Subject: [PATCH] start on view the show single record as list of label + value --- pglab/pglab.pro | 2 + pglab/widgets/SingleRecordModel.cpp | 61 +++++++++++++++++++++++++++++ pglab/widgets/SingleRecordModel.h | 39 ++++++++++++++++++ pglab/widgets/SingleRecordWidget.ui | 24 ++++++++---- 4 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 pglab/widgets/SingleRecordModel.cpp create mode 100644 pglab/widgets/SingleRecordModel.h diff --git a/pglab/pglab.pro b/pglab/pglab.pro index 33ddc9e..ea2da9e 100644 --- a/pglab/pglab.pro +++ b/pglab/pglab.pro @@ -91,6 +91,7 @@ PropertyProxyModel.cpp \ EditTableWidget.cpp \ EditColumnTableModel.cpp \ DatabaseWindow.cpp \ + widgets/SingleRecordModel.cpp \ widgets/SingleRecordWidget.cpp HEADERS += \ @@ -169,6 +170,7 @@ CustomDataRole.h \ DatabaseWindow.h \ NamespaceFilter.h \ util/PgLabTableViewHelper.h \ + widgets/SingleRecordModel.h \ widgets/SingleRecordWidget.h FORMS += \ diff --git a/pglab/widgets/SingleRecordModel.cpp b/pglab/widgets/SingleRecordModel.cpp new file mode 100644 index 0000000..18128e4 --- /dev/null +++ b/pglab/widgets/SingleRecordModel.cpp @@ -0,0 +1,61 @@ +#include "SingleRecordModel.h" +#include "CustomDataRole.h" + +SingleRecordModel::SingleRecordModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +QVariant SingleRecordModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + return {}; +} + +int SingleRecordModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return elems.size(); +} + +int SingleRecordModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + + return ColCount; +} + +QVariant SingleRecordModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + const int row = index.row(); + if (role == Qt::DisplayRole) + { + switch (index.column()) + { + case NameCol: + return elems[row].name; + case ValueCol: + return elems[row].value; + } + } + else if (role == CustomDataTypeRole) + { + switch (index.column()) + { + case NameCol: + return Pgsql::text_oid; + case ValueCol: + return elems[row].oid; + } + } + else if (role == CustomDataMeaningRole) + { + } + + return QVariant(); +} diff --git a/pglab/widgets/SingleRecordModel.h b/pglab/widgets/SingleRecordModel.h new file mode 100644 index 0000000..8107508 --- /dev/null +++ b/pglab/widgets/SingleRecordModel.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include "Pgsql_oids.h" + +class SingleRecordModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + explicit SingleRecordModel(QObject *parent = nullptr); + + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const 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; + +private: + enum Columns { + NameCol, + ValueCol, + + ColCount + }; + + class Elem { + public: + QString name; + QString value; + Oid oid; + }; + using Elems = std::vector; + Elems elems; +}; + diff --git a/pglab/widgets/SingleRecordWidget.ui b/pglab/widgets/SingleRecordWidget.ui index 6194638..d14dee0 100644 --- a/pglab/widgets/SingleRecordWidget.ui +++ b/pglab/widgets/SingleRecordWidget.ui @@ -1,21 +1,31 @@ + - - - SingleRecordWidget - + 0 0 - 400 - 300 + 500 + 679 Form + + + + + - + + + PgLabTableView + QTableView +
PgLabTableView.h
+
+
+