Skip to content

Commit 86c9134

Browse files
authored
Merge pull request #344 from gpospelov/FlatEditor
QCustomPlot update, Qt6 update
2 parents 08f692d + 8894d95 commit 86c9134

File tree

69 files changed

+27140
-20687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+27140
-20687
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ build
1111
/debian/qt-mvvm.substvars
1212
/debian/qt-mvvm-dev.substvars
1313
/obj-*
14+

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project(qt-mvvm VERSION 0.2.0 LANGUAGES CXX)
44
set(CMAKE_CXX_STANDARD 17)
55

66
option(MVVM_BUMP_VERSION "Propagate version number" OFF)
7+
option(MVVM_USE_QT6 "Compile with Qt6" OFF)
78
option(MVVM_DISCOVER_TESTS "Auto discover tests and add to ctest, otherwise will run at compile time" ON)
89
option(MVVM_ENABLE_FILESYSTEM "Enable <filesystem> (requires modern compiler), otherwise rely on Qt" ON)
910
option(MVVM_BUILD_EXAMPLES "Build user examples" ON)

README.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
## Overview
1111

1212
This model-view-viewmodel framework is intended for large Qt based scientific
13-
applications written in C++. The Project was created as a playground toward GUI
14-
refactoring of [BornAgain project](https://www.bornagainproject.org).
13+
applications written in C++. The Project was created as a refactoring
14+
playground, and it was never used for production.
1515

1616
Main features of the framework are:
1717

@@ -138,26 +138,19 @@ framework](https://doc.qt.io/archives/qq/qq18-propertybrowser.html).
138138
Third library, `libmmv_view.so`, contains few widgets for plotting and property
139139
editing.
140140

141-
## Size of the framework
142-
143-
+ 20k loc of libraries (`libmvvm_model.so`, `libmmv_viewmodel.so` and `libmmv_view.so`)
144-
+ 15k loc of tests
145-
+ 10k of user examples
146-
147141
## Disclaimer and afterword
148142

149-
The library is intended for large GUI applications. The definition of `large` is
150-
quite arbitrary and means something in the range 20k - 200k lines of code. The
151-
main logic here is that using the additional library for smaller Qt applications
152-
is redundant, Qt has everything that may be required. If a small GUI becomes messy
153-
with time, it can always be refactored or even rewritten from scratch.
154-
155-
However, when the number of views to show the same data is getting large, and
156-
the GUI enters the range 20k–200k, this is where a given library might help in
157-
proper separation of data, logic, and UI. When the GUI grows even further, well,
158-
developers of such large GUI know already what they need and probably have
159-
already implemented similar machinery.
160-
161-
The project is under active development.
143+
The library is intended for large GUI applications. The definition of `large` is quite
144+
arbitrary and means something in the range 20k - 200k lines of code. The main logic here
145+
is that using the additional library for smaller Qt applications is redundant, Qt has
146+
everything that may be required. If a small GUI becomes messy with time, it can always
147+
be refactored or even rewritten from scratch.
162148

149+
However, when the number of views to show the same data is getting large, and the GUI
150+
enters the range 20k–200k, this is where a given library might help in the proper
151+
separation of data, logic, and UI. When the GUI grows even further, well, developers
152+
of such a large GUI know already what they need and probably have already implemented
153+
similar machinery.
163154

155+
Please note, that the project is not actively maintained anymore. The author can't promise
156+
any timely reaction to user requests and bug reports.

cmake/modules/configuration.cmake

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,20 @@ file(MAKE_DIRECTORY ${MVVM_AUTOGEN_DIR})
4848
set(CMAKE_AUTOMOC ON)
4949
set(CMAKE_AUTORCC ON)
5050

51-
find_package(Qt5 5.12 COMPONENTS Widgets Core Gui PrintSupport REQUIRED)
5251
find_package(Threads)
5352

54-
get_target_property(Qt5Widgets_location Qt5::Widgets LOCATION_Release)
55-
message(STATUS " Qt5 libraries : ${Qt5Widgets_LIBRARIES} ${Qt5Widgets_location}")
56-
message(STATUS " Qt5 Includes : ${Qt5Widgets_INCLUDE_DIRS}")
53+
if (MVVM_USE_QT6)
54+
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Core Gui PrintSupport Test)
55+
else()
56+
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets Core Gui PrintSupport Test)
57+
endif()
58+
59+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core Gui PrintSupport Test)
60+
message(STATUS "Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} found")
61+
message(STATUS " Includes: ${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}")
62+
get_target_property(QtWidgets_location Qt${QT_VERSION_MAJOR}::Core LOCATION_Release)
63+
message(STATUS " Core library: ${QtWidgets_location}")
64+
5765

5866
# -----------------------------------------------------------------------------
5967
# Generating config files

examples/celleditors/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set(executable_name celleditors)
77
add_subdirectory(celleditorscore)
88
add_executable(${executable_name} main.cpp)
99

10-
target_link_libraries(${executable_name} celleditorscore Qt5::Widgets)
10+
target_link_libraries(${executable_name} celleditorscore Qt${QT_VERSION_MAJOR}::Widgets)
1111
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

examples/collidingmice/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ set(executable_name collidingmice)
1010
add_executable(${executable_name} main.cpp)
1111
add_subdirectory(collidingmicecore)
1212

13-
target_link_libraries(${executable_name} PRIVATE Qt5::Widgets MVVM::View)
13+
target_link_libraries(${executable_name} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets MVVM::View)
1414
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

examples/concurrentplot/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set(executable_name concurrentplot)
77
add_subdirectory(concurrentplotcore)
88
add_executable(${executable_name} main.cpp)
99

10-
target_link_libraries(${executable_name} concurrentplotcore Qt5::Widgets)
10+
target_link_libraries(${executable_name} concurrentplotcore Qt${QT_VERSION_MAJOR}::Widgets)
1111
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

examples/dragandmove/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set(executable_name dragandmove)
77
add_subdirectory(dragandmovecore)
88
add_executable(${executable_name} main.cpp)
99

10-
target_link_libraries(${executable_name} dragandmovecore Qt5::Widgets)
10+
target_link_libraries(${executable_name} dragandmovecore Qt${QT_VERSION_MAJOR}::Widgets)
1111
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

examples/dragandmove/dragandmovecore/dragviewmodel.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ DragViewModel::DragViewModel(SessionModel* model, QObject* parent)
3232

3333
Qt::ItemFlags DragViewModel::flags(const QModelIndex& index) const
3434
{
35-
Qt::ItemFlags defaultFlags = PropertyTableViewModel::flags(index);
35+
Qt::ItemFlags default_flags = PropertyTableViewModel::flags(index);
3636
if (index.isValid())
37-
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
38-
return Qt::ItemIsDropEnabled | defaultFlags;
37+
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | default_flags;
38+
return Qt::ItemIsDropEnabled | default_flags;
3939
}
4040

4141
QMimeData* DragViewModel::mimeData(const QModelIndexList& index_list) const
4242
{
43-
auto mimeData = new QMimeData;
43+
auto mime_data = new QMimeData;
4444
auto items = Utils::ParentItemsFromIndex(index_list);
4545

4646
// Saving list of SessionItem's identifiers related to all DemoItem
@@ -49,8 +49,8 @@ QMimeData* DragViewModel::mimeData(const QModelIndexList& index_list) const
4949
for (auto item : Utils::ParentItemsFromIndex(index_list))
5050
identifiers.append(QString::fromStdString(item->identifier()));
5151

52-
mimeData->setData(AppMimeType, Utils::serialize(identifiers));
53-
return mimeData;
52+
mime_data->setData(AppMimeType, Utils::serialize(identifiers));
53+
return mime_data;
5454
}
5555

5656
Qt::DropActions DragViewModel::supportedDragActions() const

examples/flateditor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set(executable_name flateditor)
77
add_subdirectory(flateditorcore)
88
add_executable(${executable_name} main.cpp)
99

10-
target_link_libraries(${executable_name} flateditorcore Qt5::Widgets)
10+
target_link_libraries(${executable_name} flateditorcore Qt${QT_VERSION_MAJOR}::Widgets)
1111
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)

examples/flateditor/flateditorcore/demowidget.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,52 @@
1717

1818
using namespace ModelView;
1919

