Hi, I have a group of QActions defined in c++ that I want to be able to arrange and access in qml.
I thought of writing two components like this and am wondering if it is possible: KPIM.ActionTreeFactory { id :myTree actionTree : [ "edit", [ "cut", "copy", "move" ] "view" [ "month", "week", "day" ] "message" [ "sign", [ "Use GPG", "Use SMime" ] "encrypt" [ "Use GPG", "Use SMime" ] ] ] } KPIM.ActionMenuContainer { x : 100 y : 100 width : 200 height : 200 numActions : 2 model : myTree.model } As you can see, the ActionTreeFactory defines a list of lists. I am hoping I can implement it something like this: class ActionTreeFactory { Q_PROPERTY(QObject model READ model NOTIFY modelChanged ) Q_PROPERTY(QVariant actionTree READ actionTree WRITE setActionTree ) public: void populateModel(const QVariant &actionTree, const QModelIndex &parent) { QVariantList contents = actionTree.toList(); foreach (const QVariant &content, contents) { if (content.type() == QVariant::String) { QString actionName = content.toString(); qDebug() << "GOT ACTION" << actionName; m_model->appendAction(parent, actionName); } if (content.type() == QVariant::List) { qDebug() << "GOT LIST"; Q_ASSERT(m_model->hasChildren(parent)); populateModel(content, m_model->index(m_model->rowCount(parent) - 1, 0, parent)); } } } void setActionTree(const QVariant &actionTree) { m_model = new ActionTreeModel(this); populateModel(actionTree, QModelIndex()); } QObject* model() const { return qobject_cast<QObject*>(m_model); } private: QAbstractItemModel *m_model; }; That is, I'm hoping I can get the action tree somehow as a list of lists. In my example I assumed I could get it as a QVariant, but if it's QScriptValue instead I think that would work too. So is some implementation like that possible? Turning the tree of action names into a accessible tree of actions is a separate problem, but I think it's possible. If the above is not possible though I'll need to come up with another solution. I can't find much docs on how to implement Components in c++. Does anyone have a better idea for a scalable solution to defining groups of actions in QML? http://doc.trolltech.com/main-snapshot/qdeclarativecomponent.html I think maybe this would be useful? http://doc.trolltech.com/main-snapshot/qdeclarativeproperty.html All the best, Steve. _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml