diff options
-rw-r--r-- | Swift/Controllers/HighlightManager.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/HighlightManager.h | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 22 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 3 |
4 files changed, 35 insertions, 6 deletions
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp index eac562f..ca0567e 100644 --- a/Swift/Controllers/HighlightManager.cpp +++ b/Swift/Controllers/HighlightManager.cpp @@ -105,2 +105,10 @@ void HighlightManager::removeRule(int index) +void HighlightManager::swapRules(const size_t first, const size_t second) { + assert(first < rules_->getSize()); + assert(second < rules_->getSize()); + const HighlightRule swap = rules_->getRule(first); + rules_->setRule(first, rules_->getRule(second)); + rules_->setRule(second, swap); +} + void HighlightManager::storeSettings() diff --git a/Swift/Controllers/HighlightManager.h b/Swift/Controllers/HighlightManager.h index 3da72eb..07a3fe3 100644 --- a/Swift/Controllers/HighlightManager.h +++ b/Swift/Controllers/HighlightManager.h @@ -33,6 +33,9 @@ namespace Swift { const HighlightRule& getRule(const size_t index) const { return list_[index]; } - void addRule(const HighlightRule &rule) { list_.push_back(rule); } - void combineRules(const HighlightRulesList &rhs) { + void addRule(const HighlightRule& rule) { list_.push_back(rule); } + void combineRules(const HighlightRulesList& rhs) { list_.insert(list_.end(), rhs.list_.begin(), rhs.list_.end()); } + void setRule(const size_t index, const HighlightRule& rule) { + list_[index] = rule; + } private: @@ -51,2 +54,3 @@ namespace Swift { void removeRule(int index); + void swapRules(const size_t first, const size_t second); void storeSettings(); diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 8488d7d..134155c 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -77,5 +77,5 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare - /* if these are not needed, then they should be removed */ - ui_.moveUpButton->setVisible(false); - ui_.moveDownButton->setVisible(false); + /* allowing reordering items */ + connect(ui_.moveUpButton, SIGNAL(clicked()), this, SLOT(onUpButtonClicked())); + connect(ui_.moveDownButton, SIGNAL(clicked()), this, SLOT(onDownButtonClicked())); @@ -197,2 +197,18 @@ void QtHighlightEditor::onDeleteButtonClicked() +void QtHighlightEditor::onUpButtonClicked() { + const size_t moveFrom = ui_.listWidget->currentRow(); + const size_t moveTo = moveFrom - 1; + highlightManager_->swapRules(moveFrom, moveTo); + populateList(); + selectRow(moveTo); +} + +void QtHighlightEditor::onDownButtonClicked() { + const size_t moveFrom = ui_.listWidget->currentRow(); + const size_t moveTo = moveFrom + 1; + highlightManager_->swapRules(moveFrom, moveTo); + populateList(); + selectRow(moveTo); +} + void QtHighlightEditor::onCurrentRowChanged(int currentRow) diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index c7db464..e0595ad 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -42,2 +42,4 @@ namespace Swift { void onDeleteButtonClicked(); + void onUpButtonClicked(); + void onDownButtonClicked(); void onCurrentRowChanged(int currentRow); @@ -55,3 +57,2 @@ namespace Swift { void populateList(); - void updateChatPreview(); void selectRow(int row); |