20+
namespace FlatEditor {
21+
2022
DemoWidget::DemoWidget(SessionModel* model, QWidget* parent)
2123
: QWidget(parent)
22-
, m_defaultTreeView(new AllItemsTreeView(model))
23-
, m_propertyTreeView(new PropertyTreeView)
24-
, m_propertyFlatView(new PropertyFlatView)
25-
, m_sessionModel(model)
24+
, m_default_tree_view(new AllItemsTreeView(model))
25+
, m_property_tree_view(new PropertyTreeView)
26+
, m_property_flat_view(new PropertyFlatView)
27+
, m_sessio_model(model)
2628
{
2729

2830
auto layout = new QHBoxLayout;
29-
layout->addLayout(create_left_layout());
30-
layout->addLayout(create_right_layout());
31+
layout->addLayout(createLeftLayout());
32+
layout->addLayout(createRightLayout());
3133
layout->addLayout(layout);
3234
setLayout(layout);
3335

34-
connect_views();
36+
connectViews();
3537
}
3638

3739
DemoWidget::~DemoWidget() = default;
3840

3941
//! Connect tree views to provide mutual item selection.
4042

41-
void DemoWidget::connect_views()
43+
void DemoWidget::connectViews()
4244
{
4345
// select items in other views when selection in m_defaultTreeView has changed
4446
auto on_item_selected = [this](SessionItem* item) {
45-
m_propertyTreeView->setItem(item);
46-
m_propertyFlatView->setItem(item);
47+
m_property_tree_view->setItem(item);
48+
m_property_flat_view->setItem(item);
4749
};
48-
connect(m_defaultTreeView, &AllItemsTreeView::itemSelected, on_item_selected);
50+
connect(m_default_tree_view, &AllItemsTreeView::itemSelected, on_item_selected);
4951
}
5052

51-
QBoxLayout* DemoWidget::create_left_layout()
53+
QBoxLayout* DemoWidget::createLeftLayout()
5254
{
5355
auto result = new QVBoxLayout;
54-
result->addWidget(m_defaultTreeView);
56+
result->addWidget(m_default_tree_view);
5557
return result;
5658
}
5759

58-
QBoxLayout* DemoWidget::create_right_layout()
60+
QBoxLayout* DemoWidget::createRightLayout()
5961
{
6062
auto result = new QVBoxLayout;
61-
result->addWidget(m_propertyTreeView);
62-
result->addWidget(m_propertyFlatView);
63+
result->addWidget(m_property_tree_view);
64+
result->addWidget(m_property_flat_view);
6365
return result;
6466
}
67+
68+
} // namespace FlatEditor

examples/flateditor/flateditorcore/demowidget.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
#include <QWidget>
1414
#include <memory>
1515

16+
class QBoxLayout;
17+
1618
namespace ModelView {
1719
class SessionModel;
1820
class AllItemsTreeView;
1921
class PropertyTreeView;
2022
class PropertyFlatView;
2123
} // namespace ModelView
2224

23-
class QBoxLayout;
25+
namespace FlatEditor {
2426

2527
//! Demonstrates usage of PropertyFlatView.
2628

@@ -32,15 +34,17 @@ class DemoWidget : public QWidget {
3234
~DemoWidget();
3335

3436
private:
35-
QBoxLayout* create_left_layout();
36-
QBoxLayout* create_right_layout();
37+
QBoxLayout* createLeftLayout();
38+
QBoxLayout* createRightLayout();
3739

38-
void connect_views();
40+
void connectViews();
3941

40-
ModelView::AllItemsTreeView* m_defaultTreeView{nullptr};
41-
ModelView::PropertyTreeView* m_propertyTreeView{nullptr};
42-
ModelView::PropertyFlatView* m_propertyFlatView{nullptr};
43-
ModelView::SessionModel* m_sessionModel{nullptr};
42+
ModelView::AllItemsTreeView* m_default_tree_view{nullptr};
43+
ModelView::PropertyTreeView* m_property_tree_view{nullptr};
44+
ModelView::PropertyFlatView* m_property_flat_view{nullptr};
45+
ModelView::SessionModel* m_sessio_model{nullptr};
4446
};
4547

48+
} // namespace FlatEditor
49+
4650
#endif // FLATEDITORCORE_DEMOWIDGET_H

examples/flateditor/flateditorcore/mainwindow.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ const QString size_key = "size";
1919
const QString pos_key = "pos";
2020
} // namespace
2121

22-
MainWindow::MainWindow() : m_sampleModel(std::make_unique<SampleModel>())
22+
namespace FlatEditor {
23+
24+
MainWindow::MainWindow() : m_sample_model(std::make_unique<SampleModel>())
2325
{
24-
setCentralWidget(new DemoWidget(m_sampleModel.get()));
26+
setCentralWidget(new DemoWidget(m_sample_model.get()));
2527
initApplication();
2628
}
2729

@@ -56,3 +58,5 @@ void MainWindow::writeSettings()
5658
settings.setValue(pos_key, pos());
5759
settings.endGroup();
5860
}
61+
62+
} // namespace FlatEditor

examples/flateditor/flateditorcore/mainwindow.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <QMainWindow>
1414
#include <memory>
1515

