Skip to content
Snippets Groups Projects
Commit dadaea43 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

New method in ComponentUtils to return list of children for property editors.

parent c5f73c13
No related branches found
No related tags found
No related merge requests found
...@@ -16,11 +16,38 @@ ...@@ -16,11 +16,38 @@
#include "ComponentUtils.h" #include "ComponentUtils.h"
#include "item_constants.h" #include "item_constants.h"
#include "SessionItem.h"
QStringList ComponentUtils::propertyRelatedTypes() QStringList ComponentUtils::propertyRelatedTypes()
{ {
QStringList result = QStringList() << Constants::PropertyType << Constants::GroupItemType QStringList result = QStringList() << Constants::PropertyType << Constants::GroupItemType
<< Constants::VectorType << Constants::BasicAxisType << Constants::VectorType << Constants::BasicAxisType
<< Constants::AmplitudeAxisType; << Constants::AmplitudeAxisType
<< Constants::MaterialDataType;
return result;
}
QList<SessionItem*> ComponentUtils::componentItems(const SessionItem& item)
{
static QStringList propertyRelated = ComponentUtils::propertyRelatedTypes();
QList<SessionItem*> result;
for (auto child : item.children()) {
if (!child->isVisible())
continue;
if (propertyRelated.contains(child->modelType()))
result.append(child);
if (child->modelType() == Constants::GroupItemType) {
for (auto grandchild : child->children()) {
if (grandchild->isVisible())
result+= ComponentUtils::componentItems(*grandchild);
}
}
}
return result; return result;
} }
...@@ -18,8 +18,11 @@ ...@@ -18,8 +18,11 @@
#define COMPONENTUTILS_H #define COMPONENTUTILS_H
#include "WinDllMacros.h" #include "WinDllMacros.h"
#include <QList>
#include <QStringList> #include <QStringList>
class SessionItem;
//! Contains collection of utility functions to support editing of SessionItem's components. //! Contains collection of utility functions to support editing of SessionItem's components.
namespace ComponentUtils namespace ComponentUtils
...@@ -28,6 +31,9 @@ namespace ComponentUtils ...@@ -28,6 +31,9 @@ namespace ComponentUtils
//! Returns list of strings representing modelTypes suitable for editing in component editors. //! Returns list of strings representing modelTypes suitable for editing in component editors.
BA_CORE_API_ QStringList propertyRelatedTypes(); BA_CORE_API_ QStringList propertyRelatedTypes();
//! Returns list of SessionItem's children suitable for editing in property editors.
BA_CORE_API_ QList<SessionItem*> componentItems(const SessionItem& item);
} }
#endif #endif
...@@ -121,6 +121,7 @@ void TestComponentView::init_source() ...@@ -121,6 +121,7 @@ void TestComponentView::init_source()
GUIObjectBuilder guiBuilder; GUIObjectBuilder guiBuilder;
guiBuilder.populateSampleModel(m_sourceModel, *sample); guiBuilder.populateSampleModel(m_sourceModel, *sample);
m_sourceModel->insertNewItem(Constants::VectorType); m_sourceModel->insertNewItem(Constants::VectorType);
m_sourceModel->insertNewItem(Constants::BeamType);
// SessionItem* multilayer = m_sourceModel->insertNewItem(Constants::MultiLayerType); // SessionItem* multilayer = m_sourceModel->insertNewItem(Constants::MultiLayerType);
// m_sourceModel->insertNewItem(Constants::LayerType, m_sourceModel->indexOfItem(multilayer)); // m_sourceModel->insertNewItem(Constants::LayerType, m_sourceModel->indexOfItem(multilayer));
......
#include <QtTest>
#include "ComponentUtils.h"
#include "SessionItem.h"
#include "SessionModel.h"
#include "item_constants.h"
#include "ParticleItem.h"
#include "FormFactorItems.h"
#include <QDebug>
class TestComponentUtils : public QObject
{
Q_OBJECT
public:
private slots:
void test_componentItems();
};
//! Testing component items of particle item.
inline void TestComponentUtils::test_componentItems()
{
SessionModel model("TestModel");
SessionItem* particle = model.insertNewItem(Constants::ParticleType);
SessionItem* group = particle->getItem(ParticleItem::P_FORM_FACTOR);
SessionItem* ffItem = particle->getGroupItem(ParticleItem::P_FORM_FACTOR);
QList<SessionItem*> expectedList = QList<SessionItem*> ()
<< group
<< ffItem->getItem(CylinderItem::P_RADIUS)
<< ffItem->getItem(CylinderItem::P_HEIGHT)
<< particle->getItem(ParticleItem::P_MATERIAL)
<< particle->getItem(ParticleItem::P_ABUNDANCE)
<< particle->getItem(ParticleItem::P_POSITION);
auto itemList = ComponentUtils::componentItems(*particle);
QCOMPARE(itemList.size(), 6);
QCOMPARE(itemList, expectedList);
}
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "TestComponentProxyModel.h" #include "TestComponentProxyModel.h"
#include "TestProxyModelStrategy.h" #include "TestProxyModelStrategy.h"
#include "TestSessionItemUtils.h" #include "TestSessionItemUtils.h"
#include "TestComponentUtils.h"
#include <memory> #include <memory>
class GUITestFactory { class GUITestFactory {
...@@ -102,6 +103,7 @@ int main(int argc, char** argv) { ...@@ -102,6 +103,7 @@ int main(int argc, char** argv) {
tests.add<TestComponentProxyModel>(); tests.add<TestComponentProxyModel>();
tests.add<TestProxyModelStrategy>(); tests.add<TestProxyModelStrategy>();
tests.add<TestSessionItemUtils>(); tests.add<TestSessionItemUtils>();
tests.add<TestComponentUtils>();
return tests.runAll(argc, argv); return tests.runAll(argc, argv);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment