//----------------------------------------------------------------------------------------Qt::ItemFlags PluginModel::flags(const QModelIndex &index) const{ if (!index.isValid()) return Qt::NoItemFlags; Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsUserCheckable; return flags;}//----------------------------------------------------------------------------------------QVariant PluginModel::data(const QModelIndex &index, int role) const{ if (!index.isValid() || index.model() != this) return QVariant(); const PluginNode *pluginNode = node(index); switch (role) { case Qt::EditRole: case Qt::DisplayRole: switch (index.column()) { case 0: return pluginNode->title(); } break; case Qt::CheckStateRole: if(index.column()==1){ return pluginNode->checked(); } break; } return QVariant();}//----------------------------------------------------------------------------------------bool PluginModel::setData(const QModelIndex &index, const QVariant &value, int role){ if (!index.isValid() || (flags(index) & Qt::ItemIsEditable) == 0) return false; PluginNode *pluginNode = node(index); switch (role) { case Qt::CheckStateRole: if (index.column() == 1) { pluginNode->setChecked(!pluginNode->checked()); break; } } return true;}//----------------------------------------------------------------------------------------
if(index.column()==1){ return item->checked(); }
if(index.column()==1){ return item->checked() ? 2 : 0; }