16+
namespace FlatEditor {
17+
1618
class SampleModel;
1719

1820
//! The main window of this application.
@@ -31,7 +33,9 @@ class MainWindow : public QMainWindow {
3133
void initApplication();
3234
void writeSettings();
3335

34-
std::unique_ptr<SampleModel> m_sampleModel;
36+
std::unique_ptr<SampleModel> m_sample_model;
3537
};
3638

39+
} // namespace FlatEditor
40+
3741
#endif // FLATEDITORCORE_MAINWINDOW_H

examples/flateditor/flateditorcore/sampleitems.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ using namespace ModelView;
1717
namespace {
1818
const std::string xrays = "x-rays";
1919
const std::string neutrons = "neutrons";
20+
const std::string BeamItemType = "Beam";
21+
const std::string DistributionNoneItemType = "DistributionNone";
22+
const std::string DistributionGaussianItemType = "DistributionGaussian";
23+
const std::string DistributionLogNormalItemType = "DistributionLogNormal";
24+
const std::string DistributionTrapezoidItemType = "DistributionTrapezoid";
25+
const std::string DistributionGroupItemType = "DistributionGroup";
2026
} // namespace
2127

28+
namespace FlatEditor {
29+
2230
// ----------------------------------------------------------------------------
2331

24-
BeamItem::BeamItem() : ModelView::CompoundItem(::Constants::BeamItemType)
32+
BeamItem::BeamItem() : ModelView::CompoundItem(BeamItemType)
2533
{
2634
auto combo = ComboProperty::createFrom({xrays, neutrons});
2735
addProperty(P_BEAM_TYPE, combo)->setDisplayName("Type");
@@ -61,8 +69,7 @@ void BeamItem::update_appearance()
6169

6270
// ----------------------------------------------------------------------------
6371

64-
DistributionNoneItem::DistributionNoneItem()
65-
: ModelView::CompoundItem(::Constants::DistributionNoneItemType)
72+
DistributionNoneItem::DistributionNoneItem() : ModelView::CompoundItem(DistributionNoneItemType)
6673
{
6774
setDisplayName("Fixed value");
6875
addProperty(P_MEAN, 0.5)->setDisplayName("Value");
@@ -71,7 +78,7 @@ DistributionNoneItem::DistributionNoneItem()
7178
// ----------------------------------------------------------------------------
7279

7380
DistributionGaussianItem::DistributionGaussianItem()
74-
: ModelView::CompoundItem(::Constants::DistributionGaussianItemType)
81+
: ModelView::CompoundItem(DistributionGaussianItemType)
7582
{
7683
addProperty(P_MEAN, 0.5)->setDisplayName("Mean");
7784
addProperty(P_STD_DEV, 1.0)->setDisplayName("StdDev");
@@ -80,7 +87,7 @@ DistributionGaussianItem::DistributionGaussianItem()
8087
// ----------------------------------------------------------------------------
8188

8289
DistributionLogNormalItem::DistributionLogNormalItem()
83-
: ModelView::CompoundItem(::Constants::DistributionLogNormalItemType)
90+
: ModelView::CompoundItem(DistributionLogNormalItemType)
8491
{
8592
addProperty(P_MEDIAN, 1.0)->setDisplayName("Median");
8693
addProperty(P_SCALE_PAR, 1.0)->setDisplayName("Scale");
@@ -89,7 +96,7 @@ DistributionLogNormalItem::DistributionLogNormalItem()
8996
// ----------------------------------------------------------------------------
9097

9198
DistributionTrapezoidItem::DistributionTrapezoidItem()
92-
: ModelView::CompoundItem(::Constants::DistributionTrapezoidItemType)
99+
: ModelView::CompoundItem(DistributionTrapezoidItemType)
93100
{
94101
addProperty(P_CENTER, 1.0)->setDisplayName("Center");
95102
addProperty(P_LEFTWIDTH, 0.5)->setDisplayName("Left width");
@@ -99,10 +106,12 @@ DistributionTrapezoidItem::DistributionTrapezoidItem()
99106

100107
// ----------------------------------------------------------------------------
101108

102-
DistributionGroupItem::DistributionGroupItem() : GroupItem(::Constants::DistributionGroupItemType)
109+
DistributionGroupItem::DistributionGroupItem() : GroupItem(DistributionGroupItemType)
103110
{
104111
addToGroup<DistributionNoneItem>("Fixed value");
105112
addToGroup<DistributionGaussianItem>("Gaussian");
106113
addToGroup<DistributionLogNormalItem>("Log normal");
107114
addToGroup<DistributionTrapezoidItem>("Trapezoid");
108115
}
116+
117+
} // namespace FlatEditor

0 commit comments

Comments
 (0)