bool VarUnit::shouldSave(QTreeWidgetItem* p) { TVar* var = getWVar(p); if (var->getValueType() == 6 || var->isReference()) { return false; } return true; }
void VarUnit::buildVarTree(QTreeWidgetItem* p, TVar* var, bool showHidden) { QList<QTreeWidgetItem*> cList; QListIterator<TVar*> it(var->getChildren(true)); while (it.hasNext()) { TVar* child = it.next(); if (showHidden || !isHidden(child)) { QStringList s1; s1 << child->getName(); auto pItem = new QTreeWidgetItem(s1); pItem->setText(0, child->getName()); pItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsTristate | Qt::ItemIsUserCheckable); pItem->setToolTip(0, "Checked variables will be saved and loaded with your profile."); pItem->setCheckState(0, Qt::Unchecked); if (isSaved(child)) { pItem->setCheckState(0, Qt::Checked); } if (!shouldSave(child)) { // 6 is lua_tfunction, parent must be saveable as well if not global pItem->setFlags(pItem->flags() & ~(Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable)); pItem->setForeground(0, QBrush(QColor("grey"))); pItem->setToolTip(0, ""); } pItem->setData(0, Qt::UserRole, child->getValueType()); QIcon icon; switch (child->getValueType()) { case 5: icon.addPixmap(QPixmap(QStringLiteral(":/icons/table.png")), QIcon::Normal, QIcon::Off); break; case 6: icon.addPixmap(QPixmap(QStringLiteral(":/icons/function.png")), QIcon::Normal, QIcon::Off); break; default: icon.addPixmap(QPixmap(QStringLiteral(":/icons/variable.png")), QIcon::Normal, QIcon::Off); break; } pItem->setIcon(0, icon); wVars.insert(pItem, child); cList.append(pItem); if (child->getValueType() == 5) { buildVarTree((QTreeWidgetItem*)pItem, child, showHidden); } } } p->addChildren(cList); }