Re-formatted all source files
This commit is contained in:
parent
5c6ed8191b
commit
d0f64ef440
77 changed files with 2443 additions and 2332 deletions
|
@ -4,191 +4,191 @@
|
|||
#include <QSize>
|
||||
#include <QDebug>
|
||||
|
||||
CheckableTestModel::CheckableTestModel(QObject *parent)
|
||||
CheckableTestModel::CheckableTestModel(QObject* 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
|
||||
{
|
||||
int columnCount = 0;
|
||||
int columnCount = 0;
|
||||
|
||||
for (const auto &test : m_tests)
|
||||
{
|
||||
columnCount = std::max(columnCount, static_cast<int>(test.size()));
|
||||
}
|
||||
for (const auto& test : m_tests)
|
||||
{
|
||||
columnCount = std::max(columnCount, static_cast<int>(test.size()));
|
||||
}
|
||||
|
||||
return columnCount;
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
QVariant CheckableTestModel::data(const QModelIndex &index, int role) const
|
||||
QVariant CheckableTestModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!isValidIndex(index))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if (!isValidIndex(index))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto &item = getItem(index);
|
||||
try
|
||||
{
|
||||
auto& item = getItem(index);
|
||||
|
||||
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)
|
||||
{
|
||||
qDebug() << "CheckableTestModel::data" << index << e.what();
|
||||
}
|
||||
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)
|
||||
{
|
||||
qDebug() << "CheckableTestModel::data" << index << e.what();
|
||||
}
|
||||
|
||||
return {};
|
||||
return {};
|
||||
}
|
||||
|
||||
Qt::ItemFlags CheckableTestModel::flags(const QModelIndex &index) const
|
||||
Qt::ItemFlags CheckableTestModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
if (isValidIndex(index))
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
if (isValidIndex(index))
|
||||
{
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
return Qt::NoItemFlags;
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
||||
bool CheckableTestModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
bool CheckableTestModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if (!isValidIndex(index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!isValidIndex(index))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
auto &item = getItem(index);
|
||||
item.setState(value.toBool());
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
qDebug() << "CheckableTestModel::setData" << index << e.what();
|
||||
}
|
||||
try
|
||||
{
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
auto& item = getItem(index);
|
||||
item.setState(value.toBool());
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error& e)
|
||||
{
|
||||
qDebug() << "CheckableTestModel::setData" << index << e.what();
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant CheckableTestModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
switch (orientation)
|
||||
{
|
||||
case Qt::Vertical:
|
||||
{
|
||||
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;
|
||||
}
|
||||
switch (orientation)
|
||||
{
|
||||
case Qt::Vertical:
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
bool CheckableTestModel::isValidIndex(const QModelIndex &index) const
|
||||
bool CheckableTestModel::isValidIndex(const QModelIndex& index) const
|
||||
{
|
||||
if (index.row() < m_tests.size())
|
||||
{
|
||||
return index.column() < m_tests.at(index.row()).size();
|
||||
}
|
||||
if (index.row() < m_tests.size())
|
||||
{
|
||||
return index.column() < m_tests.at(index.row()).size();
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckableItems &CheckableTestModel::getItems(const QModelIndex &index)
|
||||
CheckableItems& CheckableTestModel::getItems(const QModelIndex& index)
|
||||
{
|
||||
if (index.row() < m_tests.size())
|
||||
{
|
||||
return m_tests.at(index.row()).items();
|
||||
}
|
||||
if (index.row() < m_tests.size())
|
||||
{
|
||||
return m_tests.at(index.row()).items();
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
const CheckableItems &CheckableTestModel::getItems(const QModelIndex &index) const
|
||||
const CheckableItems& CheckableTestModel::getItems(const QModelIndex& index) const
|
||||
{
|
||||
if (index.row() < m_tests.size())
|
||||
{
|
||||
return m_tests.at(index.row()).items();
|
||||
}
|
||||
if (index.row() < m_tests.size())
|
||||
{
|
||||
return m_tests.at(index.row()).items();
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
CheckableItem &CheckableTestModel::getItem(const QModelIndex &index)
|
||||
CheckableItem& CheckableTestModel::getItem(const QModelIndex& index)
|
||||
{
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
auto& items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
const CheckableItem &CheckableTestModel::getItem(const QModelIndex &index) const
|
||||
const CheckableItem& CheckableTestModel::getItem(const QModelIndex& index) const
|
||||
{
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
auto& items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
unsigned int CheckableTestModel::getPoints() const
|
||||
{
|
||||
unsigned int points = 0;
|
||||
unsigned int points = 0;
|
||||
|
||||
for (const auto &test : m_tests)
|
||||
{
|
||||
for (const auto &item : test.items())
|
||||
{
|
||||
points += item.points();
|
||||
}
|
||||
}
|
||||
for (const auto& test : m_tests)
|
||||
{
|
||||
for (const auto& item : test.items())
|
||||
{
|
||||
points += item.points();
|
||||
}
|
||||
}
|
||||
|
||||
return points;
|
||||
return points;
|
||||
}
|
||||
|
||||
QString CheckableTestModel::getTitle() const
|
||||
{
|
||||
return m_title;
|
||||
return m_title;
|
||||
}
|
||||
|
|
|
@ -5,37 +5,36 @@
|
|||
|
||||
class CheckableTestModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
QString m_title;
|
||||
CheckableTests m_tests;
|
||||
QString m_title;
|
||||
CheckableTests m_tests;
|
||||
|
||||
public:
|
||||
CheckableTestModel(QObject *parent);
|
||||
CheckableTestModel(QObject* parent);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
unsigned int getPoints() const;
|
||||
unsigned int getPoints() const;
|
||||
|
||||
QString getTitle() const;
|
||||
QString getTitle() const;
|
||||
|
||||
protected:
|
||||
virtual bool isValidIndex(const QModelIndex &index) const;
|
||||
virtual bool isValidIndex(const QModelIndex& index) const;
|
||||
|
||||
private:
|
||||
CheckableItems &getItems(const QModelIndex &index);
|
||||
const CheckableItems &getItems(const QModelIndex &index) const;
|
||||
CheckableItems& getItems(const QModelIndex& index);
|
||||
const CheckableItems& getItems(const QModelIndex& index) const;
|
||||
|
||||
CheckableItem &getItem(const QModelIndex &index);
|
||||
const CheckableItem &getItem(const QModelIndex &index) const;
|
||||
CheckableItem& getItem(const QModelIndex& index);
|
||||
const CheckableItem& getItem(const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue