start on view the show single record as list of label + value
This commit is contained in:
parent
c71fdc4af7
commit
4ac87f285b
4 changed files with 119 additions and 7 deletions
|
|
@ -91,6 +91,7 @@ PropertyProxyModel.cpp \
|
||||||
EditTableWidget.cpp \
|
EditTableWidget.cpp \
|
||||||
EditColumnTableModel.cpp \
|
EditColumnTableModel.cpp \
|
||||||
DatabaseWindow.cpp \
|
DatabaseWindow.cpp \
|
||||||
|
widgets/SingleRecordModel.cpp \
|
||||||
widgets/SingleRecordWidget.cpp
|
widgets/SingleRecordWidget.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
|
@ -169,6 +170,7 @@ CustomDataRole.h \
|
||||||
DatabaseWindow.h \
|
DatabaseWindow.h \
|
||||||
NamespaceFilter.h \
|
NamespaceFilter.h \
|
||||||
util/PgLabTableViewHelper.h \
|
util/PgLabTableViewHelper.h \
|
||||||
|
widgets/SingleRecordModel.h \
|
||||||
widgets/SingleRecordWidget.h
|
widgets/SingleRecordWidget.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
|
|
||||||
61
pglab/widgets/SingleRecordModel.cpp
Normal file
61
pglab/widgets/SingleRecordModel.cpp
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
39
pglab/widgets/SingleRecordModel.h
Normal file
39
pglab/widgets/SingleRecordModel.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractTableModel>
|
||||||
|
#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<Elem>;
|
||||||
|
Elems elems;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -1,21 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<author/>
|
|
||||||
<comment/>
|
|
||||||
<exportmacro/>
|
|
||||||
<class>SingleRecordWidget</class>
|
<class>SingleRecordWidget</class>
|
||||||
<widget name="SingleRecordWidget" class="QWidget">
|
<widget class="QWidget" name="SingleRecordWidget">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>500</width>
|
||||||
<height>300</height>
|
<height>679</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="PgLabTableView" name="properties"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<pixmapfunction/>
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>PgLabTableView</class>
|
||||||
|
<extends>QTableView</extends>
|
||||||
|
<header>PgLabTableView.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue