X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetFileSelector.cpp;h=dbe8e8ce30411823c8863bd989e56b5b2585101d;hb=061a63480f6840b6d945f7744b3b972e2d4cb25d;hp=3292d70f228ac8df147ad4f46f07cc449e47e85f;hpb=d7d6265cce5e49374130cb4c6a4cfb3a90eba875;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index 3292d70f2..dbe8e8ce3 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -79,7 +79,7 @@ bool ModuleBase_WidgetFileSelector::storeValueCustom() const return true; } -bool ModuleBase_WidgetFileSelector::restoreValue() +bool ModuleBase_WidgetFileSelector::restoreValueCustom() { // A rare case when plugin was not loaded. if (!myFeature) @@ -88,7 +88,9 @@ bool ModuleBase_WidgetFileSelector::restoreValue() AttributeStringPtr aStringAttr = aData->string(attributeID()); bool isBlocked = myPathField->blockSignals(true); - myPathField->setText(QString::fromStdString(aStringAttr->value())); + QString aNewText = QString::fromStdString(aStringAttr->value()); + if( myPathField->text() != aNewText ) + myPathField->setText( aNewText ); myPathField->blockSignals(isBlocked); return true; @@ -97,8 +99,6 @@ bool ModuleBase_WidgetFileSelector::restoreValue() QList ModuleBase_WidgetFileSelector::getControls() const { QList result; - //QPushButton * aButton = this->findChild(); - //result << aButton; result << myPathField; return result; } @@ -119,6 +119,8 @@ void ModuleBase_WidgetFileSelector::onPathSelectionBtn() ? QFileDialog::getSaveFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter) : QFileDialog::getOpenFileName(this, myTitle, aDefaultPath, aFilter, &mySelectedFilter); if (!aFileName.isEmpty()) { + if (myType == WFS_SAVE) + aFileName = applyExtension(aFileName, mySelectedFilter); myPathField->setText(aFileName); } } @@ -131,7 +133,7 @@ void ModuleBase_WidgetFileSelector::onPathChanged() emit valuesChanged(); } -QString ModuleBase_WidgetFileSelector::formatToFilter( const QString & theFormat ) +QString ModuleBase_WidgetFileSelector::formatToFilter(const QString & theFormat) { if (theFormat.isEmpty() && !theFormat.contains(":")) return QString(); @@ -142,17 +144,31 @@ QString ModuleBase_WidgetFileSelector::formatToFilter( const QString & theFormat .arg(QStringList(aExtesionList).replaceInStrings(QRegExp("^(.*)$"), "*.\\1").join(" ")); } +QString ModuleBase_WidgetFileSelector::filterToShortFormat(const QString & theFilter) +{ + // Simplified implementation. + // It relies on theFilter was made by formatToFilter() function. + return theFilter.section(' ', 0, 0); +} + +QStringList ModuleBase_WidgetFileSelector::filterToExtensions(const QString & theFilter) +{ + // Simplified implementation. + // It relies on theFilter was made by formatToFilter() function. + QStringList anExtensions = theFilter.section("(", 1, 1).section(")", 0, 0).split(" "); + return anExtensions; +} + QStringList ModuleBase_WidgetFileSelector::getValidatorFormats() const { SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - std::list allValidators; - std::list > allArguments; - aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments); + ModelAPI_ValidatorsFactory::Validators allValidators; + aFactory->validators(myFeature->getKind(), myAttributeID, allValidators); QStringList aResult; - std::list anArgumentList = allArguments.front(); + std::list anArgumentList = allValidators.front().second; std::list::const_iterator it = anArgumentList.begin(); for (; it != anArgumentList.end(); ++it) { QString aFormat = QString::fromStdString(*it); @@ -174,3 +190,20 @@ QString ModuleBase_WidgetFileSelector::filterString() const aResult << QString("All files (*.*)"); return aResult.join(";;"); } + +QString ModuleBase_WidgetFileSelector::applyExtension(const QString& theFileName, + const QString& theFilter) +{ + QString aResult = theFileName; + bool hasExtension = false; + QStringList anExtensions = filterToExtensions(theFilter); + foreach(const QString& anExtension, anExtensions) { + if (theFileName.endsWith(anExtension.section(".", 1, 1), Qt::CaseInsensitive)) { + hasExtension = true; + break; + } + } + if (!hasExtension && !anExtensions.isEmpty()) + aResult = QString("%1.%2").arg(theFileName).arg(anExtensions[0].section(".", 1, 1)); + return aResult; +}