forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -35,6 +35,8 @@ QtcPlugin {
|
||||
"qmljstodoitemsscanner.h",
|
||||
"settings.cpp",
|
||||
"settings.h",
|
||||
"todoicons.h",
|
||||
"todoicons.cpp",
|
||||
"todoitem.h",
|
||||
"todoitemsmodel.cpp",
|
||||
"todoitemsmodel.h",
|
||||
|
||||
63
src/plugins/todo/todoicons.cpp
Normal file
63
src/plugins/todo/todoicons.cpp
Normal file
@@ -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
|
||||
51
src/plugins/todo/todoicons.h
Normal file
51
src/plugins/todo/todoicons.h
Normal file
@@ -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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user