From f724fd995b85913652a78c734e46b5d34de7e805 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 8 Sep 2015 12:00:00 +0300 Subject: [PATCH] Error label is added to solver --- src/Config/Config_Keywords.h | 1 + src/ModuleBase/CMakeLists.txt | 2 + .../ModuleBase_WidgetErrorLabel.cpp | 43 +++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetErrorLabel.h | 38 ++++++++++++++++ src/ModuleBase/ModuleBase_WidgetFactory.cpp | 3 ++ src/ModuleBase/ModuleBase_WidgetLabel.h | 1 - src/SketchPlugin/plugin-Sketch.xml | 1 + 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetErrorLabel.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index bf10876bf..0fdc9050f 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -23,6 +23,7 @@ const static char* NODE_XMLPARENT = "libxml_parent"; // Widgets const static char* WDG_INFO = "label"; +const static char* WDG_ERRORINFO = "error_label"; const static char* WDG_DOUBLEVALUE = "doublevalue"; const static char* WDG_INTEGERVALUE = "integervalue"; const static char* WDG_BOOLVALUE = "boolvalue"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 935f742e8..119a717bd 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -54,6 +54,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetToolbox.h ModuleBase_WidgetValidated.h ModuleBase_IconFactory.h + ModuleBase_WidgetErrorLabel.h ) SET(PROJECT_SOURCES @@ -105,6 +106,7 @@ SET(PROJECT_SOURCES ModuleBase_WidgetToolbox.cpp ModuleBase_WidgetValidated.cpp ModuleBase_IconFactory.cpp + ModuleBase_WidgetErrorLabel.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp b/src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp new file mode 100644 index 000000000..2f8260c91 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetErrorLabel.cpp +// Created: 03 Dec 2014 +// Author: Vitaly SMETANNIKOV + +#include "ModuleBase_WidgetErrorLabel.h" + +#include +#include +#include + +#include + +ModuleBase_WidgetErrorLabel::ModuleBase_WidgetErrorLabel(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_WidgetLabel(theParent, theData, theParentId) +{ + myDefaultStyle = myLabel->styleSheet(); +} + +ModuleBase_WidgetErrorLabel::~ModuleBase_WidgetErrorLabel() +{ +} + +bool ModuleBase_WidgetErrorLabel::restoreValueCustom() +{ + DataPtr aData = myFeature->data(); + AttributeStringPtr aStrAttr = aData->string(attributeID()); + std::string aMsg; + if (aStrAttr.get()) { + aMsg = aStrAttr->value(); + } + if (aMsg.empty()) { + myLabel->setText(""); + myLabel->setStyleSheet(myDefaultStyle); + } else { + myLabel->setText(aMsg.c_str()); + myLabel->setStyleSheet("QLabel { background-color : red; color : white; }"); + } + return true; +} diff --git a/src/ModuleBase/ModuleBase_WidgetErrorLabel.h b/src/ModuleBase/ModuleBase_WidgetErrorLabel.h new file mode 100644 index 000000000..882fe13dd --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetErrorLabel.h @@ -0,0 +1,38 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetErrorLabel.h +// Created: 03 Dec 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef ModuleBase_WidgetErrorLabel_H +#define ModuleBase_WidgetErrorLabel_H + +#include "ModuleBase.h" +#include "ModuleBase_WidgetLabel.h" + +class QLabel; + +/** +* \ingroup GUI +* Implementation of model widget for a label with error message +*/ +class MODULEBASE_EXPORT ModuleBase_WidgetErrorLabel : public ModuleBase_WidgetLabel +{ +Q_OBJECT + public: + /// Constructor + /// \param theParent the parent object + /// \param theData the widget configuation. The attribute of the model widget is obtained from + /// \param theParentId is Id of a parent of the current attribute + ModuleBase_WidgetErrorLabel(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + + virtual ~ModuleBase_WidgetErrorLabel(); + + virtual bool restoreValueCustom(); + +private: + QString myDefaultStyle; +}; + +#endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 24c3165b4..40a6c5a41 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: if (theType == WDG_INFO) { result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId); + } else if (theType == WDG_ERRORINFO) { + result = new ModuleBase_WidgetErrorLabel(theParent, myWidgetApi, myParentId); } else if (theType == WDG_DOUBLEVALUE) { result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId); } else if (theType == WDG_INTEGERVALUE) { diff --git a/src/ModuleBase/ModuleBase_WidgetLabel.h b/src/ModuleBase/ModuleBase_WidgetLabel.h index 9f74e614b..9fb8ddd76 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabel.h +++ b/src/ModuleBase/ModuleBase_WidgetLabel.h @@ -51,7 +51,6 @@ protected: return true; } -private: /// A label control QLabel* myLabel; }; diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index c27d599b7..9276c75b5 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -13,6 +13,7 @@ + -- 2.39.2