I'm still not sure what the problem is.
Here is my data method. When I use the commented code, the cells don't have checkboxes (but input data doesn't stick). When I use the code as it is below, the data sticks, but one checkbox is in each index.
{
if(index.column() == 0)
//return QVariant(ConstantValues->at(index.row()));
return QVariant(ConstantValues
->at
(index.
row()).
X);
if(index.column() == 1)
//return QVariant(ConstantValues->at(index.row()));
return QVariant(ConstantValues
->at
(index.
row()).
Y);
}
QVariant ConstantsModel::data(const QModelIndex &index, int role) const
{
if(index.column() == 0)
//return QVariant(ConstantValues->at(index.row()));
return QVariant(ConstantValues->at(index.row()).X);
if(index.column() == 1)
//return QVariant(ConstantValues->at(index.row()));
return QVariant(ConstantValues->at(index.row()).Y);
return QVariant();
}
To copy to clipboard, switch view to plain text mode
Here is my setData method (if this helps any):
{
ConstantsModelPoint point = ConstantValues->takeAt(index.row());
if(index.column() == 0)
{
point.X = Value.toString();
ConstantValues->insert(index.row(), point);
emit this->layoutChanged();
return true;
}
if(index.column() == 1)
{
point.Y = Value.toDouble();
ConstantValues->insert(index.row(), point);
emit this->layoutChanged();
return true;
}
return false;
}
bool ConstantsModel::setData(const QModelIndex &index, const QVariant &Value, int role)
{
ConstantsModelPoint point = ConstantValues->takeAt(index.row());
if(index.column() == 0)
{
point.X = Value.toString();
ConstantValues->insert(index.row(), point);
emit this->layoutChanged();
return true;
}
if(index.column() == 1)
{
point.Y = Value.toDouble();
ConstantValues->insert(index.row(), point);
emit this->layoutChanged();
return true;
}
return false;
}
To copy to clipboard, switch view to plain text mode
Finally the data container "ConstantValues" is a QList containing elements from this class:
class ConstantsModelPoint
: public QVariant{
public:
ConstantsModelPoint();
~ConstantsModelPoint();
double Y;
};
class ConstantsModelPoint : public QVariant
{
public:
ConstantsModelPoint();
~ConstantsModelPoint();
QString X;
double Y;
};
To copy to clipboard, switch view to plain text mode
Bookmarks