Salome HOME
Make ModuleBase_ModelWidget::restoreValue() non-virtual and create virtual ModuleBase...
[modules/shaper.git] / src / PartSet / PartSet_WidgetFileSelector.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * PartSet_WidgetFileSelector.cpp
5  *
6  *  Created on: May 18, 2015
7  *      Author: spo
8  */
9
10 #include "PartSet_WidgetFileSelector.h"
11
12 #include <ModelAPI_AttributeString.h>
13
14 PartSet_WidgetFileSelector::PartSet_WidgetFileSelector(QWidget* theParent,
15                                                        ModuleBase_IWorkshop* theWorkshop,
16                                                        const Config_WidgetAPI* theData,
17                                                        const std::string& theParentId)
18 : ModuleBase_WidgetFileSelector(theParent, theData, theParentId)
19 , myWorkshop(theWorkshop)
20 {
21 }
22
23 bool PartSet_WidgetFileSelector::restoreValueCustom()
24 {
25   // A rare case when plugin was not loaded.
26   if (!myFeature)
27     return false;
28
29   DataPtr aData = myFeature->data();
30   AttributeStringPtr aStringAttr = aData->string("export_file_format");
31   mySelectedFilter = formatToFilter(shortFormatToFullFormat(QString::fromStdString(aStringAttr->value())));
32
33   return ModuleBase_WidgetFileSelector::restoreValueCustom();
34 }
35
36 bool PartSet_WidgetFileSelector::storeValueCustom() const
37 {
38   // A rare case when plugin was not loaded.
39   if (!myFeature)
40     return false;
41
42   DataPtr aData = myFeature->data();
43   AttributeStringPtr aStringAttr = aData->string("export_file_format");
44   aStringAttr->setValue(filterToShortFormat(mySelectedFilter).toStdString());
45
46   return ModuleBase_WidgetFileSelector::storeValueCustom();
47 }
48
49 QString PartSet_WidgetFileSelector::shortFormatToFullFormat( const QString & theFormat ) const
50 {
51   foreach(const QString & eachFormat, getValidatorFormats())
52     if (filterToShortFormat(formatToFilter(eachFormat)) == theFormat)
53       return eachFormat;
54   return QString();
55 }