2017-02-04 11:55:49 +01:00
|
|
|
|
#include "ParamListModel.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
ParamListModel::ParamListModel(QObject *parent)
|
|
|
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant ParamListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
|
|
{
|
|
|
|
|
|
QVariant result;
|
|
|
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
2017-02-19 11:12:43 +01:00
|
|
|
|
switch (section) {
|
|
|
|
|
|
case ColValue:
|
2017-02-01 18:01:02 +01:00
|
|
|
|
result = tr("Value");
|
2017-02-19 11:12:43 +01:00
|
|
|
|
break;
|
|
|
|
|
|
case ColType:
|
2017-02-01 18:01:02 +01:00
|
|
|
|
result = tr("Type");
|
2017-02-19 11:12:43 +01:00
|
|
|
|
break;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (orientation == Qt::Vertical) {
|
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
|
result = tr("$%1").arg(section + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//bool ParamListModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (value != headerData(section, orientation, role)) {
|
|
|
|
|
|
// // FIXME: Implement me!
|
|
|
|
|
|
// emit headerDataChanged(orientation, section, section);
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
int ParamListModel::rowCount(const QModelIndex &) const
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2017-02-19 11:12:43 +01:00
|
|
|
|
return m_paramList.size();
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
int ParamListModel::columnCount(const QModelIndex &) const
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2017-02-19 11:12:43 +01:00
|
|
|
|
return ColumnCount;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant ParamListModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
|
{
|
|
|
|
|
|
QVariant result;
|
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
|
|
int row = index.row();
|
|
|
|
|
|
int col = index.column();
|
2018-01-09 20:39:43 +01:00
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
2017-02-19 11:12:43 +01:00
|
|
|
|
const auto& record = m_paramList[row];
|
2017-02-01 18:01:02 +01:00
|
|
|
|
switch (col) {
|
2017-02-19 11:12:43 +01:00
|
|
|
|
case ColValue: // value column
|
|
|
|
|
|
result = record.value; // tr("val, %1").arg(row);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
break;
|
2017-02-19 11:12:43 +01:00
|
|
|
|
case ColType: // type column
|
|
|
|
|
|
result = record.type; // tr("type, %1").arg(row);
|
2017-02-01 18:01:02 +01:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ParamListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (data(index, role) != value) {
|
2017-02-19 11:12:43 +01:00
|
|
|
|
if (role == Qt::EditRole) {
|
|
|
|
|
|
int row = index.row();
|
|
|
|
|
|
int col = index.column();
|
|
|
|
|
|
auto& record = m_paramList[row];
|
|
|
|
|
|
switch (col) {
|
|
|
|
|
|
case ColValue:
|
|
|
|
|
|
record.value = value.toString();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ColType:
|
|
|
|
|
|
record.type = value.toString();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2022-05-24 18:56:39 +02:00
|
|
|
|
Q_EMIT dataChanged(index, index, QVector<int>() << role);
|
2017-02-19 11:12:43 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags ParamListModel::flags(const QModelIndex &index) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
|
return Qt::NoItemFlags;
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
bool ParamListModel::insertRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
beginInsertRows(parent, row, row + count - 1);
|
|
|
|
|
|
// FIXME: Implement me!
|
|
|
|
|
|
auto iter = m_paramList.begin() + row;
|
|
|
|
|
|
m_paramList.insert(iter, count, Param());
|
|
|
|
|
|
endInsertRows();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
//bool ParamListModel::insertColumns(int column, int count, const QModelIndex &parent)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// beginInsertColumns(parent, column, column + count - 1);
|
|
|
|
|
|
// // FIXME: Implement me!
|
|
|
|
|
|
// endInsertColumns();
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
bool ParamListModel::removeRows(int row, int count, const QModelIndex &parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
beginRemoveRows(parent, row, row + count - 1);
|
|
|
|
|
|
auto iter = m_paramList.begin() + row;
|
|
|
|
|
|
m_paramList.erase(iter, iter + count);
|
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
|
|
//bool ParamListModel::removeColumns(int column, int count, const QModelIndex &parent)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// beginRemoveColumns(parent, column, column + count - 1);
|
|
|
|
|
|
// // FIXME: Implement me!
|
|
|
|
|
|
// endRemoveColumns();
|
|
|
|
|
|
//}
|
2017-12-09 15:46:33 +01:00
|
|
|
|
|
|
|
|
|
|
const t_ParamList& ParamListModel::GetParams() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_paramList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ParamListModel::SetParams(t_ParamList params)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_paramList = std::move(params);
|
|
|
|
|
|
}
|