Commit 337013b1 authored by Lukáš Tvrdý's avatar Lukáš Tvrdý

Move static initialization to cpp file

Every module which included Parameter.h initialized the map
mapping the type of parameter to type's name
parent d9ce183d
/*
* Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
* Copyright (c) 2013-2015 Lukáš Tvrdý <lukast.dev@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -117,8 +117,7 @@ QStringList Command::breakIntoTokens(const QString &line, bool &lastTokenEnclose
typeName.remove(0, 1);
}
const QList<QString> &typeDefs = PARAMETER_NAMES_STRINGS;
if (!typeDefs.contains(typeName))
if (!Parameter::isTypeDefined(typeName))
{
dbgPlugins << "Unknown type" << typeName << line;
}
......@@ -245,55 +244,55 @@ bool Command::processParameter(const QStringList& block)
typeDefinition.remove(0,1);
}
if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::FLOAT_P]))
if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::FLOAT_P]))
{
parameter = new FloatParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::INT_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::INT_P]))
{
parameter = new IntParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::SEPARATOR_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::SEPARATOR_P]))
{
parameter = new SeparatorParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::CHOICE_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::CHOICE_P]))
{
parameter = new ChoiceParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::TEXT_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::TEXT_P]))
{
parameter = new TextParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::NOTE_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::NOTE_P]))
{
parameter = new NoteParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::LINK_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::LINK_P]))
{
parameter = new LinkParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::BOOL_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::BOOL_P]))
{
parameter = new BoolParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::COLOR_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::COLOR_P]))
{
parameter = new ColorParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::FOLDER_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::FOLDER_P]))
{
parameter = new FolderParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::FILE_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::FILE_P]))
{
parameter = new FileParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::CONST_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::CONST_P]))
{
parameter = new ConstParameter(paramName, showPreviewOnChange);
}
else if (typeDefinition.startsWith(PARAMETER_NAMES[Parameter::BUTTON_P]))
else if (typeDefinition.startsWith(Parameter::PARAMETER_NAMES[Parameter::BUTTON_P]))
{
parameter = new ButtonParameter(paramName, showPreviewOnChange);
}
......
/*
* Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
* Copyright (c) 2013-2015 Lukáš Tvrdý <lukast.dev@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/*
* Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
* Copyright (c) 2013-2015 Lukáš Tvrdý <lukast.dev@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -23,6 +23,28 @@
#include <kis_debug.h>
QMap< Parameter::ParameterType, QString > Parameter::initMap()
{
QMap<Parameter::ParameterType, QString> map;
map.insert(Parameter::FLOAT_P,"float");
map.insert(Parameter::INT_P, "int");
map.insert(Parameter::BOOL_P, "bool");
map.insert(Parameter::CHOICE_P, "choice");
map.insert(Parameter::TEXT_P, "text");
map.insert(Parameter::FILE_P, "file");
map.insert(Parameter::FOLDER_P, "folder");
map.insert(Parameter::COLOR_P, "color");
map.insert(Parameter::NOTE_P, "note");
map.insert(Parameter::LINK_P, "link");
map.insert(Parameter::SEPARATOR_P, "separator");
map.insert(Parameter::CONST_P,"const");
map.insert(Parameter::BUTTON_P,"button");
return map;
}
const QMap<Parameter::ParameterType, QString> Parameter::PARAMETER_NAMES = initMap();
const QList<QString> Parameter::PARAMETER_NAMES_STRINGS = PARAMETER_NAMES.values();
Parameter::Parameter(const QString& name, bool updatePreview)
:m_name(name),
m_type(INVALID_P),
......@@ -105,6 +127,19 @@ Parameter::ParameterType Parameter::nameToType(const QString& typeName)
return Parameter::INVALID_P;
}
QString Parameter::typeName() const
{
Q_ASSERT(PARAMETER_NAMES.contains(m_type));
return PARAMETER_NAMES[m_type];
}
bool Parameter::isTypeDefined(const QString& typeName)
{
return PARAMETER_NAMES_STRINGS.contains(typeName);
}
/**************************
== FloatParameter ==
***************************/
......
/*
* Copyright (c) 2013 Lukáš Tvrdý <lukast.dev@gmail.com
* Copyright (c) 2013-2015 Lukáš Tvrdý <lukast.dev@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -65,6 +65,9 @@ public:
virtual void reset() { };
static Parameter::ParameterType nameToType(const QString &typeName);
static bool isTypeDefined(const QString &typeName);
QString typeName() const;
protected:
// strips parameter type (int, note, etc.) and enclosing brackets
......@@ -73,31 +76,15 @@ protected:
QStringList getValues(const QString& typeDefinition);
static QString stripQuotes(const QString& str);
static QString addQuotes(const QString& str);
};
static QMap<Parameter::ParameterType, QString> initMap()
{
QMap<Parameter::ParameterType, QString> map;
map.insert(Parameter::FLOAT_P,"float");
map.insert(Parameter::INT_P, "int");
map.insert(Parameter::BOOL_P, "bool");
map.insert(Parameter::CHOICE_P, "choice");
map.insert(Parameter::TEXT_P, "text");
map.insert(Parameter::FILE_P, "file");
map.insert(Parameter::FOLDER_P, "folder");
map.insert(Parameter::COLOR_P, "color");
map.insert(Parameter::NOTE_P, "note");
map.insert(Parameter::LINK_P, "link");
map.insert(Parameter::SEPARATOR_P, "separator");
map.insert(Parameter::CONST_P,"const");
map.insert(Parameter::BUTTON_P,"button");
return map;
}
static const QMap<Parameter::ParameterType, QString> PARAMETER_NAMES = initMap();
static const QList<QString> PARAMETER_NAMES_STRINGS = PARAMETER_NAMES.values();
static QMap<Parameter::ParameterType, QString> initMap();
public:
static const QMap<Parameter::ParameterType, QString> PARAMETER_NAMES;
static const QList<QString> PARAMETER_NAMES_STRINGS;
};
class FloatParameter : public Parameter
{
......
......@@ -28,6 +28,13 @@
#include <Command.h>
#include <Category.h>
// category match example : #@gimp _<b>Lights &amp; Shadows</b>
const static QRegExp CATEGORY_NAME_RX("#@gimp\\s+[^:]+$");
// command match example: #@gimp Poster edges : gimp_poster_edges, gimp_poster_edges_preview(0)
const static QRegExp COMMAND_NAME_RX("#@gimp\\s+\\w+[^:]+:\\s*\\w+\\s*,\\s*\\w+\\(?[0-2]?\\)?");
// parameter match example: #@gimp : Fast approximation = bool(0)
// #@gimp : X-size = float(0.9,0,2)
const static QRegExp PARAMETER_RX("#@gimp\\s+:\\s*[^=]*=\\s*[\\w]*");
KisGmicParser::KisGmicParser(const QStringList& filePaths):m_filePaths(filePaths)
{
......
......@@ -33,15 +33,7 @@ class Parameter;
class QTextStream;
const QString GIMP_COMMENT = "#@gimp";
// category match example : #@gimp _<b>Lights &amp; Shadows</b>
const QRegExp CATEGORY_NAME_RX("#@gimp\\s+[^:]+$");
// command match example: #@gimp Poster edges : gimp_poster_edges, gimp_poster_edges_preview(0)
const QRegExp COMMAND_NAME_RX("#@gimp\\s+\\w+[^:]+:\\s*\\w+\\s*,\\s*\\w+\\(?[0-2]?\\)?");
// parameter match example: #@gimp : Fast approximation = bool(0)
// #@gimp : X-size = float(0.9,0,2)
const QRegExp PARAMETER_RX("#@gimp\\s+:\\s*[^=]*=\\s*[\\w]*");
const static QString GIMP_COMMENT = "#@gimp";
class KisGmicParser
{
......
......@@ -63,7 +63,7 @@ void KisGmicSettingsWidget::createSettingsWidget(ROLE role)
for (int i = 0; i < parameters.size();i++)
{
Parameter * p = parameters.at(i);
dbgPlugins << "Processing: " << qPrintable(PARAMETER_NAMES[p->m_type]) << " " << qPrintable(p->toString());
dbgPlugins << "Processing: " << qPrintable(p->typeName()) << " " << qPrintable(p->toString());
switch (p->m_type)
{
case Parameter::INT_P:
......@@ -444,7 +444,7 @@ void KisGmicSettingsWidget::createSettingsWidget(ROLE role)
}
default:{
dbgPlugins << "IGNORING : " << qPrintable(PARAMETER_NAMES[p->m_type]);
dbgPlugins << "IGNORING : " << qPrintable(p->typeName());
break;
}
......
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