|
From: Tapio V. <aa...@us...> - 2011-02-04 08:58:19
|
Module: editor
Branch: master
Commit: f6954e541e0981582fdd9247dae6a8dba8c8f87b
Author: Tapio Vierros <tap...@gm...>
Date: Fri Feb 4 10:56:48 2011 +0200
Create and use a couple of convenience constructors for Operation.
---
notelabelmanager.cc | 28 +++++++++-------------------
operation.hh | 4 ++--
2 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/notelabelmanager.cc b/notelabelmanager.cc
index 66a850e..98514b4 100644
--- a/notelabelmanager.cc
+++ b/notelabelmanager.cc
@@ -83,12 +83,10 @@ void NoteLabelManager::split(NoteLabel *note, float ratio)
Operation new1("NEW"), new2("NEW");
new1 << id << firstst << n.begin << n.begin + n.length() * ratio << n.note << note->isFloating();
new2 << id+1 << secondst << n.begin + n.length() * ratio << n.end << n.note << note->isFloating();
- Operation del("DEL"); del << id+2;
- Operation combiner("COMBINER"); combiner << 3; // This will combine the previous ones to one undo action
doOperation(new1, Operation::NO_UPDATE);
doOperation(new2, Operation::NO_UPDATE);
- doOperation(del, Operation::NO_UPDATE);
- doOperation(combiner);
+ doOperation(Operation("DEL", id+2), Operation::NO_UPDATE);
+ doOperation(Operation("COMBINER", 3)); // This will combine the previous ones to one undo action
}
void NoteLabelManager::del(NoteLabel *note)
@@ -105,16 +103,14 @@ void NoteLabelManager::del(NoteLabel *note)
}
// Combine to one undo operation
if (i > 1) {
- Operation op("COMBINER"); op << i; doOperation(op);
+ doOperation(Operation("COMBINER", i));
}
// Clear all
m_selectedNotes.clear();
} else {
// Here we have non-selected note up for deletion
- Operation op("DEL");
- op << getNoteLabelId(note);
- doOperation(op);
+ doOperation(Operation("DEL", getNoteLabelId(note)));
}
}
@@ -134,7 +130,7 @@ void NoteLabelManager::move(NoteLabel *note, int value)
// Combine to one undo operation
if (i > 1) {
- Operation op("COMBINER"); op << i; doOperation(op);
+ doOperation(Operation("COMBINER", i));
}
}
@@ -149,20 +145,14 @@ void NoteLabelManager::setType(NoteLabel *note, int index)
void NoteLabelManager::setFloating(NoteLabel *note, bool state)
{
- if (note && note->isFloating() != state) {
- Operation op("FLOATING");
- op << getNoteLabelId(note) << state;
- doOperation(op);
- }
+ if (note && note->isFloating() != state)
+ doOperation(Operation("FLOATING", getNoteLabelId(note), state));
}
void NoteLabelManager::setLineBreak(NoteLabel *note, bool state)
{
- if (note && note->isLineBreak() != state) {
- Operation op("LINEBREAK");
- op << getNoteLabelId(note) << state;
- doOperation(op);
- }
+ if (note && note->isLineBreak() != state)
+ doOperation(Operation("LINEBREAK", getNoteLabelId(note), state));
}
void NoteLabelManager::editLyric(NoteLabel *note) {
diff --git a/operation.hh b/operation.hh
index b00a841..5b9e56f 100644
--- a/operation.hh
+++ b/operation.hh
@@ -12,13 +12,13 @@ struct Operation
Operation() { }
Operation(const QString &opString) { *this << opString; }
+ Operation(const QString &opString, int id) { *this << opString << id; }
+ Operation(const QString &opString, int id, bool state) { *this << opString << id << state; }
// Functions to add parameters to Operation
Operation& operator<<(const QString &str) { m_params.push_back(QVariant(str)); return *this; }
- //Operation& operator<<(char c) { m_params.push_back(QVariant(c)); return *this; }
Operation& operator<<(int i) { m_params.push_back(QVariant(i)); return *this; }
- //Operation& operator<<(unsigned u) { m_params.push_back(QVariant(u)); return *this; }
Operation& operator<<(bool b) { m_params.push_back(QVariant(b)); return *this; }
Operation& operator<<(float f) { m_params.push_back(QVariant(f)); return *this; }
Operation& operator<<(double d) { m_params.push_back(QVariant(d)); return *this; }
|