Skip to content

Commit

Permalink
Cleanup example
Browse files Browse the repository at this point in the history
  • Loading branch information
gpospelov committed Jan 26, 2021
1 parent ef4e2ba commit 7da500b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void ContainerEditorWidget::setModel(SampleModel* model, SessionItem* root_item)

void ContainerEditorWidget::onAdd()
{
m_model->append_random_item(m_container);
m_model->appendRandomItem(m_container);
}

void ContainerEditorWidget::onCopy()
Expand Down
18 changes: 7 additions & 11 deletions examples/dragandmove/dragandmovecore/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "samplemodel.h"
#include <QCoreApplication>
#include <QSettings>
#include <QTabWidget>

namespace {
const QString main_window_group = "MainWindow";
Expand All @@ -22,24 +21,21 @@ const QString pos_key = "pos";

namespace DragAndMove {

MainWindow::MainWindow() : m_tabWidget(new QTabWidget), m_model(std::make_unique<SampleModel>())
MainWindow::MainWindow() : m_model(std::make_unique<SampleModel>())
{
setCentralWidget(m_tabWidget);
init_application();

m_tabWidget->addTab(new ModelEditorWidget(m_model.get()), "Drag and Move");
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
setCentralWidget(new ModelEditorWidget(m_model.get()));
initApplication();
}

MainWindow::~MainWindow() = default;

void MainWindow::closeEvent(QCloseEvent* event)
{
write_settings();
writeSettings();
QMainWindow::closeEvent(event);
}

void MainWindow::write_settings()
void MainWindow::writeSettings()
{
QSettings settings;
settings.beginGroup(main_window_group);
Expand All @@ -48,7 +44,7 @@ void MainWindow::write_settings()
settings.endGroup();
}

void MainWindow::init_application()
void MainWindow::initApplication()
{
QCoreApplication::setApplicationName("dragandmove");
QCoreApplication::setApplicationVersion("0.1");
Expand All @@ -63,4 +59,4 @@ void MainWindow::init_application()
}
}

} // namespace DragAndView
} // namespace DragAndMove
7 changes: 2 additions & 5 deletions examples/dragandmove/dragandmovecore/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <QMainWindow>
#include <memory>

class QTabWidget;

namespace DragAndMove {

class SampleModel;
Expand All @@ -32,10 +30,9 @@ class MainWindow : public QMainWindow {
void closeEvent(QCloseEvent* event);

private:
void write_settings();
void init_application();
void writeSettings();
void initApplication();

QTabWidget* m_tabWidget;
std::unique_ptr<SampleModel> m_model;
};

Expand Down
20 changes: 10 additions & 10 deletions examples/dragandmove/dragandmovecore/samplemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// ************************************************************************** //

#include "samplemodel.h"
#include "sampleitems.h"
#include "mvvm/utils/numericutils.h"
#include "mvvm/widgets/widgetutils.h"
#include "sampleitems.h"
#include <QColor>

namespace DragAndMove {
Expand All @@ -36,11 +36,11 @@ SampleModel::SampleModel() : SessionModel("SampleModel")
{
registerItem<DemoItem>();
registerItem<DemoContainerItem>();
init_model_content();
populateModel();
setUndoRedoEnabled(true);
}

void SampleModel::append_random_item(ModelView::SessionItem* container)
void SampleModel::appendRandomItem(ModelView::SessionItem* container)
{
auto item = insertItem<DemoItem>(container);
item->setProperty(DemoItem::P_COLOR_PROPERTY, ModelView::Utils::RandomColor());
Expand All @@ -50,16 +50,16 @@ void SampleModel::append_random_item(ModelView::SessionItem* container)

//! Generates initial model content.

void SampleModel::init_model_content()
void SampleModel::populateModel()
{
auto container = insertItem<DemoContainerItem>();
append_random_item(container);
append_random_item(container);
append_random_item(container);
appendRandomItem(container);
appendRandomItem(container);
appendRandomItem(container);

container = insertItem<DemoContainerItem>();
append_random_item(container);
append_random_item(container);
appendRandomItem(container);
appendRandomItem(container);
}

} // namespace DragAndView
} // namespace DragAndMove
6 changes: 3 additions & 3 deletions examples/dragandmove/dragandmovecore/samplemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class SampleModel : public ModelView::SessionModel {
public:
SampleModel();

void append_random_item(ModelView::SessionItem* container);
void appendRandomItem(ModelView::SessionItem* container);

private:
void init_model_content();
void populateModel();
};

} // namespace DragAndView
} // namespace DragAndMove

#endif

0 comments on commit 7da500b

Please sign in to comment.