Skip to content

Commit

Permalink
Populate group property example with the content
Browse files Browse the repository at this point in the history
  • Loading branch information
gpospelov committed Feb 10, 2021
1 parent 6f827f8 commit ee956cf
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/groupproperty/grouppropertycore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ target_sources(${library_name} PRIVATE
mainwindow.h
items.cpp
items.h
widget.cpp
widget.h
)
6 changes: 6 additions & 0 deletions examples/groupproperty/grouppropertycore/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ ParticleItem::ParticleItem() : ModelView::CompoundItem("Particle")
addProperty<ModelView::VectorItem>("Position");
}

Model::Model()
{
// register custom item to use with the model
registerItem<ParticleItem>();
}

} // namespace GroupProperty
8 changes: 8 additions & 0 deletions examples/groupproperty/grouppropertycore/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "mvvm/model/compounditem.h"
#include "mvvm/model/groupitem.h"
#include "mvvm/model/sessionmodel.h"

namespace GroupProperty {

Expand Down Expand Up @@ -57,6 +58,13 @@ class ParticleItem : public ModelView::CompoundItem {
ParticleItem();
};

//! Main model of the application.

class Model : public ModelView::SessionModel {
public:
Model();
};

} // namespace GroupProperty

#endif // GROUPPROPERTYCORE_ITEMS_H
3 changes: 2 additions & 1 deletion examples/groupproperty/grouppropertycore/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// ************************************************************************** //

#include "mainwindow.h"
#include "widget.h"
#include <QCoreApplication>
#include <QSettings>

Expand All @@ -21,7 +22,7 @@ namespace GroupProperty {

MainWindow::MainWindow()
{
setCentralWidget(new QWidget);
setCentralWidget(new Widget);
initApplication();
}

Expand Down
33 changes: 33 additions & 0 deletions examples/groupproperty/grouppropertycore/widget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ************************************************************************** //
//
// Model-view-view-model framework for large GUI applications
//
//! @license GNU General Public License v3 or higher (see COPYING)
//! @authors see AUTHORS
//
// ************************************************************************** //

#include "widget.h"
#include "mvvm/widgets/allitemstreeview.h"
#include "mvvm/widgets/propertytreeview.h"
#include <QHBoxLayout>

namespace GroupProperty {

Widget::Widget(QWidget* parent)
: QWidget(parent)
, m_treeView(new ModelView::AllItemsTreeView(&m_model))
, m_propertyEditor(new ModelView::PropertyTreeView)
{
auto layout = new QHBoxLayout(this);
layout->addWidget(m_treeView);
layout->addWidget(m_propertyEditor);

// populate the model with single ParticleItem
auto particleItem = m_model.insertItem<ParticleItem>();

// and make property editor displaying this item
m_propertyEditor->setItem(particleItem);
}

} // namespace GroupProperty
42 changes: 42 additions & 0 deletions examples/groupproperty/grouppropertycore/widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ************************************************************************** //
//
// Model-view-view-model framework for large GUI applications
//
//! @license GNU General Public License v3 or higher (see COPYING)
//! @authors see AUTHORS
//
// ************************************************************************** //

#ifndef GROUPPROPERTYCORE_WIDGET_H
#define GROUPPROPERTYCORE_WIDGET_H

#include "items.h"
#include <QWidget>

namespace ModelView {
class AllItemsTreeView;
class PropertyTreeView;
} // namespace ModelView

namespace GroupProperty {

class Model;

//! The widget contains a tree view displaying the model content on the left,
//! and property editor showing the content of a single ParticleItem on the right.

class Widget : public QWidget {
Q_OBJECT

public:
Widget(QWidget* parent = nullptr);

private:
Model m_model;
ModelView::AllItemsTreeView* m_treeView{nullptr};
ModelView::PropertyTreeView* m_propertyEditor{nullptr};
};

} // namespace GroupProperty

#endif // GROUPPROPERTYCORE_WIDGET_H

0 comments on commit ee956cf

Please sign in to comment.