Skip to content

Commit

Permalink
Merge pull request #344 from gpospelov/FlatEditor
Browse files Browse the repository at this point in the history
QCustomPlot update, Qt6 update
  • Loading branch information
gpospelov authored Aug 3, 2024
2 parents 08f692d + 8894d95 commit 86c9134
Show file tree
Hide file tree
Showing 69 changed files with 27,140 additions and 20,687 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
/debian/qt-mvvm.substvars
/debian/qt-mvvm-dev.substvars
/obj-*

1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(qt-mvvm VERSION 0.2.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)

option(MVVM_BUMP_VERSION "Propagate version number" OFF)
option(MVVM_USE_QT6 "Compile with Qt6" OFF)
option(MVVM_DISCOVER_TESTS "Auto discover tests and add to ctest, otherwise will run at compile time" ON)
option(MVVM_ENABLE_FILESYSTEM "Enable <filesystem> (requires modern compiler), otherwise rely on Qt" ON)
option(MVVM_BUILD_EXAMPLES "Build user examples" ON)
Expand Down
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
## Overview

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

Main features of the framework are:

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

## Size of the framework

+ 20k loc of libraries (`libmvvm_model.so`, `libmmv_viewmodel.so` and `libmmv_view.so`)
+ 15k loc of tests
+ 10k of user examples

## Disclaimer and afterword

The library is intended for large GUI applications. The definition of `large` is
quite arbitrary and means something in the range 20k - 200k lines of code. The
main logic here is that using the additional library for smaller Qt applications
is redundant, Qt has everything that may be required. If a small GUI becomes messy
with time, it can always be refactored or even rewritten from scratch.

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

The project is under active development.
The library is intended for large GUI applications. The definition of `large` is quite
arbitrary and means something in the range 20k - 200k lines of code. The main logic here
is that using the additional library for smaller Qt applications is redundant, Qt has
everything that may be required. If a small GUI becomes messy with time, it can always
be refactored or even rewritten from scratch.

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

Please note, that the project is not actively maintained anymore. The author can't promise
any timely reaction to user requests and bug reports.
16 changes: 12 additions & 4 deletions cmake/modules/configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ file(MAKE_DIRECTORY ${MVVM_AUTOGEN_DIR})
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5 5.12 COMPONENTS Widgets Core Gui PrintSupport REQUIRED)
find_package(Threads)

get_target_property(Qt5Widgets_location Qt5::Widgets LOCATION_Release)
message(STATUS " Qt5 libraries : ${Qt5Widgets_LIBRARIES} ${Qt5Widgets_location}")
message(STATUS " Qt5 Includes : ${Qt5Widgets_INCLUDE_DIRS}")
if (MVVM_USE_QT6)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Core Gui PrintSupport Test)
else()
find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets Core Gui PrintSupport Test)
endif()

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core Gui PrintSupport Test)
message(STATUS "Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} found")
message(STATUS " Includes: ${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}")
get_target_property(QtWidgets_location Qt${QT_VERSION_MAJOR}::Core LOCATION_Release)
message(STATUS " Core library: ${QtWidgets_location}")


# -----------------------------------------------------------------------------
# Generating config files
Expand Down
2 changes: 1 addition & 1 deletion examples/celleditors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set(executable_name celleditors)
add_subdirectory(celleditorscore)
add_executable(${executable_name} main.cpp)

target_link_libraries(${executable_name} celleditorscore Qt5::Widgets)
target_link_libraries(${executable_name} celleditorscore Qt${QT_VERSION_MAJOR}::Widgets)
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2 changes: 1 addition & 1 deletion examples/collidingmice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ set(executable_name collidingmice)
add_executable(${executable_name} main.cpp)
add_subdirectory(collidingmicecore)

target_link_libraries(${executable_name} PRIVATE Qt5::Widgets MVVM::View)
target_link_libraries(${executable_name} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets MVVM::View)
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2 changes: 1 addition & 1 deletion examples/concurrentplot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set(executable_name concurrentplot)
add_subdirectory(concurrentplotcore)
add_executable(${executable_name} main.cpp)

target_link_libraries(${executable_name} concurrentplotcore Qt5::Widgets)
target_link_libraries(${executable_name} concurrentplotcore Qt${QT_VERSION_MAJOR}::Widgets)
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
2 changes: 1 addition & 1 deletion examples/dragandmove/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set(executable_name dragandmove)
add_subdirectory(dragandmovecore)
add_executable(${executable_name} main.cpp)

target_link_libraries(${executable_name} dragandmovecore Qt5::Widgets)
target_link_libraries(${executable_name} dragandmovecore Qt${QT_VERSION_MAJOR}::Widgets)
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
12 changes: 6 additions & 6 deletions examples/dragandmove/dragandmovecore/dragviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ DragViewModel::DragViewModel(SessionModel* model, QObject* parent)

