aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2019-08-27 09:47:14 +0200
committerEike Ziller <eike.ziller@qt.io>2019-08-27 09:47:14 +0200
commit38feea7e253636396fa629fe25a17819fccaa4ab (patch)
tree45589f004d155007483e12ee2b055145886cd76c /src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp
parent835477b52fd03608d389d00c91dcee6c7f378d63 (diff)
parent309e345818063507ed5bcd8151d670ebd43b6b9c (diff)
Merge remote-tracking branch 'origin/4.10'
Diffstat (limited to 'src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp')
-rw-r--r--src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp b/src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp
index 871c799247..c70dcd6eda 100644
--- a/src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp
+++ b/src/plugins/qmldesigner/components/curveeditor/detail/treemodel.cpp
@@ -26,6 +26,7 @@
#include "treemodel.h"
#include "detail/graphicsview.h"
#include "treeitem.h"
+#include "treeview.h"
#include <QIcon>
@@ -125,6 +126,11 @@ int TreeModel::columnCount(const QModelIndex &parent) const
return m_root->columnCount();
}
+void TreeModel::setTreeView(TreeView *view)
+{
+ m_tree = view;
+}
+
void TreeModel::setGraphicsView(GraphicsView *view)
{
m_view = view;
@@ -135,6 +141,52 @@ GraphicsView *TreeModel::graphicsView() const
return m_view;
}
+std::vector<TreeItem::Path> TreeModel::selection() const
+{
+ std::vector<TreeItem::Path> out;
+ for (auto &&index : m_tree->selectionModel()->selectedIndexes()) {
+ if (index.column() == 0) {
+ TreeItem *item = static_cast<TreeItem *>(index.internalPointer());
+ out.push_back(item->path());
+ }
+ }
+ return out;
+}
+
+QModelIndex TreeModel::findIdx(const QString &name, const QModelIndex &parent) const
+{
+ for (int i = 0; i < rowCount(parent); ++i) {
+ QModelIndex idx = index(i, 0, parent);
+ if (idx.isValid()) {
+ TreeItem *item = static_cast<TreeItem *>(idx.internalPointer());
+ if (item->name() == name)
+ return idx;
+ }
+ }
+ return QModelIndex();
+}
+
+QModelIndex TreeModel::indexOf(const TreeItem::Path &path) const
+{
+ QModelIndex parent;
+ for (size_t i = 0; i < path.size(); ++i) {
+ QModelIndex idx = findIdx(path[i], parent);
+ if (idx.isValid())
+ parent = idx;
+ }
+
+ return parent;
+}
+
+void TreeModel::select(const std::vector<TreeItem::Path> &selection)
+{
+ for (auto &&sel : selection) {
+ QModelIndex idx = indexOf(sel);
+ if (idx.isValid())
+ m_tree->selectionModel()->select(idx, QItemSelectionModel::Select);
+ }
+}
+
void TreeModel::initialize()
{
if (m_root)