Skip to content

Commit 4791f54

Browse files
committed
Providing _sortFlag allows the user to choose for themselves whether to use Models loading order or automatic sorting.
1 parent 12a40d5 commit 4791f54

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

include/QtNodes/internal/DataFlowGraphicsScene.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class NODE_EDITOR_PUBLIC DataFlowGraphicsScene
3333
QMenu *
3434
createSceneMenu(QPointF const scenePos) override;
3535

36+
void
37+
sortSceneMenu(bool sort);
3638

3739
public Q_SLOTS:
3840
void
@@ -47,6 +49,8 @@ public Q_SLOTS:
4749

4850
private:
4951
DataFlowGraphModel &_graphModel;
52+
53+
bool _sortFlag;
5054
};
5155

5256
}

include/QtNodes/internal/NodeDelegateModelRegistry.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <functional>
1111
#include <memory>
12-
#include <set>
1312
#include <type_traits>
1413
#include <unordered_map>
1514
#include <utility>
@@ -29,7 +28,7 @@ class NODE_EDITOR_PUBLIC NodeDelegateModelRegistry
2928
using RegistryItemPtr = std::unique_ptr<NodeDelegateModel>;
3029
using RegistryItemCreator = std::function<RegistryItemPtr ()>;
3130
using RegisteredModelCreatorsMap = std::unordered_map<QString, RegistryItemCreator>;
32-
using RegisteredModelsCategoryMap = std::unordered_map<QString, QString>;
31+
using RegisteredModelsCategoryMap = std::vector<std::pair<QString, QString>>;
3332

3433
//using RegisteredTypeConvertersMap = std::map<TypeConverterId, TypeConverter>;
3534

@@ -56,7 +55,7 @@ class NODE_EDITOR_PUBLIC NodeDelegateModelRegistry
5655
if (!_registeredItemCreators.count(name))
5756
{
5857
_registeredItemCreators[name] = std::move(creator);
59-
_registeredModelsCategory[name] = category;
58+
_registeredModelsCategory.push_back(std::pair(name, category));
6059
}
6160
}
6261

src/DataFlowGraphicsScene.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ DataFlowGraphicsScene(DataFlowGraphModel& graphModel,
3636
QObject* parent)
3737
: BasicGraphicsScene(graphModel, parent)
3838
, _graphModel(graphModel)
39+
, _sortFlag(true)
3940
{
4041
connect(&_graphModel, &DataFlowGraphModel::inPortDataWasSet,
4142
[this](NodeId const nodeId, PortType const, PortIndex const)
@@ -120,9 +121,11 @@ createSceneMenu(QPointF const scenePos)
120121
childItem->setText(0, assoc.first);
121122
}
122123

123-
treeView->sortByColumn(0, Qt::AscendingOrder);
124124
treeView->expandAll();
125125

126+
if (_sortFlag)
127+
treeView->sortByColumn(0, Qt::AscendingOrder);
128+
126129
connect(treeView, &QTreeWidget::itemClicked,
127130
[this,
128131
modelMenu,
@@ -148,6 +151,10 @@ createSceneMenu(QPointF const scenePos)
148151
auto modelName = (*it)->text(0);
149152
const bool match = (modelName.contains(text, Qt::CaseInsensitive));
150153
(*it)->setHidden(!match);
154+
// if (match)
155+
// {
156+
// treeView->scrollToItem(*it);
157+
// }
151158

152159
++it;
153160
}
@@ -162,6 +169,13 @@ createSceneMenu(QPointF const scenePos)
162169
return modelMenu;
163170
}
164171

172+
void
173+
DataFlowGraphicsScene::
174+
sortSceneMenu(bool sort)
175+
{
176+
_sortFlag = sort;
177+
}
178+
165179

166180
void
167181
DataFlowGraphicsScene::

0 commit comments

Comments
 (0)