tycho: add selection/deselection

master
an 2019-07-03 19:26:28 -04:00
parent 790dc9f840
commit 16b3e03cfa
4 changed files with 51 additions and 3 deletions

View File

@ -40,6 +40,18 @@
"name": "index",
"type": "quint16"
}]
},
"deselect": {
"return": "void",
"mut": true
},
"select": {
"return": "void",
"mut": true,
"arguments": [{
"name": "index",
"type": "quint16"
}]
}
},
"properties": {

View File

@ -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) {

View File

@ -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;

View File

@ -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<u16>,
}
// EOF