forked from qt-creator/qt-creator
QmlDesigner: Enable name and id for texture ComboBoxes
Change-Id: Iefe9e68bf9c54753c38c6a43f3a6d3217f2293c0 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Shrief Gabr <shrief.gabr@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -119,6 +119,41 @@ QStringList ItemFilterModel::validationItems() const
|
||||
return m_validationItems;
|
||||
}
|
||||
|
||||
QVariant ItemFilterModel::modelItemData(int row) const
|
||||
{
|
||||
QModelIndex idx = index(row, 0, {});
|
||||
if (!idx.isValid())
|
||||
return {};
|
||||
|
||||
QVariantMap mapItem;
|
||||
|
||||
auto insertData = [&](Role role) {
|
||||
mapItem.insert(QString::fromUtf8(roleNames().value(role)), idx.data(role));
|
||||
};
|
||||
|
||||
insertData(IdRole);
|
||||
insertData(IdAndNameRole);
|
||||
insertData(NameRole);
|
||||
insertData(EnabledRole);
|
||||
|
||||
return mapItem;
|
||||
}
|
||||
|
||||
int ItemFilterModel::indexFromId(const QString &id) const
|
||||
{
|
||||
AbstractView *view = m_modelNode.view();
|
||||
if (!view || !view->model())
|
||||
return -1;
|
||||
|
||||
int idx = -1;
|
||||
for (const auto &internalId : std::as_const(m_modelInternalIds)) {
|
||||
++idx;
|
||||
if (id == view->modelNodeForInternalId(internalId).id())
|
||||
return idx;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ItemFilterModel::registerDeclarativeType()
|
||||
{
|
||||
qmlRegisterType<ItemFilterModel>("HelperWidgets", 2, 0, "ItemFilterModel");
|
||||
|
||||
@@ -30,7 +30,9 @@ class ItemFilterModel : public QAbstractListModel
|
||||
Q_PROPERTY(QStringList validationItems READ validationItems NOTIFY validationItemsChanged)
|
||||
|
||||
public:
|
||||
enum { IdRole = Qt::DisplayRole, NameRole = Qt::UserRole, IdAndNameRole, EnabledRole };
|
||||
enum Role { IdRole = Qt::DisplayRole, NameRole = Qt::UserRole, IdAndNameRole, EnabledRole };
|
||||
|
||||
Q_ENUM(Role)
|
||||
|
||||
explicit ItemFilterModel(QObject *parent = nullptr);
|
||||
|
||||
@@ -45,6 +47,8 @@ public:
|
||||
QStringList itemModel() const;
|
||||
QStringList validationRoles() const;
|
||||
QStringList validationItems() const;
|
||||
Q_INVOKABLE QVariant modelItemData(int row) const;
|
||||
Q_INVOKABLE int indexFromId(const QString &id) const;
|
||||
|
||||
static void registerDeclarativeType();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user