diff --git a/StyleEditor/src/StyleAnalyser.cpp b/StyleEditor/src/StyleAnalyser.cpp index 9eea18db3..739ae8527 100644 --- a/StyleEditor/src/StyleAnalyser.cpp +++ b/StyleEditor/src/StyleAnalyser.cpp @@ -85,16 +85,11 @@ void StyleAnalyser::update(QString content) QSet errorLines; QSet warningLines; - int line; for (const auto &w: styleConfig->GetWarnings()) { - // TODO: expose warning as some structure with line number - osmscout::StringToNumberSigned(w, line); - warningLines << line; + warningLines << w.GetLine(); } for (const auto &w: styleConfig->GetErrors()) { - // TODO: expose warning as some structure with line number - osmscout::StringToNumberSigned(w, line); - errorLines << line; + errorLines << w.GetLine(); } emit problematicLines(errorLines, warningLines); diff --git a/libosmscout-client-qt/include/osmscoutclientqt/DBInstance.h b/libosmscout-client-qt/include/osmscoutclientqt/DBInstance.h index 39bf0aad4..6db94e383 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/DBInstance.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/DBInstance.h @@ -42,35 +42,6 @@ namespace osmscout { -/** - * \ingroup QtAPI - */ -class OSMSCOUT_CLIENT_QT_API StyleError -{ - enum StyleErrorType { - Symbol, Error, Warning, Exception - }; - -public: - StyleError(StyleErrorType type, int line, int column, const QString &text) : - type(type), line(line), column(column), text(text){} - explicit StyleError(QString msg); - - StyleErrorType GetType() const { return type; } - QString GetTypeName() const; - int GetLine() const{ return line; } - int GetColumn() const{ return column; } - const QString &GetText() const { return text; } - QString GetDescription() const {return GetTypeName()+": "+GetText();} - -private: - StyleErrorType type; - int line; - int column; - QString text; -}; - - /** * \ingroup QtAPI * diff --git a/libosmscout-client-qt/src/osmscoutclientqt/DBInstance.cpp b/libosmscout-client-qt/src/osmscoutclientqt/DBInstance.cpp index 16ef70a78..fe0d538c4 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/DBInstance.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/DBInstance.cpp @@ -19,50 +19,14 @@ #include +#include + #include #include namespace osmscout { -StyleError::StyleError(QString msg){ - QRegExp rx("(\\d+),(\\d+) (Symbol|Error|Warning|Exception):(.*)"); - if(rx.exactMatch(msg)){ - line = rx.cap(1).toInt(); - column = rx.cap(2).toInt(); - if(rx.cap(3) == "Symbol"){ - type = Symbol; - } else if(rx.cap(3) == "Error"){ - type = Error; - } else if(rx.cap(3) == "Warning"){ - type = Warning; - } else { - type = Exception; - } - text = rx.cap(4); - } -} - -QString StyleError::GetTypeName() const -{ - switch(type){ - case Symbol: - return QString("symbol"); - break; - case Error: - return QString("error"); - break; - case Warning: - return QString("warning"); - break; - case Exception: - return QString("exception"); - break; - default: - return QString("???"); - } -} - bool DBInstance::LoadStyle(QString stylesheetFilename, std::unordered_map stylesheetFlags, QList &errors) @@ -100,11 +64,10 @@ bool DBInstance::LoadStyle(QString stylesheetFilename, osmscout::log.Info()<< "Created new style with " << stylesheetFilename.toStdString(); } else { - std::list errorsStrings=newStyleConfig->GetErrors(); + std::list errorsStrings=newStyleConfig->GetErrors(); - for(const auto& errorString : errorsStrings) { - StyleError err(QString::fromStdString(errorString)); - qWarning() << "Style error:" << err.GetDescription(); + for(const auto& err : errorsStrings) { + qWarning() << "Style error:" << QString::fromStdString(err.GetDescription()); errors.append(err); } diff --git a/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp b/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp index aee275053..fb923fbed 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp @@ -967,7 +967,7 @@ QString MapWidget::firstStylesheetErrorDescription() const QList errors=dbThread->GetStyleErrors(); if (errors.isEmpty()) return ""; - return errors.first().GetDescription(); + return QString::fromStdString(errors.first().GetDescription()); } bool MapWidget::toggleDebug() diff --git a/libosmscout-map/CMakeLists.txt b/libosmscout-map/CMakeLists.txt index 451cd495d..5ab5b28b4 100644 --- a/libosmscout-map/CMakeLists.txt +++ b/libosmscout-map/CMakeLists.txt @@ -13,6 +13,7 @@ set(HEADER_FILES include/osmscoutmap/LabelProvider.h include/osmscoutmap/LabelPath.h include/osmscoutmap/Styles.h + include/osmscoutmap/StyleError.h include/osmscoutmap/StyleDescription.h include/osmscoutmap/StyleConfig.h include/osmscoutmap/StyleProcessor.h diff --git a/libosmscout-map/include/meson.build b/libosmscout-map/include/meson.build index d6803f4ef..c56dc1f62 100644 --- a/libosmscout-map/include/meson.build +++ b/libosmscout-map/include/meson.build @@ -11,6 +11,7 @@ osmscoutmapHeader = [ 'osmscoutmap/MapParameter.h', 'osmscoutmap/LabelProvider.h', 'osmscoutmap/LabelPath.h', + 'osmscoutmap/StyleError.h', 'osmscoutmap/Styles.h', 'osmscoutmap/StyleDescription.h', 'osmscoutmap/StyleConfig.h', diff --git a/libosmscout-map/include/osmscoutmap/StyleConfig.h b/libosmscout-map/include/osmscoutmap/StyleConfig.h index eeac869f3..5811ff5df 100644 --- a/libosmscout-map/include/osmscoutmap/StyleConfig.h +++ b/libosmscout-map/include/osmscoutmap/StyleConfig.h @@ -47,6 +47,7 @@ #include #include #include +#include namespace osmscout { @@ -634,8 +635,8 @@ namespace osmscout { private: std::unordered_map flags; std::unordered_map constants; - std::list errors; - std::list warnings; + std::list errors; + std::list warnings; private: void Reset(); @@ -848,8 +849,8 @@ namespace osmscout { bool Load(const std::string& styleFile, ColorPostprocessor colorPostprocessor=nullptr, bool submodule=false); - const std::list& GetErrors() const; - const std::list& GetWarnings() const; + const std::list& GetErrors() const; + const std::list& GetWarnings() const; //@} }; diff --git a/libosmscout-map/include/osmscoutmap/StyleError.h b/libosmscout-map/include/osmscoutmap/StyleError.h new file mode 100644 index 000000000..5d3784f2e --- /dev/null +++ b/libosmscout-map/include/osmscoutmap/StyleError.h @@ -0,0 +1,107 @@ +#ifndef OSMSCOUT_STYLEERROR_H +#define OSMSCOUT_STYLEERROR_H + +/* + This source is part of the libosmscout library + Copyright (C) 2023 Lukas Karas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include + +#include + +namespace osmscout { + + /** + * \ingroup Stylesheet + */ + class OSMSCOUT_MAP_API StyleError + { + public: + enum StyleErrorType { + Symbol, Error, Warning, Exception + }; + + public: + StyleError(StyleErrorType type, int line, int column, const std::string &text) : + type(type), line(line), column(column), text(text){} + + StyleError(const StyleError&) = default; + StyleError(StyleError&&) = default; + + StyleError& operator=(const StyleError&) = default; + StyleError& operator=(StyleError&&) = default; + + ~StyleError() = default; + + StyleErrorType GetType() const + { + return type; + } + + std::string GetTypeName() const + { + switch(type){ + case Symbol: + return "Symbol"; + case Error: + return "Error"; + case Warning: + return "Warning"; + case Exception: + return "Exception"; + default: + assert(false); + return "???"; + } + } + + int GetLine() const + { + return line; + } + + int GetColumn() const + { + return column; + } + + const std::string &GetText() const + { + return text; + } + + std::string GetShortDescription() const + { + return GetTypeName() + ": " + GetText(); + } + + std::string GetDescription() const + { + return std::to_string(GetLine()) + "," + std::to_string(GetColumn()) + " " + GetShortDescription(); + } + + private: + StyleErrorType type; + int line; + int column; + std::string text; + }; + +} + +#endif //OSMSCOUT_STYLEERROR_H diff --git a/libosmscout-map/src/osmscoutmap/StyleConfig.cpp b/libosmscout-map/src/osmscoutmap/StyleConfig.cpp index 0b1e4fc5b..40f065382 100644 --- a/libosmscout-map/src/osmscoutmap/StyleConfig.cpp +++ b/libosmscout-map/src/osmscoutmap/StyleConfig.cpp @@ -1621,16 +1621,16 @@ namespace osmscout { for (const auto& err : parser->errors->errors) { switch(err.type) { case oss::Errors::Err::Symbol: - errors.push_back(std::to_string(err.line)+","+std::to_string(err.column)+std::string(" Symbol:")+err.text); + errors.push_back(StyleError(StyleError::Symbol, err.line, err.column, err.text)); break; case oss::Errors::Err::Error: - errors.push_back(std::to_string(err.line)+","+std::to_string(err.column)+std::string(" Error:")+err.text); + errors.push_back(StyleError(StyleError::Error, err.line, err.column, err.text)); break; case oss::Errors::Err::Warning: - warnings.push_back(std::to_string(err.line)+","+std::to_string(err.column)+std::string(" Warning:")+err.text); + warnings.push_back(StyleError(StyleError::Warning, err.line, err.column, err.text)); break; case oss::Errors::Err::Exception: - errors.push_back(std::to_string(err.line)+","+std::to_string(err.column)+std::string(" Exception:")+err.text); + errors.push_back(StyleError(StyleError::Exception, err.line, err.column, err.text)); break; default: break; @@ -1713,12 +1713,12 @@ namespace osmscout { return success; } - const std::list& StyleConfig::GetErrors() const + const std::list& StyleConfig::GetErrors() const { return errors; } - const std::list& StyleConfig::GetWarnings() const + const std::list& StyleConfig::GetWarnings() const { return warnings; }