aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@theqtcompany.com>2015-11-16 16:45:05 +0100
committerAlessandro Portale <alessandro.portale@theqtcompany.com>2015-11-18 17:12:53 +0000
commit19eb9e4f06408877351bf28c5332725c76772b7e (patch)
tree570a2b905fba7a50d54d5cb954f7a37caefe586d
parent04fda7d0f5b8f9d868e63e8905508185aeef32cf (diff)
Todo: Store icons in the settings via index instead of strings
This allows us to use something else than a string in order to reference icons. For an upcoming patch this will be necessary. Since this patch introduces a settings structure change, a migration feature from the old "Keyword\iconResource" string to the new "Keyword \iconType" int is implemented. Change-Id: Ia5695418fb135510ed549cf9a7cb59aab5389f31 Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
-rw-r--r--src/plugins/todo/keyword.cpp5
-rw-r--r--src/plugins/todo/keyword.h4
-rw-r--r--src/plugins/todo/keyworddialog.cpp28
-rw-r--r--src/plugins/todo/keyworddialog.h3
-rw-r--r--src/plugins/todo/lineparser.cpp2
-rw-r--r--src/plugins/todo/optionsdialog.cpp12
-rw-r--r--src/plugins/todo/settings.cpp32
-rw-r--r--src/plugins/todo/todo.pro6
-rw-r--r--src/plugins/todo/todo.qbs2
-rw-r--r--src/plugins/todo/todoicons.cpp63
-rw-r--r--src/plugins/todo/todoicons.h51
-rw-r--r--src/plugins/todo/todoitem.h3
-rw-r--r--src/plugins/todo/todoitemsmodel.cpp2
-rw-r--r--src/plugins/todo/todooutputpane.cpp3
14 files changed, 176 insertions, 40 deletions
diff --git a/src/plugins/todo/keyword.cpp b/src/plugins/todo/keyword.cpp
index fbae123a28..22ccd27301 100644
--- a/src/plugins/todo/keyword.cpp
+++ b/src/plugins/todo/keyword.cpp
@@ -31,6 +31,9 @@
#include "keyword.h"
+#include <coreplugin/coreconstants.h>
+#include <utils/themehelper.h>
+
namespace Todo {
namespace Internal {
@@ -41,7 +44,7 @@ Keyword::Keyword() : color(Qt::white)
bool Keyword::equals(const Keyword &other) const
{
return (this->name == other.name)
- && (this->iconResource == other.iconResource)
+ && (this->iconType == other.iconType)
&& (this->color == other.color);
}
diff --git a/src/plugins/todo/keyword.h b/src/plugins/todo/keyword.h
index 1ba8c5be1b..980e22e8ca 100644
--- a/src/plugins/todo/keyword.h
+++ b/src/plugins/todo/keyword.h
@@ -32,6 +32,8 @@
#ifndef KEYWORD_H
#define KEYWORD_H
+#include "todoicons.h"
+
#include <QColor>
#include <QString>
#include <QList>
@@ -46,7 +48,7 @@ public:
Keyword();
QString name;
- QString iconResource;
+ IconType iconType;
QColor color;
bool equals(const Keyword &other) const;
};
diff --git a/src/plugins/todo/keyworddialog.cpp b/src/plugins/todo/keyworddialog.cpp
index eb9ceeb860..9fb9f2022a 100644
--- a/src/plugins/todo/keyworddialog.cpp
+++ b/src/plugins/todo/keyworddialog.cpp
@@ -50,7 +50,7 @@ KeywordDialog::KeywordDialog(const Keyword &keyword, const QSet<QString> &alread
m_alreadyUsedKeywordNames(alreadyUsedKeywordNames)
{
ui->setupUi(this);
- setupListWidget(keyword.iconResource);
+ setupListWidget(keyword.iconType);
setupColorWidgets(keyword.color);
ui->keywordNameEdit->setText(keyword.name);
ui->errorLabel->hide();
@@ -68,7 +68,7 @@ Keyword KeywordDialog::keyword()
{
Keyword result;
result.name = keywordName();
- result.iconResource = ui->listWidget->currentItem()->data(Qt::UserRole).toString();
+ result.iconType = static_cast<IconType>(ui->listWidget->currentItem()->data(Qt::UserRole).toInt());
result.color = ui->colorEdit->text();
return result;
@@ -85,31 +85,27 @@ void KeywordDialog::acceptButtonClicked()
accept();
}
-void KeywordDialog::setupListWidget(const QString &selectedIcon)
+void KeywordDialog::setupListWidget(IconType selectedIcon)
{
ui->listWidget->setViewMode(QListWidget::IconMode);
ui->listWidget->setDragEnabled(false);
- const QString infoIconName = QLatin1String(Core::Constants::ICON_INFO);
- QListWidgetItem *item = new QListWidgetItem(Utils::ThemeHelper::themedIcon(infoIconName),
- QLatin1String("information"));
- item->setData(Qt::UserRole, infoIconName);
+
+ QListWidgetItem *item =
+ new QListWidgetItem(icon(IconType::Info), QLatin1String("information"));
+ item->setData(Qt::UserRole, static_cast<int>(IconType::Info));
ui->listWidget->addItem(item);
- const QString warningIconName = QLatin1String(Core::Constants::ICON_WARNING);
- item = new QListWidgetItem(Utils::ThemeHelper::themedIcon(warningIconName),
- QLatin1String("warning"));
- item->setData(Qt::UserRole, warningIconName);
+ item = new QListWidgetItem(icon(IconType::Warning), QLatin1String("warning"));
+ item->setData(Qt::UserRole, static_cast<int>(IconType::Warning));
ui->listWidget->addItem(item);
- const QString errorIconName = QLatin1String(Core::Constants::ICON_ERROR);
- item = new QListWidgetItem(Utils::ThemeHelper::themedIcon(errorIconName),
- QLatin1String("error"));
- item->setData(Qt::UserRole, errorIconName);
+ item = new QListWidgetItem(icon(IconType::Error), QLatin1String("error"));
+ item->setData(Qt::UserRole, static_cast<int>(IconType::Error));
ui->listWidget->addItem(item);
for (int i = 0; i < ui->listWidget->count(); ++i) {
item = ui->listWidget->item(i);
- if (item->data(Qt::UserRole).toString() == selectedIcon) {
+ if (static_cast<IconType>(item->data(Qt::UserRole).toInt()) == selectedIcon) {
ui->listWidget->setCurrentItem(item);
break;
}
diff --git a/src/plugins/todo/keyworddialog.h b/src/plugins/todo/keyworddialog.h
index a22fbd3421..c5e676eb79 100644
--- a/src/plugins/todo/keyworddialog.h
+++ b/src/plugins/todo/keyworddialog.h
@@ -41,6 +41,7 @@ namespace Internal {
namespace Ui { class KeywordDialog; }
class Keyword;
+enum class IconType;
class KeywordDialog : public QDialog
{
@@ -57,7 +58,7 @@ private slots:
void acceptButtonClicked();
private:
- void setupListWidget(const QString &selectedIcon);
+ void setupListWidget(IconType selectedIcon);
void setupColorWidgets(const QColor &color);
bool canAccept();
bool isKeywordNameCorrect();
diff --git a/src/plugins/todo/lineparser.cpp b/src/plugins/todo/lineparser.cpp
index fefc7338a8..e39276e39a 100644
--- a/src/plugins/todo/lineparser.cpp
+++ b/src/plugins/todo/lineparser.cpp
@@ -175,7 +175,7 @@ QList<TodoItem> LineParser::todoItemsFromKeywordEntries(const QList<KeywordEntry
TodoItem item;
item.text = m_keywords.at(entry.keywordIndex).name + entry.text;
item.color = m_keywords.at(entry.keywordIndex).color;
- item.iconResource = m_keywords.at(entry.keywordIndex).iconResource;
+ item.iconType = m_keywords.at(entry.keywordIndex).iconType;
todoItems << item;
}
diff --git a/src/plugins/todo/optionsdialog.cpp b/src/plugins/todo/optionsdialog.cpp
index 9c0e439e43..481f236003 100644
--- a/src/plugins/todo/optionsdialog.cpp
+++ b/src/plugins/todo/optionsdialog.cpp
@@ -72,8 +72,8 @@ void OptionsDialog::setSettings(const Settings &settings)
void OptionsDialog::addToKeywordsList(const Keyword &keyword)
{
QListWidgetItem *item = new QListWidgetItem(
- Utils::ThemeHelper::themedIcon(keyword.iconResource), keyword.name);
- item->setData(Qt::UserRole, keyword.iconResource);
+ icon(keyword.iconType), keyword.name);
+ item->setData(Qt::UserRole, static_cast<int>(keyword.iconType));
item->setBackgroundColor(keyword.color);
ui->keywordsList->addItem(item);
}
@@ -114,7 +114,7 @@ void OptionsDialog::editKeyword(QListWidgetItem *item)
{
Keyword keyword;
keyword.name = item->text();
- keyword.iconResource = item->data(Qt::UserRole).toString();
+ keyword.iconType = static_cast<IconType>(item->data(Qt::UserRole).toInt());
keyword.color = item->backgroundColor();
QSet<QString> keywordNamesButThis = keywordNames();
@@ -123,9 +123,9 @@ void OptionsDialog::editKeyword(QListWidgetItem *item)
KeywordDialog *keywordDialog = new KeywordDialog(keyword, keywordNamesButThis, this);
if (keywordDialog->exec() == QDialog::Accepted) {
keyword = keywordDialog->keyword();
- item->setIcon(Utils::ThemeHelper::themedIcon(keyword.iconResource));
+ item->setIcon(icon(keyword.iconType));
item->setText(keyword.name);
- item->setData(Qt::UserRole, keyword.iconResource);
+ item->setData(Qt::UserRole, static_cast<int>(keyword.iconType));
item->setBackgroundColor(keyword.color);
}
}
@@ -177,7 +177,7 @@ Settings OptionsDialog::settingsFromUi()
Keyword keyword;
keyword.name = item->text();
- keyword.iconResource = item->data(Qt::UserRole).toString();
+ keyword.iconType = static_cast<IconType>(item->data(Qt::UserRole).toInt());
keyword.color = item->backgroundColor();
settings.keywords << keyword;
diff --git a/src/plugins/todo/settings.cpp b/src/plugins/todo/settings.cpp
index a6aaee6cb8..8ecaa00bf4 100644
--- a/src/plugins/todo/settings.cpp
+++ b/src/plugins/todo/settings.cpp
@@ -48,12 +48,12 @@ void Settings::save(QSettings *settings) const
if (const int size = keywords.size()) {
const QString nameKey = QLatin1String("name");
const QString colorKey = QLatin1String("color");
- const QString iconResourceKey = QLatin1String("iconResource");
+ const QString iconTypeKey = QLatin1String("iconType");
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
settings->setValue(nameKey, keywords.at(i).name);
settings->setValue(colorKey, keywords.at(i).color);
- settings->setValue(iconResourceKey, keywords.at(i).iconResource);
+ settings->setValue(iconTypeKey, static_cast<int>(keywords.at(i).iconType));
}
}
settings->endArray();
@@ -62,6 +62,17 @@ void Settings::save(QSettings *settings) const
settings->sync();
}
+// Compatibility helper for transition from 3.6 to higher
+// TODO: remove in 4.0
+IconType resourceToTypeKey(const QString &key)
+{
+ if (key.contains(QLatin1String("error")))
+ return IconType::Error;
+ else if (key.contains(QLatin1String("warning")))
+ return IconType::Warning;
+ return IconType::Info;
+}
+
void Settings::load(QSettings *settings)
{
setDefault();
@@ -76,13 +87,16 @@ void Settings::load(QSettings *settings)
if (keywordsSize > 0) {
const QString nameKey = QLatin1String("name");
const QString colorKey = QLatin1String("color");
- const QString iconResourceKey = QLatin1String("iconResource");
+ const QString iconResourceKey = QLatin1String("iconResource"); // Legacy since 3.7 TODO: remove in 4.0
+ const QString iconTypeKey = QLatin1String("iconType");
for (int i = 0; i < keywordsSize; ++i) {
settings->setArrayIndex(i);
Keyword keyword;
keyword.name = settings->value(nameKey).toString();
keyword.color = settings->value(colorKey).value<QColor>();
- keyword.iconResource = settings->value(iconResourceKey).toString();
+ keyword.iconType = settings->contains(iconTypeKey) ?
+ static_cast<IconType>(settings->value(iconTypeKey).toInt())
+ : resourceToTypeKey(settings->value(iconResourceKey).toString());
newKeywords << keyword;
}
keywords = newKeywords;
@@ -101,27 +115,27 @@ void Settings::setDefault()
Keyword keyword;
keyword.name = QLatin1String("TODO");
- keyword.iconResource = QLatin1String(Core::Constants::ICON_WARNING);
+ keyword.iconType = IconType::Warning;
keyword.color = QColor(QLatin1String(Constants::COLOR_TODO_BG));
keywords.append(keyword);
keyword.name = QLatin1String("NOTE");
- keyword.iconResource = QLatin1String(Core::Constants::ICON_INFO);
+ keyword.iconType = IconType::Info;
keyword.color = QColor(QLatin1String(Constants::COLOR_NOTE_BG));
keywords.append(keyword);
keyword.name = QLatin1String("FIXME");
- keyword.iconResource = QLatin1String(Core::Constants::ICON_ERROR);
+ keyword.iconType = IconType::Error;
keyword.color = QColor(QLatin1String(Constants::COLOR_FIXME_BG));
keywords.append(keyword);
keyword.name = QLatin1String("BUG");
- keyword.iconResource = QLatin1String(Core::Constants::ICON_ERROR);
+ keyword.iconType = IconType::Error;
keyword.color = QColor(QLatin1String(Constants::COLOR_BUG_BG));
keywords.append(keyword);
keyword.name = QLatin1String("WARNING");
- keyword.iconResource = QLatin1String(Core::Constants::ICON_WARNING);
+ keyword.iconType = IconType::Warning;
keyword.color = QColor(QLatin1String(Constants::COLOR_WARNING_BG));
keywords.append(keyword);
}
diff --git a/src/plugins/todo/todo.pro b/src/plugins/todo/todo.pro
index a485a50a8a..7271425959 100644
--- a/src/plugins/todo/todo.pro
+++ b/src/plugins/todo/todo.pro
@@ -17,7 +17,8 @@ HEADERS += todoplugin.h \
lineparser.h \
todooutputtreeview.h \
todooutputtreeviewdelegate.h \
- todoprojectsettingswidget.h
+ todoprojectsettingswidget.h \
+ todoicons.h
SOURCES += todoplugin.cpp \
keyword.cpp \
@@ -34,7 +35,8 @@ SOURCES += todoplugin.cpp \
lineparser.cpp \
todooutputtreeview.cpp \
todooutputtreeviewdelegate.cpp \
- todoprojectsettingswidget.cpp
+ todoprojectsettingswidget.cpp \
+ todoicons.cpp
RESOURCES += \
todoplugin.qrc
diff --git a/src/plugins/todo/todo.qbs b/src/plugins/todo/todo.qbs
index e72b2862e6..49d6d7f33e 100644
--- a/src/plugins/todo/todo.qbs
+++ b/src/plugins/todo/todo.qbs
@@ -35,6 +35,8 @@ QtcPlugin {
"qmljstodoitemsscanner.h",
"settings.cpp",
"settings.h",
+ "todoicons.h",
+ "todoicons.cpp",
"todoitem.h",
"todoitemsmodel.cpp",
"todoitemsmodel.h",
diff --git a/src/plugins/todo/todoicons.cpp b/src/plugins/todo/todoicons.cpp
new file mode 100644
index 0000000000..0ae9fd95ad
--- /dev/null
+++ b/src/plugins/todo/todoicons.cpp
@@ -0,0 +1,63 @@
+/**************************************************************************
+**
+** Copyright (C) 2015 Dmitry Savchenko
+** Copyright (C) 2015 Vasiliy Sorokin
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include <coreplugin/coreconstants.h>
+#include <utils/themehelper.h>
+
+#include "todoicons.h"
+
+namespace Todo {
+namespace Internal {
+
+QIcon icon(IconType type)
+{
+ switch (type) {
+ case IconType::Info: {
+ const static QIcon icon = Utils::ThemeHelper::themedIcon(
+ QLatin1String(Core::Constants::ICON_INFO));
+ return icon;
+ }
+ case IconType::Warning: {
+ const static QIcon icon = Utils::ThemeHelper::themedIcon(
+ QLatin1String(Core::Constants::ICON_WARNING));
+ return icon;
+ }
+ default:
+ case IconType::Error: {
+ const static QIcon icon = Utils::ThemeHelper::themedIcon(
+ QLatin1String(Core::Constants::ICON_ERROR));
+ return icon;
+ }
+ }
+}
+
+} // namespace Internal
+} // namespace Todo
diff --git a/src/plugins/todo/todoicons.h b/src/plugins/todo/todoicons.h
new file mode 100644
index 0000000000..a3b5dba872
--- /dev/null
+++ b/src/plugins/todo/todoicons.h
@@ -0,0 +1,51 @@
+/**************************************************************************
+**
+** Copyright (C) 2015 Dmitry Savchenko
+** Copyright (C) 2015 Vasiliy Sorokin
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef TODOICONS_H
+#define TODOICONS_H
+
+#include <QIcon>
+
+namespace Todo {
+namespace Internal {
+
+enum class IconType {
+ Info,
+ Error,
+ Warning
+};
+
+QIcon icon(IconType type);
+
+} // namespace Internal
+} // namespace Todo
+
+#endif // TODOICONS_H
diff --git a/src/plugins/todo/todoitem.h b/src/plugins/todo/todoitem.h
index 1e95f35904..ae01485384 100644
--- a/src/plugins/todo/todoitem.h
+++ b/src/plugins/todo/todoitem.h
@@ -33,6 +33,7 @@
#define TODOITEM_H
#include "constants.h"
+#include "todoicons.h"
#include <QMetaType>
#include <QString>
@@ -49,7 +50,7 @@ public:
QString text;
QString file;
int line;
- QString iconResource;
+ IconType iconType;
QColor color;
};
diff --git a/src/plugins/todo/todoitemsmodel.cpp b/src/plugins/todo/todoitemsmodel.cpp
index b212361f0d..2179f010f3 100644
--- a/src/plugins/todo/todoitemsmodel.cpp
+++ b/src/plugins/todo/todoitemsmodel.cpp
@@ -100,7 +100,7 @@ QVariant TodoItemsModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
return item.text;
case Qt::DecorationRole:
- return QVariant::fromValue(Utils::ThemeHelper::themedIcon(item.iconResource));
+ return icon(item.iconType);
}
break;
diff --git a/src/plugins/todo/todooutputpane.cpp b/src/plugins/todo/todooutputpane.cpp
index e31a95f9e5..f72636eb67 100644
--- a/src/plugins/todo/todooutputpane.cpp
+++ b/src/plugins/todo/todooutputpane.cpp
@@ -175,7 +175,8 @@ void TodoOutputPane::todoTreeViewClicked(const QModelIndex &index)
item.file = index.sibling(row, Constants::OUTPUT_COLUMN_FILE).data().toString();
item.line = index.sibling(row, Constants::OUTPUT_COLUMN_LINE).data().toInt();
item.color = index.data(Qt::BackgroundColorRole).value<QColor>();
- item.iconResource = index.sibling(row, Constants::OUTPUT_COLUMN_TEXT).data(Qt::DecorationRole).toString();
+ item.iconType = static_cast<IconType>(index.sibling(row, Constants::OUTPUT_COLUMN_TEXT)
+ .data(Qt::UserRole).toInt());
emit todoItemClicked(item);
}