7#include <QtDesigner/abstractwidgetdatabase.h>
8#include <QtDesigner/abstractpromotioninterface.h>
9#include <QtDesigner/abstractformeditor.h>
11#include <QtGui/qstandarditemmodel.h>
12#include <QtCore/qcoreapplication.h>
17 using StandardItemList = QList<QStandardItem *>;
26 rc.push_back(
new QStandardItem());
33 StandardItemList rc = modelRow();
37 rc[i]->setFlags(Qt::ItemIsEnabled);
47 qdesigner_internal::PromotionModel::ModelData data;
48 data.baseItem = baseItem;
49 data.promotedItem = dbItem;
50 data.referenced = referenced;
52 const QVariant userData = QVariant::fromValue(data);
54 StandardItemList rc = modelRow();
57 rc[ClassNameColumn]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
60 const qdesigner_internal::IncludeSpecification spec = qdesigner_internal::includeSpecification(dbItem->includeFile());
62 rc[IncludeFileColumn]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable);
65 rc[IncludeTypeColumn]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable|Qt::ItemIsUserCheckable);
67 rc[IncludeTypeColumn]->setCheckState(spec.second == qdesigner_internal::IncludeGlobal ? Qt::Checked : Qt::Unchecked);
69 rc[ReferencedColumn]->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
73 static const QString notUsed = QCoreApplication::translate(
"PromotionModel",
"Not used");
85 connect(
this, &QStandardItemModel::itemChanged,
this, &PromotionModel::slotItemChanged);
90 QStringList horizontalLabels(tr(
"Name"));
91 horizontalLabels += tr(
"Header file");
92 horizontalLabels += tr(
"Global include");
93 horizontalLabels += tr(
"Usage");
94 setHorizontalHeaderLabels (horizontalLabels);
98 using PromotedClasses = QDesignerPromotionInterface::PromotedClasses;
105 const PromotedClasses promotedClasses = m_core->promotion()->promotedClasses();
107 if (promotedClasses.isEmpty())
110 const QSet<QString> usedPromotedClasses = m_core->promotion()->referencedPromotedClassNames();
112 QDesignerWidgetDataBaseItemInterface *baseClass =
nullptr;
113 QStandardItem *baseItem =
nullptr;
115 for (
auto &pi : promotedClasses) {
117 if (baseClass != pi.baseItem) {
118 baseClass = pi.baseItem;
119 const StandardItemList baseRow = baseModelRow(pi.baseItem);
120 baseItem = baseRow.constFirst();
125 baseItem->appendRow(promotedModelRow(pi.baseItem, pi.promotedItem,
126 usedPromotedClasses.contains(pi.promotedItem->name())));
130 void PromotionModel::slotItemChanged(QStandardItem * changedItem) {
132 const ModelData data = modelData(changedItem);
133 Q_ASSERT(data.isValid());
134 QDesignerWidgetDataBaseItemInterface *dbItem = data.promotedItem;
136 switch (changedItem->column()) {
138 emit classNameChanged(dbItem, changedItem->text());
143 const QStandardItem *baseClassItem = changedItem->parent();
144 const QStandardItem *fileItem = baseClassItem->child(changedItem->row(), IncludeFileColumn);
145 const QStandardItem *typeItem = baseClassItem->child(changedItem->row(), IncludeTypeColumn);
146 emit includeFileChanged(dbItem, buildIncludeFile(fileItem->text(), typeItem->checkState() == Qt::Checked ? IncludeGlobal : IncludeLocal));
154 const QVariant userData = item->data();
155 return userData.canConvert<ModelData>() ? userData.value<ModelData>() : ModelData();
160 return index.isValid() ? modelData(itemFromIndex(index)) : ModelData();
164 const StandardItemList matches = findItems (className, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive);
165 return matches.isEmpty() ? QModelIndex() : indexFromItem (matches.constFirst());
Combined button and popup list for selecting options.
StandardItemList baseModelRow(const QDesignerWidgetDataBaseItemInterface *dbItem)
StandardItemList promotedModelRow(QDesignerWidgetDataBaseItemInterface *baseItem, QDesignerWidgetDataBaseItemInterface *dbItem, bool referenced)
StandardItemList modelRow()
Auxiliary methods to store/retrieve settings.