Qt::ItemFlags DragViewModel::flags(const QModelIndex& index) const
{
Qt::ItemFlags defaultFlags = PropertyTableViewModel::flags(index);
Qt::ItemFlags default_flags = PropertyTableViewModel::flags(index);
if (index.isValid())
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
return Qt::ItemIsDropEnabled | defaultFlags;
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | default_flags;
return Qt::ItemIsDropEnabled | default_flags;
}

QMimeData* DragViewModel::mimeData(const QModelIndexList& index_list) const
{
auto mimeData = new QMimeData;
auto mime_data = new QMimeData;
auto items = Utils::ParentItemsFromIndex(index_list);

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

mimeData->setData(AppMimeType, Utils::serialize(identifiers));
return mimeData;
mime_data->setData(AppMimeType, Utils::serialize(identifiers));
return mime_data;
}

Qt::DropActions DragViewModel::supportedDragActions() const
Expand Down
2 changes: 1 addition & 1 deletion examples/flateditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set(executable_name flateditor)
add_subdirectory(flateditorcore)
add_executable(${executable_name} main.cpp)

target_link_libraries(${executable_name} flateditorcore Qt5::Widgets)
target_link_libraries(${executable_name} flateditorcore Qt${QT_VERSION_MAJOR}::Widgets)
target_include_directories(${executable_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
36 changes: 20 additions & 16 deletions examples/flateditor/flateditorcore/demowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,52 @@

using namespace ModelView;

namespace FlatEditor {

DemoWidget::DemoWidget(SessionModel* model, QWidget* parent)
: QWidget(parent)
, m_defaultTreeView(new AllItemsTreeView(model))
, m_propertyTreeView(new PropertyTreeView)
, m_propertyFlatView(new PropertyFlatView)
, m_sessionModel(model)
, m_default_tree_view(new AllItemsTreeView(model))
, m_property_tree_view(new PropertyTreeView)
, m_property_flat_view(new PropertyFlatView)
, m_sessio_model(model)
{

auto layout = new QHBoxLayout;
layout->addLayout(create_left_layout());
layout->addLayout(create_right_layout());
layout->addLayout(createLeftLayout());
layout->addLayout(createRightLayout());
layout->addLayout(layout);
setLayout(layout);

connect_views();
connectViews();
}

DemoWidget::~DemoWidget() = default;

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

void DemoWidget::connect_views()
void DemoWidget::connectViews()
{
// select items in other views when selection in m_defaultTreeView has changed
auto on_item_selected = [this](SessionItem* item) {
m_propertyTreeView->setItem(item);
m_propertyFlatView->setItem(item);
m_property_tree_view->setItem(item);
m_property_flat_view->setItem(item);
};
connect(m_defaultTreeView, &AllItemsTreeView::itemSelected, on_item_selected);
connect(m_default_tree_view, &AllItemsTreeView::itemSelected, on_item_selected);
}

QBoxLayout* DemoWidget::create_left_layout()
QBoxLayout* DemoWidget::createLeftLayout()
{
auto result = new QVBoxLayout;
result->addWidget(m_defaultTreeView);
result->addWidget(m_default_tree_view);
return result;
}

QBoxLayout* DemoWidget::create_right_layout()
QBoxLayout* DemoWidget::createRightLayout()
{
auto result = new QVBoxLayout;
result->addWidget(m_propertyTreeView);
result->addWidget(m_propertyFlatView);
result->addWidget(m_property_tree_view);
result->addWidget(m_property_flat_view);
return result;
}

} // namespace FlatEditor
20 changes: 12 additions & 8 deletions examples/flateditor/flateditorcore/demowidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
#include <QWidget>
#include <memory>

class QBoxLayout;

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

class QBoxLayout;
namespace FlatEditor {

//! Demonstrates usage of PropertyFlatView.

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

private:
QBoxLayout* create_left_layout();
QBoxLayout* create_right_layout();
QBoxLayout* createLeftLayout();
QBoxLayout* createRightLayout();

void connect_views();
void connectViews();

ModelView::AllItemsTreeView* m_defaultTreeView{nullptr};
ModelView::PropertyTreeView* m_propertyTreeView{nullptr};
ModelView::PropertyFlatView* m_propertyFlatView{nullptr};
ModelView::SessionModel* m_sessionModel{nullptr};
ModelView::AllItemsTreeView* m_default_tree_view{nullptr};
ModelView::PropertyTreeView* m_property_tree_view{nullptr};
ModelView::PropertyFlatView* m_property_flat_view{nullptr};
ModelView::SessionModel* m_sessio_model{nullptr};
};

} // namespace FlatEditor

#endif // FLATEDITORCORE_DEMOWIDGET_H
8 changes: 6 additions & 2 deletions examples/flateditor/flateditorcore/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const QString size_key = "size";
const QString pos_key = "pos";
} // namespace

