Compare commits

...

2 Commits

7 changed files with 104 additions and 114 deletions

View File

@ -21,23 +21,23 @@ find_package(
add_library(
maraiah-tycho-hermes
SHARED
$ENV{OUT_DIR}/bindings.cc
$ENV{OUT_DIR}/bindings.h
cc/main.cc
cc/mapmodel.cc
cc/mapprops.cc
cc/mapview.cc
cc/menu.cc
cc/project.cc
cc/tycho.h
resources/resources.qrc
ui/about.ui
ui/license.ui
ui/mapprops.ui
ui/mapview.ui
ui/menu.ui
ui/points.ui
ui/project.ui
$ENV{OUT_DIR}/bindings.cc
$ENV{OUT_DIR}/bindings.h
cc/main.cc
cc/mapmodel.cc
cc/mapprops.cc
cc/mapview.cc
cc/menu.cc
cc/project.cc
cc/tycho.h
resources/resources.qrc
ui/about.ui
ui/license.ui
ui/mapprops.ui
ui/mapview.ui
ui/menu.ui
ui/points.ui
ui/project.ui
)
set_target_properties(
@ -55,8 +55,8 @@ target_include_directories(
target_link_libraries(
maraiah-tycho-hermes
Qt5::Core
Qt5::Widgets
Qt5::Core
Qt5::Widgets
)
target_compile_definitions(

View File

@ -17,26 +17,6 @@ ProjectModel::Type MapModel::type() const
return ProjectModel::Map;
}
QAbstractItemModel const *MapModel::getAbstract() const
{
return this;
}
QAbstractItemModel *MapModel::getAbstract()
{
return this;
}
MapModel const *MapModel::getMap() const
{
return this;
}
MapModel *MapModel::getMap()
{
return this;
}
bool MapModel::isDirty() const
{
return AbstractMapModel::isDirty();
@ -62,7 +42,8 @@ QVariant MapModel::data(const QModelIndex &index, int role) const
switch(role) {
case Qt::DecorationRole: {
auto name = propIcon(index.row());
auto icon = name.front() == ':' ? QIcon(name) : QIcon::fromTheme(name);
auto icon = name.front() == ':' ? QIcon(name)
: QIcon::fromTheme(name);
return QVariant::fromValue(icon);
}
default:

View File

@ -1,6 +1,6 @@
#include "tycho.h"
MapProps::MapProps(MapModel *_mapModel, QWidget *parent) :
MapProps::MapProps(std::weak_ptr<MapModel> _mapModel, QWidget *parent) :
QDialog(parent),
mapModel(_mapModel)
{

View File

@ -1,7 +1,8 @@
#include "tycho.h"
MapView::MapView(MapModel *mapModel, QWidget *parent) :
QWidget(parent)
MapView::MapView(std::weak_ptr<MapModel> _mapModel, QWidget *parent) :
QWidget(parent),
mapModel(_mapModel)
{
setupUi(this);

View File

@ -42,7 +42,7 @@ void Menu::mapOpen()
if(!fname.isEmpty()) {
QScopedPointer proj{new Project(new MapModel)};
if(proj->model->open(fname)) {
if(proj->getModel()->open(fname)) {
addProject(proj.take());
}
}
@ -98,8 +98,8 @@ void Menu::openMapProperties()
{
auto proj = activeProject();
if(proj && proj->model->type() == ProjectModel::Map) {
MapProps props{proj->model->getMap(), proj};
if(proj && proj->getModel()->type() == ProjectModel::Map) {
MapProps props{proj->getMapModel(), proj};
props.exec();
}
}

View File

@ -11,7 +11,7 @@ Project::Project(ProjectModel *_model, QWidget *parent) :
setWidget(widget);
setAttribute(Qt::WA_DeleteOnClose);
listView->setModel(model->getAbstract());
listView->setModel(dynamic_cast<QAbstractItemModel *>(model.get()));
dbgPrintFunc();
}
@ -21,6 +21,16 @@ Project::~Project()
dbgPrintFunc();
}
std::shared_ptr<ProjectModel> Project::getModel()
{
return model;
}
std::shared_ptr<MapModel> Project::getMapModel()
{
return std::dynamic_pointer_cast<MapModel>(model);
}
void Project::closeEvent(QCloseEvent *event)
{
if(model->isDirty()) {

View File

@ -3,6 +3,7 @@
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <memory>
#include <vector>
#include <QApplication>
@ -15,6 +16,8 @@
#include <QMdiSubWindow>
#include <QMessageBox>
#include "bindings.h"
#include "../ui/ui_about.h"
#include "../ui/ui_license.h"
#include "../ui/ui_mapprops.h"
@ -22,66 +25,17 @@
#include "../ui/ui_menu.h"
#include "../ui/ui_project.h"
#include "bindings.h"
#ifdef TYCHO_DEBUG_ASSERTIONS
#define dbgPrint(...) qDebug(__VA_ARGS__)
#else
#define dbgPrint(...)
#endif
#define dbgPrintFunc() dbgPrint("%s", __func__)
// TODO: namespace Tycho {
class MapModel;
class MapProps;
class MapView;
class Menu;
class Project;
class ProjectModel;
class MapProps : public QDialog, private Ui::MapProps
{
Q_OBJECT
public:
explicit MapProps(MapModel *mapModel, QWidget *parent = nullptr);
~MapProps();
private:
MapModel *mapModel;
};
class MapView : public QWidget, private Ui::MapView
{
Q_OBJECT
public:
explicit MapView(MapModel *mapModel, QWidget *parent = nullptr);
~MapView();
};
class Project : public QMdiSubWindow, private Ui::Project
{
Q_OBJECT
public:
explicit Project(ProjectModel *model, QWidget *parent = nullptr);
~Project();
QSharedPointer<ProjectModel> model;
protected:
void closeEvent(QCloseEvent *event) override;
};
class ProjectModel
{
public:
enum Type
{
Invalid,
Map,
};
@ -89,18 +43,13 @@ public:
virtual Type type() const = 0;
virtual QAbstractItemModel const *getAbstract() const = 0;
virtual QAbstractItemModel *getAbstract() = 0;
virtual MapModel const *getMap() const = 0;
virtual MapModel *getMap() = 0;
virtual bool isDirty() const = 0;
virtual bool open(QString const &path) = 0;
virtual bool save() const = 0;
virtual bool saveAs(QString const &path) const = 0;
};
class MapModel final : private AbstractMapModel, public ProjectModel
class MapModel final : public AbstractMapModel, public ProjectModel
{
Q_OBJECT
@ -110,11 +59,6 @@ public:
ProjectModel::Type type() const override;
QAbstractItemModel const *getAbstract() const override;
QAbstractItemModel *getAbstract() override;
MapModel const *getMap() const override;
MapModel *getMap() override;
bool isDirty() const override;
bool open(QString const &path) override;
bool save() const override;
@ -125,7 +69,33 @@ private:
const override;
};
class Menu : public QMainWindow, private Ui::Menu
class MapProps final : public QDialog, private Ui::MapProps
{
Q_OBJECT
public:
explicit MapProps(std::weak_ptr<MapModel> mapModel,
QWidget *parent = nullptr);
~MapProps();
private:
std::weak_ptr<MapModel> mapModel;
};
class MapView final : public QWidget, private Ui::MapView
{
Q_OBJECT
public:
explicit MapView(std::weak_ptr<MapModel> mapModel,
QWidget *parent = nullptr);
~MapView();
private:
std::weak_ptr<MapModel> mapModel;
};
class Menu final : public QMainWindow, private Ui::Menu
{
Q_OBJECT
@ -151,10 +121,40 @@ private:
void addProject(Project *proj);
};
constexpr std::uint32_t fourCC(std::uint8_t a,
std::uint8_t b,
std::uint8_t c,
std::uint8_t d)
class Project final : public QMdiSubWindow, private Ui::Project
{
Q_OBJECT
public:
explicit Project(ProjectModel *model, QWidget *parent = nullptr);
~Project();
std::shared_ptr<ProjectModel> getModel();
std::shared_ptr<MapModel> getMapModel();
std::shared_ptr<QAbstractItemModel> getAbstractModel();
protected:
void closeEvent(QCloseEvent *event) override;
private:
std::shared_ptr<ProjectModel> model;
};
template<typename... VA>
static inline void dbgPrint([[maybe_unused]] char const *fmt,
[[maybe_unused]] VA &&...va)
{
#ifdef TYCHO_DEBUG_ASSERTIONS
qDebug(fmt, std::forward<VA>(va)...);
#endif
}
#define dbgPrintFunc() dbgPrint("%s", __func__)
static inline constexpr std::uint32_t fourCC(std::uint8_t a,
std::uint8_t b,
std::uint8_t c,
std::uint8_t d)
{
return (a << 24) | (b << 16) | (c << 8) | d;
}
@ -167,6 +167,4 @@ extern "C" {
char const *tychoVersion();
}
// }
// EOF