From fa7d78521253a78e948829c7b8bfd7c2999ad27a Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Wed, 3 Jul 2019 20:51:38 -0400 Subject: [PATCH] tycho: rename classes for consistency --- tycho/bindings.json | 35 +++++++--------- tycho/cc/mapmodel.cc | 36 ++++++++-------- tycho/cc/mapview.cc | 4 +- tycho/cc/project.cc | 4 +- tycho/cc/tycho.h | 52 ++++++++++-------------- tycho/source/gui.rs | 4 +- tycho/source/gui/{map.rs => mapmodel.rs} | 20 ++++----- 7 files changed, 69 insertions(+), 86 deletions(-) rename tycho/source/gui/{map.rs => mapmodel.rs} (84%) diff --git a/tycho/bindings.json b/tycho/bindings.json index c0294f5..0280840 100644 --- a/tycho/bindings.json +++ b/tycho/bindings.json @@ -6,16 +6,15 @@ "implementationModule": "gui" }, "objects": { - "AbstractMapModel": { + "IMapModel": { "type": "List", "functions": { "open": { "return": "bool", "mut": true, - "arguments": [{ - "name": "path", - "type": "QString" - }] + "arguments": [ + {"name": "path", "type": "QString"} + ] }, "save": { "return": "bool", @@ -24,10 +23,9 @@ "saveAs": { "return": "bool", "mut": false, - "arguments": [{ - "name": "path", - "type": "QString" - }] + "arguments": [ + {"name": "path", "type": "QString"} + ] }, "isDirty": { "return": "bool", @@ -36,10 +34,9 @@ "propIcon": { "return": "QString", "mut": false, - "arguments": [{ - "name": "index", - "type": "quint16" - }] + "arguments": [ + {"name": "index", "type": "quint16"} + ] }, "deselect": { "return": "void", @@ -48,19 +45,15 @@ "select": { "return": "void", "mut": true, - "arguments": [{ - "name": "index", - "type": "quint16" - }] + "arguments": [ + {"name": "index", "type": "quint16"} + ] } }, "properties": { }, "itemProperties": { - "propIndex": { - "type": "quint64", - "roles": [["display"]] - } + "propIndex": {"type": "quint64", "roles": [["display"]]} } } } diff --git a/tycho/cc/mapmodel.cc b/tycho/cc/mapmodel.cc index 0054a3b..0ef3596 100644 --- a/tycho/cc/mapmodel.cc +++ b/tycho/cc/mapmodel.cc @@ -1,54 +1,54 @@ #include "tycho.h" -MapModel::MapModel(Project *parent) : - AbstractMapModel(static_cast(parent)), - ProjectModel() +CMapModel::CMapModel(Project *parent) : + IMapModel(static_cast(parent)), + IProjectModel() { dbgPrintFunc(); } -MapModel::~MapModel() +CMapModel::~CMapModel() { dbgPrintFunc(); } -bool MapModel::isDirty() const +bool CMapModel::isDirty() const { - return AbstractMapModel::isDirty(); + return IMapModel::isDirty(); } -bool MapModel::open(QString const &path) +bool CMapModel::open(QString const &path) { - return AbstractMapModel::open(path); + return IMapModel::open(path); } -bool MapModel::save() const +bool CMapModel::save() const { - return AbstractMapModel::save(); + return IMapModel::save(); } -bool MapModel::saveAs(QString const &path) const +bool CMapModel::saveAs(QString const &path) const { - return AbstractMapModel::saveAs(path); + return IMapModel::saveAs(path); } -void MapModel::deselect() +void CMapModel::deselect() { - AbstractMapModel::deselect(); + IMapModel::deselect(); emit deselected(); } -void MapModel::select(QModelIndex const &index) +void CMapModel::select(QModelIndex const &index) { auto idx = index.internalId(); - AbstractMapModel::select(idx); + IMapModel::select(idx); emit selected(idx); } -QVariant MapModel::data(const QModelIndex &index, int role) const +QVariant CMapModel::data(const QModelIndex &index, int role) const { switch(role) { case Qt::DecorationRole: { @@ -58,7 +58,7 @@ QVariant MapModel::data(const QModelIndex &index, int role) const return QVariant::fromValue(icon); } default: - return AbstractMapModel::data(index, role); + return IMapModel::data(index, role); } } diff --git a/tycho/cc/mapview.cc b/tycho/cc/mapview.cc index 18d2905..051df96 100644 --- a/tycho/cc/mapview.cc +++ b/tycho/cc/mapview.cc @@ -1,6 +1,6 @@ #include "tycho.h" -MapView::MapView(Project *parent) : +CMapView::CMapView(Project *parent) : QWidget(static_cast(parent)), mapModel(parent->getMapModel()) { @@ -9,7 +9,7 @@ MapView::MapView(Project *parent) : dbgPrintFunc(); } -MapView::~MapView() +CMapView::~CMapView() { dbgPrintFunc(); } diff --git a/tycho/cc/project.cc b/tycho/cc/project.cc index 91c6d66..adb470f 100644 --- a/tycho/cc/project.cc +++ b/tycho/cc/project.cc @@ -1,7 +1,7 @@ #include "tycho.h" static -ProjectModel *makeModel(Project *proj) +IProjectModel *makeModel(Project *proj) { switch(proj->getType()) { case ProjectType::Map: return new MapModel(proj); @@ -9,7 +9,7 @@ ProjectModel *makeModel(Project *proj) } static -ProjectView *makeView(Project *proj) +IProjectView *makeView(Project *proj) { switch(proj->getType()) { case ProjectType::Map: return new MapView(proj); diff --git a/tycho/cc/tycho.h b/tycho/cc/tycho.h index 7c18f15..630ec80 100644 --- a/tycho/cc/tycho.h +++ b/tycho/cc/tycho.h @@ -25,14 +25,6 @@ #include "../ui/ui_menu.h" #include "../ui/ui_project.h" -// Types ---------------------------------------------------------------------| - -class MapModel; -class MapProps; -class MapView; -class Menu; -class Project; - enum class ProjectType { Map, @@ -40,12 +32,10 @@ enum class ProjectType using byte = std::uint8_t; -// Interfaces ----------------------------------------------------------------| - -class ProjectModel +class IProjectModel { public: - virtual ~ProjectModel() {} + virtual ~IProjectModel() {} virtual bool isDirty() const = 0; virtual bool open(QString const &path) = 0; @@ -53,21 +43,20 @@ public: virtual bool saveAs(QString const &path) const = 0; }; -class ProjectView +class IProjectView { public: - virtual ~ProjectView() {} + virtual ~IProjectView() {} }; -// Implementations -----------------------------------------------------------| - -class MapModel final : public AbstractMapModel, public ProjectModel +class CMapModel final : public IMapModel, + public IProjectModel { Q_OBJECT public: - explicit MapModel(Project *parent); - ~MapModel() override; + explicit CMapModel(Project *parent); + ~CMapModel() override; bool isDirty() const override; bool open(QString const &path) override; @@ -87,21 +76,22 @@ private: const override; }; -class MapView final : public QWidget, public ProjectView, private Ui::MapView +class CMapView final : public QWidget, + public IProjectView, + private Ui::CMapView { Q_OBJECT public: - explicit MapView(Project *parent); - ~MapView(); + explicit CMapView(Project *parent); + ~CMapView(); private: - MapModel *const mapModel; + CMapModel *const m_mapModel; }; -// UI ------------------------------------------------------------------------| - -class MapProps final : public QDialog, private Ui::MapProps +class MapProps final : public QDialog, + private Ui::MapProps { Q_OBJECT @@ -112,10 +102,11 @@ public: void accept() override; private: - MapModel *const mapModel; + CMapModel *const m_mapModel; }; -class Menu final : public QMainWindow, private Ui::Menu +class Menu final : public QMainWindow, + private Ui::Menu { Q_OBJECT @@ -142,7 +133,8 @@ private: void addProject(Project *proj); }; -class Project final : public QMdiSubWindow, private Ui::Project +class Project final : public QMdiSubWindow, + private Ui::Project { Q_OBJECT @@ -165,8 +157,6 @@ private: ProjectView *const view; }; -// Functions -----------------------------------------------------------------| - #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-security" diff --git a/tycho/source/gui.rs b/tycho/source/gui.rs index d616258..2c5078c 100644 --- a/tycho/source/gui.rs +++ b/tycho/source/gui.rs @@ -1,8 +1,8 @@ //! GUI implementation. -mod map; +mod mapmodel; mod qobj; -pub use self::map::AbstractMapModel; +pub use self::mapmodel::IMapModel; // EOF diff --git a/tycho/source/gui/map.rs b/tycho/source/gui/mapmodel.rs similarity index 84% rename from tycho/source/gui/map.rs rename to tycho/source/gui/mapmodel.rs index 6142484..8e1fc51 100644 --- a/tycho/source/gui/map.rs +++ b/tycho/source/gui/mapmodel.rs @@ -4,7 +4,7 @@ use super::qobj::*; use maraiah::{backtrace, err::*, map::{self, data::*}}; use crate::cc; -impl AbstractMapModel +impl IMapModel { pub fn open_map(path: String) -> ResultS { @@ -29,20 +29,20 @@ impl AbstractMapModel */ } -impl AbstractMapModelTrait for AbstractMapModel +impl IMapModelTrait for IMapModel { - /// Returns a new `AbstractMapModel` instance. - fn new(emit: AbstractMapModelEmitter, _: AbstractMapModelList) -> Self + /// Returns a new `IMapModel` instance. + fn new(emit: IMapModelEmitter, _: IMapModelList) -> Self { if cfg!(debug_assertions) { - eprintln!("new AbstractMapModel"); + eprintln!("new IMapModel"); } Self{emit, map: EntryDataMap::default(), selected: None} } /// Returns the emitter of `self`. - fn emit(&mut self) -> &mut AbstractMapModelEmitter {&mut self.emit} + fn emit(&mut self) -> &mut IMapModelEmitter {&mut self.emit} fn row_count(&self) -> usize {self.map.len()} @@ -113,18 +113,18 @@ impl AbstractMapModelTrait for AbstractMapModel } } -impl Drop for AbstractMapModel +impl Drop for IMapModel { fn drop(&mut self) { if cfg!(debug_assertions) { - eprintln!("drop AbstractMapModel"); + eprintln!("drop IMapModel"); } } } -pub struct AbstractMapModel { - emit: AbstractMapModelEmitter, +pub struct IMapModel { + emit: IMapModelEmitter, map: EntryDataMap, selected: Option, }