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