Can use the parameter list in the query window now.

Still requires extensive testing for all possible types.
This commit is contained in:
eelke 2017-02-19 11:12:43 +01:00
parent aefc9eb7ba
commit 3af26d915e
14 changed files with 461 additions and 242 deletions

View file

@ -11,12 +11,13 @@ QVariant ParamListModel::headerData(int section, Qt::Orientation orientation, in
QVariant result;
if (orientation == Qt::Horizontal) {
if (role == Qt::DisplayRole) {
if (section == 0) {
// result = tr("$n");
switch (section) {
case ColValue:
result = tr("Value");
}
else if (section == 1) {
break;
case ColType:
result = tr("Type");
break;
}
}
}
@ -39,20 +40,14 @@ QVariant ParamListModel::headerData(int section, Qt::Orientation orientation, in
//}
int ParamListModel::rowCount(const QModelIndex &parent) const
int ParamListModel::rowCount(const QModelIndex &) const
{
//if (parent.isValid())
return 2;
// FIXME: Implement me!
return m_paramList.size();
}
int ParamListModel::columnCount(const QModelIndex &parent) const
int ParamListModel::columnCount(const QModelIndex &) const
{
//if (parent.isValid())
return 2;
// FIXME: Implement me!
return ColumnCount;
}
QVariant ParamListModel::data(const QModelIndex &index, int role) const
@ -62,28 +57,40 @@ QVariant ParamListModel::data(const QModelIndex &index, int role) const
int row = index.row();
int col = index.column();
if (role == Qt::DisplayRole) {
const auto& record = m_paramList[row];
switch (col) {
case 0: // value column
result = tr("val, %1").arg(row);
case ColValue: // value column
result = record.value; // tr("val, %1").arg(row);
break;
case 1: // type column
result = tr("type, %1").arg(row);
case ColType: // type column
result = record.type; // tr("type, %1").arg(row);
break;
}
}
}
// FIXME: Implement me!
return result;
}
bool ParamListModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (data(index, role) != value) {
// // FIXME: Implement me!
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;
}
emit dataChanged(index, index, QVector<int>() << role);
return true;
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
}
return false;
}
@ -93,16 +100,18 @@ Qt::ItemFlags ParamListModel::flags(const QModelIndex &index) const
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEnabled | Qt::ItemIsEditable; // FIXME: Implement me!
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
}
//bool ParamListModel::insertRows(int row, int count, const QModelIndex &parent)
//{
// beginInsertRows(parent, row, row + count - 1);
// // FIXME: Implement me!
// endInsertRows();
// return false;
//}
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;
}
//bool ParamListModel::insertColumns(int column, int count, const QModelIndex &parent)
//{
@ -111,13 +120,14 @@ Qt::ItemFlags ParamListModel::flags(const QModelIndex &index) const
// endInsertColumns();
//}
//bool ParamListModel::removeRows(int row, int count, const QModelIndex &parent)
//{
// beginRemoveRows(parent, row, row + count - 1);
// // FIXME: Implement me!
// endRemoveRows();
// return false;
//}
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;
}
//bool ParamListModel::removeColumns(int column, int count, const QModelIndex &parent)
//{