MainWindow::MainWindow() : m_sampleModel(std::make_unique<SampleModel>())
namespace FlatEditor {

MainWindow::MainWindow() : m_sample_model(std::make_unique<SampleModel>())
{
setCentralWidget(new DemoWidget(m_sampleModel.get()));
setCentralWidget(new DemoWidget(m_sample_model.get()));
initApplication();
}

Expand Down Expand Up @@ -56,3 +58,5 @@ void MainWindow::writeSettings()
settings.setValue(pos_key, pos());
settings.endGroup();
}

} // namespace FlatEditor
6 changes: 5 additions & 1 deletion examples/flateditor/flateditorcore/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <QMainWindow>
#include <memory>

namespace FlatEditor {

class SampleModel;

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

std::unique_ptr<SampleModel> m_sampleModel;
std::unique_ptr<SampleModel> m_sample_model;
};

} // namespace FlatEditor

#endif // FLATEDITORCORE_MAINWINDOW_H
23 changes: 16 additions & 7 deletions examples/flateditor/flateditorcore/sampleitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ using namespace ModelView;
namespace {
const std::string xrays = "x-rays";
const std::string neutrons = "neutrons";
const std::string BeamItemType = "Beam";
const std::string DistributionNoneItemType = "DistributionNone";
const std::string DistributionGaussianItemType = "DistributionGaussian";
const std::string DistributionLogNormalItemType = "DistributionLogNormal";
const std::string DistributionTrapezoidItemType = "DistributionTrapezoid";
const std::string DistributionGroupItemType = "DistributionGroup";
} // namespace

namespace FlatEditor {

// ----------------------------------------------------------------------------

BeamItem::BeamItem() : ModelView::CompoundItem(::Constants::BeamItemType)
BeamItem::BeamItem() : ModelView::CompoundItem(BeamItemType)
{
auto combo = ComboProperty::createFrom({xrays, neutrons});
addProperty(P_BEAM_TYPE, combo)->setDisplayName("Type");
Expand Down Expand Up @@ -61,8 +69,7 @@ void BeamItem::update_appearance()

// ----------------------------------------------------------------------------

DistributionNoneItem::DistributionNoneItem()
: ModelView::CompoundItem(::Constants::DistributionNoneItemType)
DistributionNoneItem::DistributionNoneItem() : ModelView::CompoundItem(DistributionNoneItemType)
{
setDisplayName("Fixed value");
addProperty(P_MEAN, 0.5)->setDisplayName("Value");
Expand All @@ -71,7 +78,7 @@ DistributionNoneItem::DistributionNoneItem()
// ----------------------------------------------------------------------------

DistributionGaussianItem::DistributionGaussianItem()
: ModelView::CompoundItem(::Constants::DistributionGaussianItemType)
: ModelView::CompoundItem(DistributionGaussianItemType)
{
addProperty(P_MEAN, 0.5)->setDisplayName("Mean");
addProperty(P_STD_DEV, 1.0)->setDisplayName("StdDev");
Expand All @@ -80,7 +87,7 @@ DistributionGaussianItem::DistributionGaussianItem()
// ----------------------------------------------------------------------------

DistributionLogNormalItem::DistributionLogNormalItem()
: ModelView::CompoundItem(::Constants::DistributionLogNormalItemType)
: ModelView::CompoundItem(DistributionLogNormalItemType)
{
addProperty(P_MEDIAN, 1.0)->setDisplayName("Median");
addProperty(P_SCALE_PAR, 1.0)->setDisplayName("Scale");
Expand All @@ -89,7 +96,7 @@ DistributionLogNormalItem::DistributionLogNormalItem()
// ----------------------------------------------------------------------------

DistributionTrapezoidItem::DistributionTrapezoidItem()
: ModelView::CompoundItem(::Constants::DistributionTrapezoidItemType)
: ModelView::CompoundItem(DistributionTrapezoidItemType)
{
addProperty(P_CENTER, 1.0)->setDisplayName("Center");
addProperty(P_LEFTWIDTH, 0.5)->setDisplayName("Left width");
Expand All @@ -99,10 +106,12 @@ DistributionTrapezoidItem::DistributionTrapezoidItem()

// ----------------------------------------------------------------------------

DistributionGroupItem::DistributionGroupItem() : GroupItem(::Constants::DistributionGroupItemType)
DistributionGroupItem::DistributionGroupItem() : GroupItem(DistributionGroupItemType)
{
addToGroup<DistributionNoneItem>("Fixed value");
addToGroup<DistributionGaussianItem>("Gaussian");
addToGroup<DistributionLogNormalItem>("Log normal");
addToGroup<DistributionTrapezoidItem>("Trapezoid");
}

} // namespace FlatEditor
Loading

0 comments on commit 86c9134

Please sign in to comment.