Deducing the column count of the table model from the header names.
This commit is contained in:
@ -2,18 +2,12 @@
|
|||||||
|
|
||||||
#include "modelitem.h"
|
#include "modelitem.h"
|
||||||
|
|
||||||
enum UserRoles {
|
enum UserRoles { NameRole = Qt::UserRole + 1, DescriptionRole, InfoRole, AmountRole, FactorRole };
|
||||||
NameRole = Qt::UserRole + 1,
|
static const QHash<int, QByteArray> ROLE_NAMES = {{NameRole, "Name"},
|
||||||
DescriptionRole,
|
{DescriptionRole, "Description"},
|
||||||
InfoRole,
|
{InfoRole, "Info"},
|
||||||
AmountRole,
|
{AmountRole, "Amount"},
|
||||||
FactorRole,
|
{FactorRole, "Factor"}};
|
||||||
FactoredAmountRole
|
|
||||||
};
|
|
||||||
static const QHash<int, QByteArray> ROLE_NAMES = {
|
|
||||||
{NameRole, "Name"}, {DescriptionRole, "Description"},
|
|
||||||
{InfoRole, "Info"}, {AmountRole, "Amount"},
|
|
||||||
{FactorRole, "Factor"}, {FactoredAmountRole, "FactoredAmount"}};
|
|
||||||
|
|
||||||
TableModel::TableModel(QObject* parent)
|
TableModel::TableModel(QObject* parent)
|
||||||
: QAbstractTableModel{parent} {
|
: QAbstractTableModel{parent} {
|
||||||
@ -36,10 +30,7 @@ Qt::ItemFlags TableModel::flags(const QModelIndex& index) const {
|
|||||||
|
|
||||||
int TableModel::rowCount(const QModelIndex& parent) const { return m_items.size(); }
|
int TableModel::rowCount(const QModelIndex& parent) const { return m_items.size(); }
|
||||||
|
|
||||||
int TableModel::columnCount(const QModelIndex& parent) const {
|
int TableModel::columnCount(const QModelIndex& parent) const { return ROLE_NAMES.size(); }
|
||||||
// TODO read from amount of header names (when available)
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant TableModel::data(const QModelIndex& index, int role) const {
|
QVariant TableModel::data(const QModelIndex& index, int role) const {
|
||||||
const int row = index.row();
|
const int row = index.row();
|
||||||
|
|||||||
Reference in New Issue
Block a user