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
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">
|
||||
<author/>
|
||||
<comment/>
|
||||
<exportmacro/>
|
||||
<class>SingleRecordWidget</class>
|
||||
<widget name="SingleRecordWidget" class="QWidget">
|
||||
<widget class="QWidget" name="SingleRecordWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>500</width>
|
||||
<height>679</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="PgLabTableView" name="properties"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<pixmapfunction/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>PgLabTableView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>PgLabTableView.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue