parent
ef959251b1
commit
96b367e877
@ -1,6 +1,7 @@
|
|||||||
#include "CheckableTestModel.h"
|
#include "CheckableTestModel.h"
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QSize>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
CheckableTestModel::CheckableTestModel(QObject *parent)
|
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());
|
return static_cast<int>(m_tests.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
int CheckableTestModel::columnCount(const QModelIndex &parent) const
|
int CheckableTestModel::columnCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
int columnCount = 0;
|
int columnCount = 0;
|
||||||
|
|
||||||
@ -36,16 +37,18 @@ QVariant CheckableTestModel::data(const QModelIndex &index, int role) const
|
|||||||
{
|
{
|
||||||
auto &item = getItem(index);
|
auto &item = getItem(index);
|
||||||
|
|
||||||
if (role == Qt::DisplayRole)
|
switch (role)
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
{
|
{
|
||||||
return item.getText().c_str();
|
return item.getText().c_str();
|
||||||
}
|
}
|
||||||
|
case Qt::CheckStateRole:
|
||||||
if (role == Qt::CheckStateRole)
|
|
||||||
{
|
{
|
||||||
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
|
return item.isChecked() ? Qt::Checked : Qt::Unchecked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (std::runtime_error &e)
|
catch (std::runtime_error &e)
|
||||||
{
|
{
|
||||||
qDebug() << "CheckableTestModel::data" << index << e.what();
|
qDebug() << "CheckableTestModel::data" << index << e.what();
|
||||||
@ -101,7 +104,7 @@ QVariant CheckableTestModel::headerData(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return QAbstractTableModel::headerData(section, orientation, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckableTestModel::write(QJsonObject &json) const
|
void CheckableTestModel::write(QJsonObject &json) const
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "PluralModel.h"
|
#include "PluralModel.h"
|
||||||
|
|
||||||
|
#include <QSize>
|
||||||
|
|
||||||
PluralModel::PluralModel(QObject *parent)
|
PluralModel::PluralModel(QObject *parent)
|
||||||
: CheckableTestModel(parent)
|
: CheckableTestModel(parent)
|
||||||
{
|
{
|
||||||
@ -8,3 +10,13 @@ PluralModel::PluralModel(QObject *parent)
|
|||||||
"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:
|
public:
|
||||||
PluralModel(QObject *parent);
|
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)
|
void PluralWidget::setModel(PluralModel *model)
|
||||||
{
|
{
|
||||||
ui->pluralTableView->setModel(model);
|
ui->pluralTableView->setModel(model);
|
||||||
|
ui->pluralTableView->resizeColumnsToContents();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user