/// Returns True if data of its attribute was modified
virtual bool isModified() const { return false; }
+ virtual void setReadOnly(bool isReadOnly) { setEnabled(!isReadOnly); }
+
+ virtual bool isReadOnly() const { return !isEnabled(); }
+
signals:
/// The signal about widget values are to be changed
void beforeValuesChanged();
const Config_WidgetAPI* theData)
: ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1),
- myIsFirst(true), myFiltersWgt(0)
+ myIsFirst(true), myFiltersWgt(0), myShowOnlyBtn(0)
{
std::string aPropertyTypes = theData->getProperty("shape_types");
QString aTypesStr = aPropertyTypes.c_str();
if (!aAllowedList.isEmpty())
myAllowedObjects = aAllowedList.split(' ', QString::SkipEmptyParts);
- QVBoxLayout* aMainLay = new QVBoxLayout(this);
- ModuleBase_Tools::adjustMargins(aMainLay);
+ myMainLayout = new QVBoxLayout(this);
+ ModuleBase_Tools::adjustMargins(myMainLayout);
QStringList aIconsList = getIconsList(myShapeTypes);
myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
myTypeCtrl->setValue(0);
myDefMode = myShapeTypes.first().toStdString();
}
- aMainLay->addWidget(myTypeCtrl);
+ myMainLayout->addWidget(myTypeCtrl);
// 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
QWidget* aLabelWgt = new QWidget(this);
QHBoxLayout* aLabelLayout = new QHBoxLayout(aLabelWgt);
aLabelLayout->setContentsMargins(0, 0, 0, 0);
- aMainLay->addWidget(aLabelWgt);
+ myMainLayout->addWidget(aLabelWgt);
QLabel* aListLabel = new QLabel(aLabelText, this);
aLabelLayout->addWidget(aListLabel);
connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem()));
connect(myListView, SIGNAL(listActivated()), SLOT(onListActivated()));
- aMainLay->addWidget(myListView->getControl());
+ myMainLayout->addWidget(myListView->getControl());
connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
- std::string aUseFilters = theData->getProperty("use_filters");
- if (aUseFilters.length() > 0) {
+ myUseFilters = theData->getProperty("use_filters");
+ if (myUseFilters.length() > 0) {
QWidget* aFltrWgt = new QWidget(this);
QHBoxLayout* aFltrLayout = new QHBoxLayout(aFltrWgt);
- myFiltersWgt = new ModuleBase_FilterStarter(aUseFilters.c_str(), aFltrWgt, theWorkshop);
+ myFiltersWgt = new ModuleBase_FilterStarter(myUseFilters, aFltrWgt, theWorkshop);
aFltrLayout->addWidget(myFiltersWgt);
aFltrLayout->addStretch();
- QPushButton* aShowBtn = new QPushButton(tr("Show only"), aFltrWgt);
- aShowBtn->setCheckable(true);
- aShowBtn->setChecked(false);
- connect(aShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
- aFltrLayout->addWidget(aShowBtn);
+ myShowOnlyBtn = new QPushButton(tr("Show only"), aFltrWgt);
+ myShowOnlyBtn->setCheckable(true);
+ myShowOnlyBtn->setChecked(false);
+ connect(myShowOnlyBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool)));
+ aFltrLayout->addWidget(myShowOnlyBtn);
- aMainLay->addWidget(aFltrWgt);
+ myMainLayout->addWidget(aFltrWgt);
}
bool aSameTop = theData->getBooleanAttribute("same_topology", false);
if (aSameTop) {
myGeomCheck = new QCheckBox(tr("Add elements that share the same topology"), this);
- aMainLay->addWidget(myGeomCheck);
+ myMainLayout->addWidget(myGeomCheck);
connect(myGeomCheck, SIGNAL(toggled(bool)), SLOT(onSameTopology(bool)));
}
else
bool ModuleBase_WidgetMultiSelector::isModified() const
{
return myListView->getControl()->count() > 0;
-}
\ No newline at end of file
+}
+
+
+void ModuleBase_WidgetMultiSelector::setReadOnly(bool isReadOnly)
+{
+ ModuleBase_WidgetSelector::setReadOnly(isReadOnly);
+ if (myShowOnlyBtn)
+ myShowOnlyBtn->hide();
+ if (myFiltersWgt) {
+ myFiltersWgt->hide();
+
+ AttributeSelectionListPtr aAttrList = feature()->selectionList(attributeID());
+ if (aAttrList.get()) {
+ FiltersFeaturePtr aFilters = aAttrList->filters();
+ if (aFilters.get()) {
+ ModuleBase_WidgetSelectionFilter::SelectorFeature = feature();
+ ModuleBase_WidgetSelectionFilter::AttributeId = attributeID();
+
+ std::string aXmlCfg, aDescription;
+ myWorkshop->module()->getXMLRepresentation(myUseFilters, aXmlCfg, aDescription);
+
+ ModuleBase_WidgetSelectionFilter* aWgt =
+ new ModuleBase_WidgetSelectionFilter(this, myWorkshop,
+ new Config_WidgetAPI(aDescription), true);
+ aWgt->setFeature(aFilters);
+ aWgt->restoreValue();
+ myMainLayout->addWidget(aWgt);
+ }
+ }
+ }
+}
class QWidget;
class QCheckBox;
-//class QComboBox;
+class QPushButton;
+class QVBoxLayout;
class ModuleBase_ListView;
class ModuleBase_IWorkshop;
class ModuleBase_ChoiceCtrl;
/// Returns True if data of its feature was modified during operation
virtual bool isModified() const;
+ virtual void setReadOnly(bool isReadOnly);
+
public slots:
/// Slot is called on selection type changed
void onSelectionTypeChanged();
bool myIsFirst;
std::string myDefMode;
+ QVBoxLayout* myMainLayout;
QCheckBox* myGeomCheck;
ModuleBase_FilterStarter* myFiltersWgt;
+ QPushButton* myShowOnlyBtn;
QObjectPtrList myVisibleObjects;
QStringList myAllowedObjects;
QStringList myTmpAllowed;
+ std::string myUseFilters;
};
#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
#include <QCheckBox>
#include <QDir>
-static FeaturePtr SelectorFeature;
-static std::string AttributeId;
+FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature;
+std::string ModuleBase_WidgetSelectionFilter::AttributeId;
GeomAPI_Shape::ShapeType selectionType(const QString& theType)
}
if (!aSelector)
return;
- SelectorFeature = aSelector->feature();
- AttributeId = aSelector->attributeID();
+ ModuleBase_WidgetSelectionFilter::SelectorFeature = aSelector->feature();
+ ModuleBase_WidgetSelectionFilter::AttributeId = aSelector->attributeID();
// Launch Filters operation
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(myWorkshop->module()->createOperation(myFeatureName));
- AttributeSelectionListPtr aAttrList = SelectorFeature->selectionList(AttributeId);
+ AttributeSelectionListPtr aAttrList =
+ ModuleBase_WidgetSelectionFilter::SelectorFeature->selectionList(
+ ModuleBase_WidgetSelectionFilter::AttributeId);
FiltersFeaturePtr aFilters = aAttrList->filters();
if (aFilters.get())
aFOperation->setFeature(aFilters);
//*****************************************************************************
//*****************************************************************************
ModuleBase_WidgetSelectionFilter::ModuleBase_WidgetSelectionFilter(QWidget* theParent,
- ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData)
+ ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, bool theReadOnly)
: ModuleBase_ModelWidget(theParent, theData),
myWorkshop(theWorkshop),
- mySelectorFeature(SelectorFeature),
- mySelectorAttribute(AttributeId)
+ mySelectorFeature(ModuleBase_WidgetSelectionFilter::SelectorFeature),
+ mySelectorAttribute(ModuleBase_WidgetSelectionFilter::AttributeId)
{
// Clear Old selection
- AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
- mySelectionType = selectionType(aAttrList->selectionType().c_str());
- aAttrList->clear();
+ AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+ mySelectionType = selectionType(aAttrList->selectionType().c_str());
+ if (!theReadOnly) {
+ aAttrList->clear();
+ }
// Define widgets
QVBoxLayout* aMainLayout = new QVBoxLayout(this);
aMainLayout->addStretch(1);
updateSelectBtn();
+ if (theReadOnly) {
+ myFiltersCombo->hide();
+ mySelectBtn->hide();
+ aLblWgt->hide();
+ myShowBtn->hide();
+ }
}
ModuleBase_WidgetSelectionFilter::~ModuleBase_WidgetSelectionFilter()
{
ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
FiltersFeaturePtr aFiltersFeature = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(myFeature);
+
+ // Init filters member of the parent attribute
+ AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
+ if (aAttrList->filters() != aFiltersFeature) {
+ aAttrList->setFilters(aFiltersFeature);
+ }
+
std::list<std::string> aFilters = aFiltersFeature->filters();
std::list<std::string>::const_iterator aIt;
for (aIt = aFilters.cbegin(); aIt != aFilters.cend(); aIt++) {
std::string aStr = (*aIt);
- onAddFilter(aStr);
+ ModuleBase_FilterItem* aItem = onAddFilter(aStr);
FilterPtr aFilterObj = aFactory->filter(aStr);
int aId = myFiltersCombo->findText(aFilterObj->name().c_str());
if (aId != -1)
myFiltersCombo->removeItem(aId);
- }
- // Init filters member of the parent attribute
- AttributeSelectionListPtr aAttrList = mySelectorFeature->selectionList(mySelectorAttribute);
- if (aAttrList->filters() != aFiltersFeature) {
- aAttrList->setFilters(aFiltersFeature);
- }
- QList<QWidget*> aWidgets;
- QList<ModuleBase_FilterItem*> aItems = myFiltersLayout->findChildren<ModuleBase_FilterItem*>();
- foreach(ModuleBase_FilterItem* aItem, aItems) {
- QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
- foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
- aWgt->restoreValue();
+ if (aItem) {
+ QList<ModuleBase_ModelWidget*> aSubList = aItem->widgets();
+ foreach(ModuleBase_ModelWidget* aWgt, aSubList) {
+ aWgt->restoreValue();
+ }
}
}
return true;
{
Q_OBJECT
public:
+ static FeaturePtr SelectorFeature;
+ static std::string AttributeId;
+
/// Constructor
/// \param theParent the parent object
/// \param theData the widget configuration. The attribute of the model widget is obtained from
/// a low-level API for reading xml definitions of widgets
ModuleBase_WidgetSelectionFilter(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData);
+ const Config_WidgetAPI* theData, bool theReadOnly = false);
/// Destructor
~ModuleBase_WidgetSelectionFilter();
}
foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
if (aWgt->isInformative()) {
- aWgt->setEnabled(false);
aWgt->setFeature(theFeature, false, false);
+ aWgt->setReadOnly(true);
aWgt->setEditingMode(true);
aWgt->restoreValue();
aWgt->showInformativePage();