Add initial project structure with essential files including .gitignore, application resources, and various model and view components for the application. Implemented asynchronous parsing support and database structure checks.
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
#include "paramtable.h"
|
||||
#include <QDebug>
|
||||
|
||||
ParamTable::ParamTable(QObject *parent)
|
||||
: QAbstractTableModel{parent}
|
||||
{}
|
||||
|
||||
int ParamTable::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
int ParamTable::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return 2; // Название и значение
|
||||
}
|
||||
|
||||
QVariant ParamTable::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_data.size())
|
||||
return QVariant();
|
||||
|
||||
ProjectParamModel *param = m_data.at(index.row());
|
||||
if (!param)
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
switch (index.column()) {
|
||||
case 0: // Название параметра
|
||||
return param->name();
|
||||
case 1: // Значение параметра
|
||||
return param->value();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ParamTable::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return tr("Название");
|
||||
case 1:
|
||||
return tr("Значение");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool ParamTable::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_data.size() || role != Qt::EditRole)
|
||||
return false;
|
||||
|
||||
ProjectParamModel *param = m_data.at(index.row());
|
||||
if (!param)
|
||||
return false;
|
||||
|
||||
bool changed = false;
|
||||
switch (index.column()) {
|
||||
case 0: // Название параметра
|
||||
if (param->name() != value.toString()) {
|
||||
param->setName(value.toString());
|
||||
changed = true;
|
||||
}
|
||||
break;
|
||||
case 1: // Значение параметра
|
||||
if (param->value() != value.toString()) {
|
||||
param->setValue(value.toString());
|
||||
changed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags ParamTable::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
void ParamTable::addParam(ProjectParamModel *param)
|
||||
{
|
||||
if (!param)
|
||||
return;
|
||||
|
||||
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
|
||||
m_data.append(param);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ParamTable::removeParam(int row)
|
||||
{
|
||||
if (row < 0 || row >= m_data.size())
|
||||
return;
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
m_data.removeAt(row);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void ParamTable::clear()
|
||||
{
|
||||
if (m_data.isEmpty())
|
||||
return;
|
||||
|
||||
beginResetModel();
|
||||
m_data.clear();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
ProjectParamModel* ParamTable::getParam(int row) const
|
||||
{
|
||||
if (row < 0 || row >= m_data.size())
|
||||
return nullptr;
|
||||
return m_data.at(row);
|
||||
}
|
||||
|
||||
QList<ProjectParamModel*> ParamTable::getData() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void ParamTable::setData(const QList<ProjectParamModel*> &data)
|
||||
{
|
||||
beginResetModel();
|
||||
m_data = data;
|
||||
endResetModel();
|
||||
}
|
||||
Reference in New Issue
Block a user