From f92d78241228f6a9c0b649c8addcc7ae82071167 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 13 May 2018 09:35:53 +0200 Subject: Added list of Instrument to Project including serialiser/deserialiser. --- src/project.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'src/project.cc') diff --git a/src/project.cc b/src/project.cc index 33c3054..ba7f279 100644 --- a/src/project.cc +++ b/src/project.cc @@ -28,6 +28,35 @@ #include +Instrument::Instrument(Project& project, int id) + : id(id) + , project(project) +{ +} + +int Instrument::getId() const +{ + return id; +} + +QString Instrument::getInstrumentName() const +{ + return instrument_name; +} + +void Instrument::setInstrumentName(const QString& instrument_name) +{ + if(this->instrument_name == instrument_name) + { + return; + } + + { + Project::RAIIBulkUpdate bulkUpdate(project); + this->instrument_name = instrument_name; + } +} + void Project::bulkUpdateBegin() { ++update_count; @@ -90,9 +119,50 @@ void Project::setRawFileRoot(const QString& raw_file_root) } } +Instrument& Project::getInstrument(int id) +{ + for(auto& instrument : instruments) + { + if(instrument.getId() == id) + { + return instrument; + } + } + + Q_ASSERT(false); // No such instrument id. +} + +int Project::createInstrument() +{ + RAIIBulkUpdate bulkUpdate(*this); + + instruments.emplace_back(Instrument(*this, next_id)); + ++next_id; + + return instruments.back().getId(); +} + +void Project::deleteInstrument(int id) +{ + RAIIBulkUpdate bulkUpdate(*this); + + for(auto it = instruments.begin(); it != instruments.end(); ++it) + { + if((*it).getId() == id) + { + instruments.erase(it); + return; + } + } + + Q_ASSERT(false); // No such instrument id. +} + void Project::reset() { RAIIBulkUpdate bulkUpdate(*this); setRawFileRoot(""); setProjectName(""); + instruments.clear(); + next_id = 0; } -- cgit v1.2.3