diff --git a/tycho/bindings.json b/tycho/bindings.json index 3c3b1a3..c0294f5 100644 --- a/tycho/bindings.json +++ b/tycho/bindings.json @@ -40,6 +40,18 @@ "name": "index", "type": "quint16" }] + }, + "deselect": { + "return": "void", + "mut": true + }, + "select": { + "return": "void", + "mut": true, + "arguments": [{ + "name": "index", + "type": "quint16" + }] } }, "properties": { diff --git a/tycho/cc/mapmodel.cc b/tycho/cc/mapmodel.cc index 0fc6942..0054a3b 100644 --- a/tycho/cc/mapmodel.cc +++ b/tycho/cc/mapmodel.cc @@ -32,6 +32,22 @@ bool MapModel::saveAs(QString const &path) const return AbstractMapModel::saveAs(path); } +void MapModel::deselect() +{ + AbstractMapModel::deselect(); + + emit deselected(); +} + +void MapModel::select(QModelIndex const &index) +{ + auto idx = index.internalId(); + + AbstractMapModel::select(idx); + + emit selected(idx); +} + QVariant MapModel::data(const QModelIndex &index, int role) const { switch(role) { diff --git a/tycho/cc/tycho.h b/tycho/cc/tycho.h index 1013f91..daae988 100644 --- a/tycho/cc/tycho.h +++ b/tycho/cc/tycho.h @@ -72,6 +72,14 @@ public: bool save() const override; bool saveAs(QString const &path) const override; +public slots: + void deselect(); + void select(QModelIndex const &index); + +signals: + void deselected(); + void selected(std::uint16_t index); + private: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; diff --git a/tycho/source/gui/map.rs b/tycho/source/gui/map.rs index a283615..6142484 100644 --- a/tycho/source/gui/map.rs +++ b/tycho/source/gui/map.rs @@ -38,7 +38,7 @@ impl AbstractMapModelTrait for AbstractMapModel eprintln!("new AbstractMapModel"); } - Self{emit, map: EntryDataMap::default()} + Self{emit, map: EntryDataMap::default(), selected: None} } /// Returns the emitter of `self`. @@ -100,6 +100,17 @@ impl AbstractMapModelTrait for AbstractMapModel /// Returns `true` if the file has been modified from its original state. fn is_dirty(&self) -> bool {false} + + fn deselect(&mut self) {self.selected = None;} + + fn select(&mut self, index: u16) + { + if cfg!(debug_assertions) { + eprintln!("selecting map {}", index); + } + + self.selected = Some(index); + } } impl Drop for AbstractMapModel @@ -113,8 +124,9 @@ impl Drop for AbstractMapModel } pub struct AbstractMapModel { - emit: AbstractMapModelEmitter, - map: EntryDataMap, + emit: AbstractMapModelEmitter, + map: EntryDataMap, + selected: Option, } // EOF