}
}
+void ModuleBase_ChoiceCtrl::setValue(const QString& theVal)
+{
+ switch (myType) {
+ case RadioButtons:
+ foreach (QAbstractButton* aBtn, myButtons->buttons()) {
+ aBtn->setChecked(aBtn->toolTip() == theVal);
+ }
+ break;
+ case ComboBox:
+ myCombo->setCurrentText(theVal);
+ break;
+ }
+}
+
+
void ModuleBase_ChoiceCtrl::setTooltip(QString theTip)
{
if (myType == ComboBox)
/// \param theVal a value (from 0 to number of items)
void setValue(int theVal);
+ /// Set value: text of button or item of combo box.
+ /// \param theVal a value (one of text items)
+ void setValue(const QString& theVal);
+
/// Set tool tip for label. Used only for combo box.
void setTooltip(QString theTip);
/// If not then it means that the widget do not need attribute at all.
virtual bool usesAttribute() const { return true; }
+ /// It is called when user press Ok or OkPlus buttons in the parent property panel
+ /// By default this slot does nothing
+ virtual void onFeatureAccepted() {}
+
signals:
/// The signal about widget values are to be changed
void beforeValuesChanged();
#include <QVBoxLayout>
+static QMap<std::string, std::string> defaultValues;
+
ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent,
const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData),
- myIsFocusOnCurrentPage(false)
+ myIsFocusOnCurrentPage(false), myIsFirst(true)
{
// it is not obligatory to be ignored when property panel tries to activate next active widget
// but if focus is moved to this control, it can accept it.
myIsObligatory = false;
+ if (defaultValues.contains(myFeatureId))
+ myDefValue = defaultValues[myFeatureId];
}
ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
return false;
DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
- QString aCaseId = QString::fromStdString(aStringAttr->value());
+ QString aCaseId = QString::fromStdString(myDefValue.empty()?
+ aStringAttr->value() : myDefValue);
+ myIsFirst = false;
int idx = myCaseIds.indexOf(aCaseId);
if (idx == -1)
- return false;
+ idx = currentPageIndex();
setCurrentPageIndex(idx);
return true;
}
if(!myFeature)
return false;
DataPtr aData = myFeature->data();
+
AttributeStringPtr aStringAttr = aData->string(attributeID());
- QString aWidgetValue = myCaseIds.at(currentPageIndex());
- aStringAttr->setValue(aWidgetValue.toStdString());
+ std::string aWidgetValue;
+ if (myIsFirst)
+ aWidgetValue = myDefValue.empty()?
+ myCaseIds.at(currentPageIndex()).toStdString() : myDefValue;
+ else
+ aWidgetValue = myCaseIds.at(currentPageIndex()).toStdString();
+ myDefValue = aWidgetValue;
+ aStringAttr->setValue(aWidgetValue);
+
+ myIsFirst = false;
+
updateObject(myFeature); // for preview
return true;
}
focusTo();
}
+void ModuleBase_PagedContainer::onFeatureAccepted()
+{
+ defaultValues[myFeatureId] = myDefValue;
+}
/// Redefinition of virtual function
virtual void enableFocusProcessing();
+ /// The slot is called when user press Ok or OkPlus buttons in the parent property panel
+ virtual void onFeatureAccepted();
+
protected:
/// Returns index of current page
virtual int currentPageIndex() const = 0;
bool myIsFocusOnCurrentPage;
QStringList myCaseIds;
QList<ModuleBase_PageBase*> myPages;
-
+ bool myIsFirst;
+ std::string myDefValue;
};
#endif /* MODULEBASE_PAGEDCONTAINER_H_ */
#include <QRadioButton>
#include <QToolButton>
+static QMap<std::string, int> defaultValues;
+
ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData)//, myCombo(0), myButtons(0)
+: ModuleBase_ModelWidget(theParent, theData), myIsFirst(true)
{
+ myHasValue = defaultValues.contains(myFeatureId);
+ if (myHasValue)
+ myDefValue = defaultValues[myFeatureId];
+ else
+ myDefValue = 0;
+
QString aLabelText = translate(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
std::string aTypes = theData->getProperty("string_list");
DataPtr aData = myFeature->data();
std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
- aIntAttr->setValue(myChoiceCtrl->value());
+ int aCase = 0;
+ if (myIsFirst)
+ aCase = myHasValue? myDefValue : myChoiceCtrl->value();
+ else
+ aCase = myChoiceCtrl->value();
+
+ aIntAttr->setValue(aCase);
+ myDefValue = aCase;
+ myIsFirst = false;
+
updateObject(myFeature);
return true;
}
}
myChoiceCtrl->blockSignals(isBlocked);
emit itemSelected(this, aIntAttr->value());
+ myDefValue = aIntAttr->value();
+ myIsFirst = false;
}
return true;
}
emit itemSelected(this, theIndex);
}
+
+void ModuleBase_WidgetChoice::onFeatureAccepted()
+{
+ defaultValues[myFeatureId] = myDefValue;
+}
/// \return the title value
QString getPropertyPanelTitle(int theIndex);
+ /// The slot is called when user press Ok or OkPlus buttons in the parent property panel
+ virtual void onFeatureAccepted();
+
signals:
/// Segnal about selected item
/// \param theWidget selected widget
void onCurrentIndexChanged(int theIndex);
private:
- /// The label
- //QLabel* myLabel;
-
- /// The control
- //QComboBox* myCombo;
- //QButtonGroup* myButtons;
ModuleBase_ChoiceCtrl* myChoiceCtrl;
// XML definition of titles
QStringList myButtonTitles;
std::string myStringListAttribute;
+
+ bool myIsFirst;
+ int myDefValue;
+ bool myHasValue;
};
#endif
return aIcons;
}
+/// Stores default values of selected option (selection mode)
+/// It is used only in case if myTypeCtrl is used
+static QMap<std::string, std::string> defaultValues;
ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData)
: ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
- myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1)
+ myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1),
+ myIsFirst(true)
{
std::string aPropertyTypes = theData->getProperty("type_choice");
QString aTypesStr = aPropertyTypes.c_str();
myTypeCtrl->setLabel(tr("Type"));
myTypeCtrl->setValue(0);
aMainLay->addWidget(myTypeCtrl, 0, 0, 1, 2);
+ myDefMode = myShapeTypes.first().toStdString();
// There is no sense to parameterize list of types while we can not parameterize selection mode
// if the xml definition contains one type, the controls to select a type should not be shown
connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
myIsNeutralPointClear = theData->getBooleanAttribute("clear_in_neutral_point", true);
+ if (myShapeTypes.size() > 1 || myIsUseChoice) {
+ if (defaultValues.contains(myFeatureId)) {
+ myDefMode = defaultValues[myFeatureId];
+ myTypeCtrl->setValue(myDefMode.c_str());
+ }
+ }
}
ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
std::string aType = anAttribute->attributeType();
if (aType == ModelAPI_AttributeSelectionList::typeId()) {
AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
- aSelectionListAttr->setSelectionType(myTypeCtrl->textValue().toStdString());
+
+ std::string aMode = myTypeCtrl->textValue().toStdString();
+ if (myTypeCtrl->isVisible() && myIsFirst && (!myDefMode.empty()))
+ aMode = myDefMode;
+
+ aSelectionListAttr->setSelectionType(aMode);
+ myIsFirst = false;
}
return true;
}
AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
// Restore shape type
std::string aSelectionType = aSelectionListAttr->selectionType().c_str();
- if (!aSelectionType.empty())
+ if (!aSelectionType.empty()) {
setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionType.c_str()));
+ myDefMode = aSelectionType;
+ myIsFirst = false;
+ }
}
updateSelectionList();
return true;
}
}
return aList;
-}
\ No newline at end of file
+}
+
+
+void ModuleBase_WidgetMultiSelector::onFeatureAccepted()
+{
+ defaultValues[myFeatureId] = myDefMode;
+}
/// \param theActionType type of action. It can be ActionUndo or ActionRedo.
virtual QList<ActionInfo> actionsList(ModuleBase_ActionType theActionType) const;
+ /// The slot is called when user press Ok or OkPlus buttons in the parent property panel
+ virtual void onFeatureAccepted();
+
public slots:
/// Slot is called on selection type changed
void onSelectionTypeChanged();
/// Position in a container of selected values
int myCurrentHistoryIndex;
+
+ bool myIsFirst;
+ std::string myDefMode;
};
#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
{
myWidgets = theWidgets;
- if (theWidgets.empty()) return;
+ if (theWidgets.empty())
+ return;
foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
this, SLOT(onFocusInWidget(ModuleBase_ModelWidget*)));
this, SIGNAL(keyReleased(QObject*, QKeyEvent*)));
connect(aWidget, SIGNAL(enterClicked(QObject*)),
this, SIGNAL(enterClicked(QObject*)));
-
}
}
QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
aBtn->setDefaultAction(anAct);
}
+ QToolButton* aBtn = findButton(PROP_PANEL_OK);
+ connect(aBtn->defaultAction(), SIGNAL(triggered(bool)), this, SLOT(onAcceptData()));
+ aBtn = findButton(PROP_PANEL_OK_PLUS);
+ connect(aBtn->defaultAction(), SIGNAL(triggered(bool)), this, SLOT(onAcceptData()));
}
+void XGUI_PropertyPanel::onAcceptData()
+{
+ foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
+ aWidget->onFeatureAccepted();
+ }
+}
+
+
ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
{
return myPreselectionWidget;
/// \param theWidget the current widget
void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
+ void onAcceptData();
+
signals:
/// The signal is emitted if the enter is clicked in the control of the widget
/// \param theObject a sender of the event