X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetFileSelector.cpp;h=c7fcacd11e278cd8036eaad8416098419a2666c4;hb=eaa34d7803a364b8da51b6dde8b0ee3c469ae27a;hp=d857d2d66f444a4e5e69aa183627f022511565cd;hpb=0a76161addf39a6d03b90308eb99abc3a8d10e74;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index d857d2d66..c7fcacd11 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -17,14 +17,15 @@ #include -#include #include +#include +#include #include #include #include #include +#include #include -#include #include #include @@ -35,17 +36,17 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, : ModuleBase_ModelWidget(theParent, theData, theParentId) { myTitle = QString::fromStdString(theData->getProperty("title")); + myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN; myDefaultPath = QString::fromStdString(theData->getProperty("path")); - myMainWidget = new QWidget(theParent); - QGridLayout* aMainLay = new QGridLayout(myMainWidget); + QGridLayout* aMainLay = new QGridLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); - QLabel* aTitleLabel = new QLabel(myTitle, myMainWidget); + QLabel* aTitleLabel = new QLabel(myTitle, this); aTitleLabel->setIndent(1); aMainLay->addWidget(aTitleLabel, 0, 0); - myPathField = new QLineEdit(myMainWidget); + myPathField = new QLineEdit(this); aMainLay->addWidget(myPathField, 1, 0); - QPushButton* aSelectPathBtn = new QPushButton("...", myMainWidget); + QPushButton* aSelectPathBtn = new QPushButton("...", this); aSelectPathBtn->setToolTip(tr("Select file...")); aSelectPathBtn->setMaximumWidth(20); aSelectPathBtn->setMaximumHeight(20); @@ -53,7 +54,7 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, aMainLay->setColumnStretch(0, 1); myPathField->setMinimumHeight(20); aMainLay->setHorizontalSpacing(1); - myMainWidget->setLayout(aMainLay); + this->setLayout(aMainLay); connect(myPathField, SIGNAL(textChanged(const QString&)), this, SLOT(onPathChanged())); @@ -68,7 +69,7 @@ ModuleBase_WidgetFileSelector::~ModuleBase_WidgetFileSelector() bool ModuleBase_WidgetFileSelector::storeValueCustom() const { // A rare case when plugin was not loaded. - if(!myFeature) + if (!myFeature) return false; DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); @@ -81,7 +82,7 @@ bool ModuleBase_WidgetFileSelector::storeValueCustom() const bool ModuleBase_WidgetFileSelector::restoreValue() { // A rare case when plugin was not loaded. - if(!myFeature) + if (!myFeature) return false; DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); @@ -93,15 +94,10 @@ bool ModuleBase_WidgetFileSelector::restoreValue() return true; } -QWidget* ModuleBase_WidgetFileSelector::getControl() const -{ - return myMainWidget; -} - QList ModuleBase_WidgetFileSelector::getControls() const { QList result; - //QPushButton * aButton = myMainWidget->findChild(); + //QPushButton * aButton = this->findChild(); //result << aButton; result << myPathField; return result; @@ -109,15 +105,16 @@ QList ModuleBase_WidgetFileSelector::getControls() const bool ModuleBase_WidgetFileSelector::isCurrentPathValid() { - QFileInfo aFile (myPathField->text()); + QFileInfo aFile(myPathField->text()); return aFile.exists(); } - void ModuleBase_WidgetFileSelector::onPathSelectionBtn() { - QString aFilter = formatsString(); - QString aFileName = QFileDialog::getOpenFileName(myMainWidget, myTitle, myDefaultPath, aFilter); + QString aFilter = filterString(); + QString aFileName = (myType == WFS_SAVE) + ? QFileDialog::getSaveFileName(this, myTitle, myDefaultPath, aFilter) + : QFileDialog::getOpenFileName(this, myTitle, myDefaultPath, aFilter); if (!aFileName.isEmpty()) { myPathField->setText(aFileName); } @@ -125,19 +122,21 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn() void ModuleBase_WidgetFileSelector::onPathChanged() { - if(!isCurrentPathValid()) + if (myType == WFS_OPEN && !isCurrentPathValid()) return; storeValue(); emit valuesChanged(); } -QString ModuleBase_WidgetFileSelector::formatsString() const +QString ModuleBase_WidgetFileSelector::filterString() const { QStringList aResult; QStringList aValidatorFormats = getValidatorFormats(); foreach(QString eachFormat, aValidatorFormats) { - aResult << QString("%1 files (*.%1)").arg(eachFormat); + QStringList aFormatList = eachFormat.split("|"); + aResult << QString("%1 files (%2)").arg(aFormatList.value(0)) + .arg(QStringList(aFormatList).replaceInStrings(QRegExp("^(.*)$"), "*.\\1").join(" ")); } aResult << QString("All files (*.*)"); return aResult.join(";;"); @@ -150,21 +149,22 @@ QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const std::list allValidators; std::list > allArguments; aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments); - //TODO(sbh): extract as separate method - if(allArguments.empty()) - return QStringList(); + QStringList aResult; std::list anArgumentList = allArguments.front(); std::list::const_iterator it = anArgumentList.begin(); - QStringList aResult; for (; it != anArgumentList.end(); ++it) { - std::string anArg = *it; - int aSepPos = anArg.find(":"); - if (aSepPos == std::string::npos) { - continue; - } - QString aFormat = QString::fromStdString(anArg.substr(0, aSepPos)); - aFormat = aFormat.toUpper(); - aResult.append(aFormat); + QString aFormat = getFormat(*it); + if (!aFormat.isNull()) + aResult << aFormat; } return aResult; } + +QString ModuleBase_WidgetFileSelector::getFormat( const std::string& theArgument ) const +{ + QString anArgument = QString::fromStdString(theArgument); + if (!anArgument.contains(":")) + return QString(); + return anArgument.section(":", 0, 0).toUpper(); +} +