parent
ef959251b1
commit
96b367e877
4 changed files with 32 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "CheckableTestModel.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QSize>
|
||||
#include <QDebug>
|
||||
|
||||
CheckableTestModel::CheckableTestModel(QObject *parent)
|
||||
|
@ -8,12 +9,12 @@ CheckableTestModel::CheckableTestModel(QObject *parent)
|
|||
{
|
||||
}
|
||||
|
||||
int CheckableTestModel::rowCount(const QModelIndex &parent) const
|
||||
int CheckableTestModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return static_cast<int>(m_tests.size());
|
||||
}
|
||||
|
||||
int CheckableTestModel::columnCount(const QModelIndex &parent) const
|
||||
int CheckableTestModel::columnCount(const QModelIndex &) const
|
||||
{
|
||||
int columnCount = 0;
|
||||
|
||||
|
@ -36,15 +37,17 @@ QVariant CheckableTestModel::data(const QModelIndex &index, int role) const
|
|||
{
|
||||
auto &item = getItem(index);
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return item.getText().c_str();
|
||||
}
|
||||
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
return item.getText().c_str();
|
||||
}
|
||||
case Qt::CheckStateRole:
|
||||
{
|
||||
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
|
@ -101,7 +104,7 @@ QVariant CheckableTestModel::headerData(
|
|||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
void CheckableTestModel::write(QJsonObject &json) const
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
#include "PluralModel.h"
|
||||
|
||||
#include <QSize>
|
||||
|
||||
PluralModel::PluralModel(QObject *parent)
|
||||
: CheckableTestModel(parent)
|
||||
{
|
||||
m_tests = { { "",
|
||||
{ "Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/",
|
||||
"Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML" } } };
|
||||
"Korn UML+/-er/", "Nuss UML+/-e/", "Bär /-en/", "Apfel UML" } } };
|
||||
}
|
||||
|
||||
QVariant PluralModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::SizeHintRole)
|
||||
{
|
||||
return QSize(180, 0);
|
||||
}
|
||||
|
||||
return CheckableTestModel::data(index, role);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,4 +8,7 @@ class PluralModel : public CheckableTestModel
|
|||
|
||||
public:
|
||||
PluralModel(QObject *parent);
|
||||
|
||||
QVariant data(
|
||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
};
|
||||
|
|
|
@ -18,4 +18,5 @@ PluralWidget::~PluralWidget()
|
|||
void PluralWidget::setModel(PluralModel *model)
|
||||
{
|
||||
ui->pluralTableView->setModel(model);
|
||||
ui->pluralTableView->resizeColumnsToContents();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue