Set equal size for all row headers
This commit is contained in:
parent
13a6468757
commit
baf0cb8dbe
5 changed files with 42 additions and 51 deletions
|
@ -5,13 +5,13 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
CheckableTestModel::CheckableTestModel(QObject *parent)
|
CheckableTestModel::CheckableTestModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int CheckableTestModel::rowCount(const QModelIndex &) 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 &) const
|
int CheckableTestModel::columnCount(const QModelIndex &) const
|
||||||
|
@ -20,7 +20,7 @@ int CheckableTestModel::columnCount(const QModelIndex &) const
|
||||||
|
|
||||||
for (const auto &test : m_tests)
|
for (const auto &test : m_tests)
|
||||||
{
|
{
|
||||||
columnCount = std::max(columnCount, static_cast<int>(test.size()));
|
columnCount = std::max(columnCount, static_cast<int>(test.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return columnCount;
|
return columnCount;
|
||||||
|
@ -37,17 +37,17 @@ QVariant CheckableTestModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
auto &item = getItem(index);
|
auto &item = getItem(index);
|
||||||
|
|
||||||
switch (role)
|
switch (role)
|
||||||
{
|
{
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
{
|
{
|
||||||
return item.getText().c_str();
|
return item.getText().c_str();
|
||||||
}
|
}
|
||||||
case Qt::CheckStateRole:
|
case 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)
|
||||||
{
|
{
|
||||||
|
@ -67,8 +67,7 @@ Qt::ItemFlags CheckableTestModel::flags(const QModelIndex &index) const
|
||||||
return Qt::NoItemFlags;
|
return Qt::NoItemFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckableTestModel::setData(
|
bool CheckableTestModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
const QModelIndex &index, const QVariant &value, int role)
|
|
||||||
{
|
{
|
||||||
if (!isValidIndex(index))
|
if (!isValidIndex(index))
|
||||||
{
|
{
|
||||||
|
@ -93,18 +92,33 @@ bool CheckableTestModel::setData(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CheckableTestModel::headerData(
|
QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
{
|
||||||
if (role == Qt::DisplayRole && orientation == Qt::Vertical)
|
switch (orientation)
|
||||||
{
|
{
|
||||||
if (section < m_tests.size())
|
case Qt::Vertical:
|
||||||
{
|
{
|
||||||
return m_tests.at(section).name();
|
switch (role)
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
{
|
||||||
|
if (section < m_tests.size())
|
||||||
|
{
|
||||||
|
return m_tests.at(section).name();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case Qt::SizeHintRole:
|
||||||
|
{
|
||||||
|
return QSize(200, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QAbstractTableModel::headerData(section, orientation, role);
|
return QAbstractTableModel::headerData(section, orientation, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckableTestModel::write(QJsonObject &json) const
|
void CheckableTestModel::write(QJsonObject &json) const
|
||||||
|
@ -151,8 +165,7 @@ CheckableItems &CheckableTestModel::getItems(const QModelIndex &index)
|
||||||
throw std::runtime_error("invalid index");
|
throw std::runtime_error("invalid index");
|
||||||
}
|
}
|
||||||
|
|
||||||
const CheckableItems &CheckableTestModel::getItems(
|
const CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) const
|
||||||
const QModelIndex &index) const
|
|
||||||
{
|
{
|
||||||
if (index.row() < m_tests.size())
|
if (index.row() < m_tests.size())
|
||||||
{
|
{
|
||||||
|
@ -186,7 +199,7 @@ const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const
|
||||||
|
|
||||||
unsigned int CheckableTestModel::getPoints() const
|
unsigned int CheckableTestModel::getPoints() const
|
||||||
{
|
{
|
||||||
unsigned int points = 0;
|
unsigned int points = 0;
|
||||||
|
|
||||||
for (const auto &test : m_tests)
|
for (const auto &test : m_tests)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,21 +5,11 @@
|
||||||
PluralModel::PluralModel(QObject *parent)
|
PluralModel::PluralModel(QObject *parent)
|
||||||
: CheckableTestModel(parent)
|
: CheckableTestModel(parent)
|
||||||
{
|
{
|
||||||
m_tests = {{"",
|
m_tests = {{"Plural",
|
||||||
{"Fisch /-e/", "Banane /-n/", "Bonbon /-s/", "Ei /-er/", "Eimer /-ø/",
|
{"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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluralModel::read(const ESGRAF48::PluralModel &model)
|
void PluralModel::read(const ESGRAF48::PluralModel &model)
|
||||||
{
|
{
|
||||||
auto &testItems = m_tests.at(0).items();
|
auto &testItems = m_tests.at(0).items();
|
||||||
|
|
|
@ -10,9 +10,6 @@ class PluralModel : public CheckableTestModel
|
||||||
public:
|
public:
|
||||||
PluralModel(QObject *parent);
|
PluralModel(QObject *parent);
|
||||||
|
|
||||||
QVariant data(
|
|
||||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
|
|
||||||
void read(const ESGRAF48::PluralModel &model);
|
void read(const ESGRAF48::PluralModel &model);
|
||||||
void write(ESGRAF48::PluralModel &model) const;
|
void write(ESGRAF48::PluralModel &model) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,8 @@ PluralWidget::PluralWidget(QWidget *parent)
|
||||||
, ui(new Ui::PluralWidget)
|
, ui(new Ui::PluralWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->pluralTableView->horizontalHeader()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
PluralWidget::~PluralWidget()
|
PluralWidget::~PluralWidget()
|
||||||
|
@ -18,5 +20,4 @@ PluralWidget::~PluralWidget()
|
||||||
void PluralWidget::setModel(PluralModel *model)
|
void PluralWidget::setModel(PluralModel *model)
|
||||||
{
|
{
|
||||||
ui->pluralTableView->setModel(model);
|
ui->pluralTableView->setModel(model);
|
||||||
ui->pluralTableView->resizeColumnsToContents();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,17 +15,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="pluralTableView">
|
<widget class="QTableView" name="pluralTableView"/>
|
||||||
<attribute name="horizontalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
|
||||||
<number>120</number>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Reference in a new issue