diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-01-16 11:50:09 (GMT) |
---|---|---|
committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-01-16 11:50:09 (GMT) |
commit | ef013f01cb857626153e305de6177ee878139015 (patch) | |
tree | 0e066b2ac76021e9b823df0312a3a8bc290eddb9 | |
parent | a65f146578f927898321f1bc0dcb224317245931 (diff) | |
download | swift-ef013f01cb857626153e305de6177ee878139015.zip swift-ef013f01cb857626153e305de6177ee878139015.tar.bz2 |
Starting to wire up Highlight Rules dialog.
Change-Id: I81dae3a2c32b38a3affa8b2765d51c6d688e3bae
-rw-r--r-- | Swift/Controllers/HighlightManager.cpp | 41 | ||||
-rw-r--r-- | Swift/Controllers/HighlightManager.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 94 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 9 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.ui | 195 |
5 files changed, 189 insertions, 154 deletions
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp index fa98a6e..46af389 100644 --- a/Swift/Controllers/HighlightManager.cpp +++ b/Swift/Controllers/HighlightManager.cpp @@ -54,16 +54,6 @@ void HighlightManager::handleSettingChanged(const std::string& settingPath) } } -void HighlightManager::loadSettings() -{ - std::string highlightRules = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES); - if (highlightRules == "@") { - rules_ = getDefaultRules(); - } else { - rules_ = rulesFromString(highlightRules); - } -} - std::string HighlightManager::rulesToString() const { std::stringstream stream; @@ -98,13 +88,6 @@ std::vector<HighlightRule> HighlightManager::getDefaultRules() return rules; } -void HighlightManager::storeSettings() -{ - storingSettings_ = true; // don't reload settings while saving - settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES, rulesToString()); - storingSettings_ = false; -} - HighlightRule HighlightManager::getRule(int index) const { assert(index >= 0 && static_cast<size_t>(index) < rules_.size()); @@ -115,21 +98,39 @@ void HighlightManager::setRule(int index, const HighlightRule& rule) { assert(index >= 0 && static_cast<size_t>(index) < rules_.size()); rules_[static_cast<size_t>(index)] = rule; - storeSettings(); + //storeSettings(); } void HighlightManager::insertRule(int index, const HighlightRule& rule) { assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) <= rules_.size()); rules_.insert(rules_.begin() + index, rule); - storeSettings(); + //storeSettings(); } void HighlightManager::removeRule(int index) { assert(index >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(index) < rules_.size()); rules_.erase(rules_.begin() + index); - storeSettings(); + //storeSettings(); +} + +void HighlightManager::storeSettings() +{ + storingSettings_ = true; // don't reload settings while saving + settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES, rulesToString()); + storingSettings_ = false; +} + +void HighlightManager::loadSettings() +{ + std::string highlightRules = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES); + std::vector<HighlightRule> rules = rulesFromString(highlightRules); + if (rules.empty()) { + rules_ = getDefaultRules(); + } else { + rules_ = rules; + } } Highlighter* HighlightManager::createHighlighter() diff --git a/Swift/Controllers/HighlightManager.h b/Swift/Controllers/HighlightManager.h index d195d05..e91d8ce 100644 --- a/Swift/Controllers/HighlightManager.h +++ b/Swift/Controllers/HighlightManager.h @@ -28,6 +28,8 @@ namespace Swift { void setRule(int index, const HighlightRule& rule); void insertRule(int index, const HighlightRule& rule); void removeRule(int index); + void storeSettings(); + void loadSettings(); boost::signal<void (const HighlightAction&)> onHighlight; @@ -40,8 +42,6 @@ namespace Swift { SettingsProvider* settings_; bool storingSettings_; - void storeSettings(); - void loadSettings(); std::vector<HighlightRule> rules_; }; diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 5ac2857..e18ca94 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -12,7 +12,13 @@ #include <cassert> +#include <boost/lexical_cast.hpp> + +#include <Swift/Controllers/HighlightManager.cpp> #include <Swift/QtUI/QtHighlightEditor.h> +#include <Swift/QtUI/QtSwiftUtil.h> + +#include <QTreeWidgetItem> namespace Swift { @@ -41,15 +47,16 @@ QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* pare // //setHighlightManager(NULL); // setup buttons for empty rules list // - //connect(ui_.treeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), SLOT(onCurrentRowChanged(QModelIndex))); -// - //connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked())); - //connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked())); -// - //connect(ui_.moveUpButton, SIGNAL(clicked()), SLOT(onMoveUpButtonClicked())); - //connect(ui_.moveDownButton, SIGNAL(clicked()), SLOT(onMoveDownButtonClicked())); -// - //connect(ui_.closeButton, SIGNAL(clicked()), SLOT(close())); + connect(ui_.listWidget, SIGNAL(currentRowChanged(int)), SLOT(onCurrentRowChanged(int))); + + connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked())); + connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked())); + connect(ui_.moveUpButton, SIGNAL(clicked()), SLOT(onMoveUpButtonClicked())); + connect(ui_.moveDownButton, SIGNAL(clicked()), SLOT(onMoveDownButtonClicked())); + + connect(ui_.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(onApplyButtonClick())); + connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(onCancelButtonClick())); + connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(onOkButtonClick())); setWindowTitle(tr("Highlight Rules")); } @@ -67,8 +74,23 @@ void QtHighlightEditor::show() QWidget::activateWindow(); } +std::string formatNaturalDescription(const HighlightRule& rule) +{ + return "(null)"; +} + void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager) { + highlightManager_ = highlightManager; + + ui_.listWidget->clear(); + + foreach(const HighlightRule &rule, highlightManager_->getRules()) { + QListWidgetItem *item = new QListWidgetItem(); + item->setText(P2QSTRING(formatNaturalDescription(rule))); + ui_.listWidget->addItem(item); + } + //itemModel_->setHighlightManager(highlightManager); //ui_.newButton->setEnabled(highlightManager != NULL); // @@ -78,16 +100,13 @@ void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager) //ui_.moveDownButton->setEnabled(false); } -void QtHighlightEditor::closeEvent(QCloseEvent* event) { - //ui_.ruleWidget->save(); - //event->accept(); -} - void QtHighlightEditor::onNewButtonClicked() { - //int row = getSelectedRow() + 1; - //itemModel_->insertRow(row, QModelIndex()); - //selectRow(row); + int row = getSelectedRow() + 1; + QListWidgetItem *item = new QListWidgetItem(); + item->setText("New rule"); + ui_.listWidget->insertItem(row, item); + selectRow(row); } void QtHighlightEditor::onDeleteButtonClicked() @@ -125,31 +144,50 @@ void QtHighlightEditor::onMoveDownButtonClicked() //} } -void QtHighlightEditor::onCurrentRowChanged(const QModelIndex& index) +void QtHighlightEditor::onCurrentRowChanged(int currentRow) { //ui_.ruleWidget->save(); //ui_.ruleWidget->setActiveIndex(index); // //ui_.ruleWidget->setEnabled(index.isValid()); -// - //ui_.deleteButton->setEnabled(index.isValid()); -// - //ui_.moveUpButton->setEnabled(index.isValid() && index.row() != 0); - //ui_.moveDownButton->setEnabled(index.isValid() && index.row() != itemModel_->rowCount(QModelIndex()) - 1); + + ui_.deleteButton->setEnabled(currentRow != -1); + + ui_.moveUpButton->setEnabled(currentRow != -1 && currentRow != 0); + ui_.moveDownButton->setEnabled(currentRow != -1 && currentRow != (ui_.listWidget->count()-1)); +} + +void QtHighlightEditor::onApplyButtonClick() +{ + close(); +} + +void QtHighlightEditor::onCancelButtonClick() +{ + close(); +} + +void QtHighlightEditor::onOkButtonClick() +{ + close(); } void QtHighlightEditor::selectRow(int row) { - //QModelIndex index = itemModel_->index(row, 0, QModelIndex()); - //ui_.treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + for (int i = 0; i < ui_.listWidget->count(); ++i) { + ui_.listWidget->item(i)->setSelected(i == row); + } } /** Return index of selected row or -1 if none is selected */ int QtHighlightEditor::getSelectedRow() const { - //QModelIndexList rows = ui_.treeView->selectionModel()->selectedRows(); - //return rows.isEmpty() ? -1 : rows[0].row(); - return 0; + for (int i = 0; i < ui_.listWidget->count(); ++i) { + if (ui_.listWidget->item(i)->isSelected()) { + return i; + } + } + return -1; } } diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index c4c008d..4769ed9 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -34,16 +34,19 @@ namespace Swift { void onDeleteButtonClicked(); void onMoveUpButtonClicked(); void onMoveDownButtonClicked(); - void onCurrentRowChanged(const QModelIndex&); + void onCurrentRowChanged(int currentRow); + void onApplyButtonClick(); + void onCancelButtonClick(); + void onOkButtonClick(); private: - virtual void closeEvent(QCloseEvent* event); void selectRow(int row); int getSelectedRow() const; Ui::QtHighlightEditor ui_; - QtSettingsProvider *settings_; + QtSettingsProvider* settings_; + HighlightManager* highlightManager_; }; } diff --git a/Swift/QtUI/QtHighlightEditor.ui b/Swift/QtUI/QtHighlightEditor.ui index 474d384..c132c29 100644 --- a/Swift/QtUI/QtHighlightEditor.ui +++ b/Swift/QtUI/QtHighlightEditor.ui @@ -178,107 +178,6 @@ <enum>Qt::Horizontal</enum> </property> </widget> - <widget class="QWidget" name="layoutWidget"> - <property name="geometry"> - <rect> - <x>10</x> - <y>10</y> - <width>721</width> - <height>191</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>Incoming messages are checked against the following rules. First rule that matches will be executed.</string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QTreeView" name="treeView"> - <property name="rootIsDecorated"> - <bool>false</bool> - </property> - <property name="itemsExpandable"> - <bool>false</bool> - </property> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QPushButton" name="newButton"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="list-add"> - <normaloff/> - </iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="deleteButton"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="list-remove"> - <normaloff/> - </iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="moveUpButton"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="up"> - <normaloff/> - </iconset> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="moveDownButton"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset theme="down"> - <normaloff/> - </iconset> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> <widget class="QGroupBox" name="groupBox_3"> <property name="geometry"> <rect> @@ -539,6 +438,100 @@ p, li { white-space: pre-wrap; } </property> </widget> </widget> + <widget class="QWidget" name=""> + <property name="geometry"> + <rect> + <x>10</x> + <y>12</y> + <width>721</width> + <height>191</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Incoming messages are checked against the following rules. First rule that matches will be executed.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QListWidget" name="listWidget"/> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QPushButton" name="newButton"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="list-add"> + <normaloff/> + </iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="deleteButton"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="list-remove"> + <normaloff/> + </iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="moveUpButton"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="up"> + <normaloff/> + </iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="moveDownButton"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset theme="down"> + <normaloff/> + </iconset> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> </widget> <customwidgets> <customwidget> |