Commit f8499fd4 authored by Friedemann Kleint's avatar Friedemann Kleint

Initial cleanup of the Todo-plugin.

- Compile with QT_NO_CAST_FROM_ASCII, fix
  single character strings
- Remove special character from constants.h,
  fix constant names
- Fix tr() errors.
- Clean include directives
- struct -> class (coding style)

Change-Id: Id6108a03312bdecc6df3015b5a12653c95390647
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 085bf393
......@@ -58,7 +58,7 @@ const char ICON_TODO[] = ":/todoplugin/images/todo.png";
const char ICON_WARNING[] = ":/projectexplorer/images/compile_warning.png";
const char ICON_ERROR[] = ":/projectexplorer/images/compile_error.png";
// Public domain, Im the author
// Public domain, I am the author
const char ICON_CURRENT_FILE[] = ":/todoplugin/images/current-file.png";
const char ICON_WHOLE_PROJECT[] = ":/todoplugin/images/whole-project.png";
......@@ -77,14 +77,14 @@ enum OutputColumnIndex {
OUTPUT_COLUMN_LAST
};
const char OUPTUT_COLUMN_TEXT_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "Description");
const char OUTPUT_COLUMN_FILE_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "File");
const char OUTPUT_COLUMN_LINE_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "Line");
const char OUTPUT_COLUMN_TEXT_TITLE[] = QT_TRANSLATE_NOOP("Todo::Internal::TodoItemsModel", "Description");
const char OUTPUT_COLUMN_FILE_TITLE[] = QT_TRANSLATE_NOOP("Todo::Internal::TodoItemsModel", "File");
const char OUTPUT_COLUMN_LINE_TITLE[] = QT_TRANSLATE_NOOP("Todo::Internal::TodoItemsModel", "Line");
const int OUTPUT_TOOLBAR_SPACER_WIDHT = 25;
const int OUTPUT_TOOLBAR_SPACER_WIDTH = 25;
const int OUTPUT_PANE_UPDATE_INTERVAL = 2000;
const char OUTPUT_PANE_TITLE[] = QT_TRANSLATE_NOOP("TodoOutputPane", "To-Do Entries");
const char OUTPUT_PANE_TITLE[] = QT_TRANSLATE_NOOP("Todo::Internal::TodoOutputPane", "To-Do Entries");
} // namespace Constants
} // namespace Todo
......
......@@ -98,7 +98,8 @@ void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc)
// Process every line of the comment
// TODO: Do not create QStringList, just iterate through a string tracking line endings.
QStringList commentLines = QString::fromUtf8(source).split("\n", QString::SkipEmptyParts);
const QStringList commentLines =
QString::fromUtf8(source).split(QLatin1Char('\n'), QString::SkipEmptyParts);
unsigned lineNumber = 0;
translationUnit->getPosition(token.begin(), &lineNumber);
for (int j = 0; j < commentLines.count(); ++j) {
......
......@@ -34,7 +34,6 @@
#ifndef KEYWORD_H
#define KEYWORD_H
#include <QIcon>
#include <QColor>
#include <QString>
#include <QList>
......
......@@ -32,6 +32,7 @@
**************************************************************************/
#include "keyworddialog.h"
#include "keyword.h"
#include "ui_keyworddialog.h"
#include "constants.h"
......@@ -74,16 +75,22 @@ void KeywordDialog::setupListWidget(const QString &selectedIcon)
{
ui->listWidget->setViewMode(QListWidget::IconMode);
QListWidgetItem *item = new QListWidgetItem(QIcon(Constants::ICON_INFO), "information");
item->setData(Qt::UserRole, Constants::ICON_INFO);
const QString infoIconName = QLatin1String(Constants::ICON_INFO);
QListWidgetItem *item = new QListWidgetItem(QIcon(infoIconName),
QLatin1String("information"));
item->setData(Qt::UserRole, infoIconName);
ui->listWidget->addItem(item);
item = new QListWidgetItem(QIcon(Constants::ICON_WARNING), "warning");
item->setData(Qt::UserRole, Constants::ICON_WARNING);
const QString warningIconName = QLatin1String(Constants::ICON_WARNING);
item = new QListWidgetItem(QIcon(warningIconName),
QLatin1String("warning"));
item->setData(Qt::UserRole, warningIconName);
ui->listWidget->addItem(item);
item = new QListWidgetItem(QIcon(Constants::ICON_ERROR), "error");
item->setData(Qt::UserRole, Constants::ICON_ERROR);
const QString errorIconName = QLatin1String(Constants::ICON_ERROR);
item = new QListWidgetItem(QIcon(errorIconName),
QLatin1String("error"));
item->setData(Qt::UserRole, errorIconName);
ui->listWidget->addItem(item);
for (int i = 0; i < ui->listWidget->count(); ++i) {
......
......@@ -34,8 +34,6 @@
#ifndef ADDKEYWORDDIALOG_H
#define ADDKEYWORDDIALOG_H
#include "keyword.h"
#include <QDialog>
namespace Todo {
......@@ -45,6 +43,8 @@ namespace Ui {
class AddKeywordDialog;
}
class Keyword;
class KeywordDialog : public QDialog
{
Q_OBJECT
......
......@@ -37,10 +37,10 @@
<item>
<widget class="QLineEdit" name="colorEdit">
<property name="inputMask">
<string>\#HHHHHH; </string>
<string notr="true">\#HHHHHH; </string>
</property>
<property name="text">
<string>#000000</string>
<string notr="true">#000000</string>
</property>
</widget>
</item>
......
......@@ -66,7 +66,8 @@ LineParser::KeywordEntryCandidates LineParser::findKeywordEntryCandidates(const
for (int i = 0; i < m_keywords.count(); ++i) {
int searchFrom = -1;
forever {
int index = line.lastIndexOf(m_keywords.at(i).name + ":", searchFrom);
const int index = line.lastIndexOf(m_keywords.at(i).name
+ QLatin1Char(':'), searchFrom);
if (index == -1)
break; // 'forever' loop exit condition
......@@ -133,9 +134,8 @@ QList<TodoItem> LineParser::todoItemsFromKeywordEntries(const QList<KeywordEntry
foreach (const KeywordEntry &entry, entries) {
TodoItem item;
item.text = QString("%1: %2")
.arg(m_keywords.at(entry.keywordIndex).name)
.arg(entry.text);
item.text = m_keywords.at(entry.keywordIndex).name
+ QLatin1String(": ") + entry.text;
item.color = m_keywords.at(entry.keywordIndex).color;
item.iconResource = m_keywords.at(entry.keywordIndex).iconResource;
todoItems << item;
......
......@@ -34,6 +34,8 @@
#include "optionsdialog.h"
#include "ui_optionsdialog.h"
#include "keyworddialog.h"
#include "keyword.h"
#include "settings.h"
#include "constants.h"
namespace Todo {
......
......@@ -34,9 +34,6 @@
#ifndef OPTIONSDIALOG_H
#define OPTIONSDIALOG_H
#include "keyword.h"
#include "settings.h"
#include <QWidget>
namespace Todo {
......@@ -46,6 +43,9 @@ namespace Ui {
class OptionsDialog;
}
class Settings;
class Keyword;
class OptionsDialog : public QWidget
{
Q_OBJECT
......
......@@ -33,10 +33,12 @@
#include "optionspage.h"
#include "constants.h"
#include "optionsdialog.h"
#include <coreplugin/icore.h>
#include <QList>
#include <QIcon>
#include <QMessageBox>
Todo::Internal::OptionsDialog *some = 0;
......@@ -62,7 +64,7 @@ void OptionsPage::setSettings(const Settings &settings)
QString OptionsPage::id() const
{
return "TodoSettings";
return QLatin1String("TodoSettings");
}
QString OptionsPage::trName() const
......@@ -72,7 +74,7 @@ QString OptionsPage::trName() const
QString OptionsPage::category() const
{
return "To-Do";
return QLatin1String("To-Do");
}
QString OptionsPage::trCategory() const
......@@ -92,7 +94,7 @@ QString OptionsPage::displayCategory() const
QIcon OptionsPage::categoryIcon() const
{
return QIcon(Constants::ICON_TODO);
return QIcon(QLatin1String(Constants::ICON_TODO));
}
......@@ -119,7 +121,7 @@ void OptionsPage::finish()
bool OptionsPage::matches(const QString &searchKeyWord) const
{
return searchKeyWord == QString("todo");
return searchKeyWord == QLatin1String("todo");
}
} // namespace Internal
......
......@@ -34,7 +34,6 @@
#ifndef SETTINGSPAGE_H
#define SETTINGSPAGE_H
#include "optionsdialog.h"
#include "settings.h"
#include <coreplugin/dialogs/ioptionspage.h>
......@@ -42,6 +41,8 @@
namespace Todo {
namespace Internal {
class OptionsDialog;
class OptionsPage : public Core::IOptionsPage
{
Q_OBJECT
......
......@@ -86,7 +86,7 @@ void QmlJsTodoItemsScanner::processDocument(QmlJS::Document::Ptr doc)
// Process every line
// TODO: Do not create QStringList, just iterate through a string tracking line endings.
QStringList commentLines = source.split("\n", QString::SkipEmptyParts);
QStringList commentLines = source.split(QLatin1Char('\n'), QString::SkipEmptyParts);
quint32 startLine = sourceLocation.startLine;
for (int j = 0; j < commentLines.count(); ++j) {
const QString &commentLine = commentLines.at(j);
......
......@@ -34,20 +34,27 @@
#include "settings.h"
#include "constants.h"
#include <QSettings>
namespace Todo {
namespace Internal {
void Settings::save(QSettings *settings) const
{
settings->beginGroup(Constants::SETTINGS_GROUP);
settings->setValue(Constants::SCANNING_SCOPE, scanningScope);
settings->beginWriteArray(Constants::KEYWORDS_LIST);
for (int i = 0; i < keywords.size(); ++i) {
settings->setArrayIndex(i);
settings->setValue("name", keywords.at(i).name);
settings->setValue("color", keywords.at(i).color);
settings->setValue("iconResource", keywords.at(i).iconResource);
settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
settings->setValue(QLatin1String(Constants::SCANNING_SCOPE), scanningScope);
settings->beginWriteArray(QLatin1String(Constants::KEYWORDS_LIST));
if (const int size = keywords.size()) {
const QString nameKey = QLatin1String("name");
const QString colorKey = QLatin1String("color");
const QString iconResourceKey = QLatin1String("iconResource");
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->endArray();
......@@ -59,20 +66,23 @@ void Settings::load(QSettings *settings)
{
setDefault();
settings->beginGroup(Constants::SETTINGS_GROUP);
settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
scanningScope = static_cast<ScanningScope>(settings->value(Constants::SCANNING_SCOPE,
scanningScope = static_cast<ScanningScope>(settings->value(QLatin1String(Constants::SCANNING_SCOPE),
scanningScope).toInt());
KeywordList newKeywords;
int size = settings->beginReadArray(Constants::KEYWORDS_LIST);
const int size = settings->beginReadArray(QLatin1String(Constants::KEYWORDS_LIST));
if (size > 0) {
const QString nameKey = QLatin1String("name");
const QString colorKey = QLatin1String("color");
const QString iconResourceKey = QLatin1String("iconResource");
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
Keyword keyword;
keyword.name = settings->value("name").toString();
keyword.color = settings->value("color").value<QColor>();
keyword.iconResource = settings->value("iconResource").toString();
keyword.name = settings->value(nameKey).toString();
keyword.color = settings->value(colorKey).value<QColor>();
keyword.iconResource = settings->value(iconResourceKey).toString();
newKeywords << keyword;
}
keywords = newKeywords;
......
......@@ -36,7 +36,7 @@
#include "keyword.h"
#include <QSettings>
QT_FORWARD_DECLARE_CLASS(QSettings)
namespace Todo {
namespace Internal {
......@@ -46,7 +46,8 @@ enum ScanningScope {
ScanningScopeProject
};
struct Settings {
class Settings {
public:
KeywordList keywords;
ScanningScope scanningScope;
void save(QSettings *settings) const;
......
......@@ -4,6 +4,8 @@ TARGET = Todo
include(../../qtcreatorplugin.pri)
include(todo_dependencies.pri)
DEFINES += QT_NO_CAST_FROM_ASCII
HEADERS += todoplugin.h \
keyword.h \
constants.h \
......
......@@ -38,13 +38,16 @@
#include <QMetaType>
#include <QString>
#include <QIcon>
#include <QColor>
namespace Todo {
namespace Internal {
struct TodoItem
class TodoItem
{
public:
TodoItem() : line(-1) {}
QString text;
QString file;
int line;
......
......@@ -34,6 +34,8 @@
#include "todoitemsmodel.h"
#include "constants.h"
#include <QIcon>
namespace Todo {
namespace Internal {
......@@ -117,7 +119,7 @@ QVariant TodoItemsModel::headerData(int section, Qt::Orientation orientation, in
switch (section) {
case Constants::OUTPUT_COLUMN_TEXT:
return tr(Constants::OUPTUT_COLUMN_TEXT_TITLE);
return tr(Constants::OUTPUT_COLUMN_TEXT_TITLE);
case Constants::OUTPUT_COLUMN_FILE:
return tr(Constants::OUTPUT_COLUMN_FILE_TITLE);
......
......@@ -35,6 +35,8 @@
#include "constants.h"
#include "cpptodoitemsscanner.h"
#include "qmljstodoitemsscanner.h"
#include "todoitemsmodel.h"
#include "todoitemsscanner.h"
#include <projectexplorer/projectexplorer.h>
#include <coreplugin/editormanager/editormanager.h>
......
......@@ -36,8 +36,6 @@
#include "todoitem.h"
#include "settings.h"
#include "todoitemsmodel.h"
#include "todoitemsscanner.h"
#include <projectexplorer/project.h>
#include <coreplugin/editormanager/ieditor.h>
......@@ -48,6 +46,9 @@
namespace Todo {
namespace Internal {
class TodoItemsModel;
class TodoItemsScanner;
class TodoItemsProvider : public QObject
{
Q_OBJECT
......
......@@ -35,7 +35,7 @@
#define TODOITEMSSCANNER_H
#include "todoitem.h"
#include "settings.h"
#include "keyword.h"
#include <QObject>
......
......@@ -33,9 +33,13 @@
#include "todooutputpane.h"
#include "constants.h"
#include "todoitemsmodel.h"
#include <QIcon>
#include <QHeaderView>
#include <QTreeView>
#include <QToolButton>
#include <QButtonGroup>
namespace Todo {
namespace Internal {
......@@ -147,7 +151,7 @@ void TodoOutputPane::scopeButtonClicked(QAbstractButton* button)
emit scanningScopeChanged(ScanningScopeProject);
}
void TodoOutputPane::todoTreeViewClicked(QModelIndex index)
void TodoOutputPane::todoTreeViewClicked(const QModelIndex &index)
{
// Create a to-do item and notify that it was clicked on
......@@ -190,12 +194,12 @@ void TodoOutputPane::freeTreeView()
void TodoOutputPane::createScopeButtons()
{
m_currentFileButton = new QToolButton();
m_currentFileButton->setIcon(QIcon(QString(Constants::ICON_CURRENT_FILE)));
m_currentFileButton->setIcon(QIcon(QLatin1String(Constants::ICON_CURRENT_FILE)));
m_currentFileButton->setCheckable(true);
m_currentFileButton->setToolTip(tr("Scan in the current opened file"));
m_wholeProjectButton = new QToolButton();
m_wholeProjectButton->setIcon(QIcon(QString(Constants::ICON_WHOLE_PROJECT)));
m_wholeProjectButton->setIcon(QIcon(QLatin1String(Constants::ICON_WHOLE_PROJECT)));
m_wholeProjectButton->setCheckable(true);
m_wholeProjectButton->setToolTip(tr("Scan in the whole project"));
......@@ -205,7 +209,7 @@ void TodoOutputPane::createScopeButtons()
connect(m_scopeButtons, SIGNAL(buttonClicked(QAbstractButton*)), SLOT(scopeButtonClicked(QAbstractButton*)));
m_spacer = new QWidget;
m_spacer->setMinimumWidth(Constants::OUTPUT_TOOLBAR_SPACER_WIDHT);
m_spacer->setMinimumWidth(Constants::OUTPUT_TOOLBAR_SPACER_WIDTH);
}
void TodoOutputPane::freeScopeButtons()
......
......@@ -34,20 +34,24 @@
#ifndef TODOOUTPUTPANE_H
#define TODOOUTPUTPANE_H
#include "keyword.h"
#include "todoitem.h"
#include "settings.h"
#include "todoitemsmodel.h"
#include <coreplugin/ioutputpane.h>
#include <QTreeView>
#include <QToolButton>
#include <QButtonGroup>
QT_BEGIN_NAMESPACE
class QTreeView;
class QToolButton;
class QButtonGroup;
class QModelIndex;
class QAbstractButton;
QT_END_NAMESPACE
namespace Todo {
namespace Internal {
class TodoItem;
class TodoItemsModel;
class TodoOutputPane : public Core::IOutputPane
{
Q_OBJECT
......@@ -79,7 +83,7 @@ signals:
private slots:
void scopeButtonClicked(QAbstractButton *button);
void todoTreeViewClicked(QModelIndex index);
void todoTreeViewClicked(const QModelIndex &index);
private:
QTreeView *m_todoTreeView;
......
......@@ -33,6 +33,10 @@
#include "todoplugin.h"
#include "constants.h"
#include "optionspage.h"
#include "keyword.h"
#include "todooutputpane.h"
#include "todoitemsprovider.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
......
......@@ -34,19 +34,18 @@
#ifndef TODOPLUGIN_H
#define TODOPLUGIN_H
#include "optionspage.h"
#include "keyword.h"
#include "todooutputpane.h"
#include "settings.h"
#include "todoitemsprovider.h"
#include <extensionsystem/iplugin.h>
#include <QStringList>
namespace Todo {
namespace Internal {
class TodoOutputPane;
class OptionsPage;
class TodoItemsProvider;
class TodoItem;
class TodoPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment