X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetExprEditor.cpp;h=721ace1e0eb663b98ff45d8232b6fff25feb1c1a;hb=9afe243148ea67f2eccbd0afa419541424de451e;hp=1df376b2b2cff2127f5f3fd05321153f707817f9;hpb=cf463f65c127715829e65a8da84fb1619588b576;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp index 1df376b2b..721ace1e0 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp @@ -1,15 +1,27 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -/* - * ModuleBase_WidgetExprEditor.cpp - * - * Created on: Aug 28, 2014 - * Author: sbh - */ +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include #include +#include + #include #include #include @@ -31,6 +43,8 @@ #include #include #include +#include +#include #include #include @@ -90,9 +104,7 @@ void ExpressionEditor::performCompletion() QTextCursor aCursor = textCursor(); aCursor.select(QTextCursor::WordUnderCursor); const QString aPrefix = aCursor.selectedText(); - if (!aPrefix.isEmpty() && aPrefix.at(aPrefix.length() - 1).isLetter()) { - performCompletion(aPrefix); - } + performCompletion(aPrefix); } void ExpressionEditor::performCompletion(const QString& theCompletionPrefix) @@ -194,7 +206,8 @@ void ExpressionEditor::paintEvent( QPaintEvent* theEvent ) QPen anOldpen = aPainter.pen(); aPainter.setPen( aColor ); lineRect.adjust(minLB, 0, 0, 0); - QString elidedText = aFontMetrics.elidedText( myPlaceHolderText, Qt::ElideRight, lineRect.width() ); + QString elidedText = + aFontMetrics.elidedText( myPlaceHolderText, Qt::ElideRight, lineRect.width() ); aPainter.drawText( lineRect, va, elidedText ); aPainter.setPen( anOldpen ); } @@ -208,9 +221,8 @@ void ExpressionEditor::onTextChanged() ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor( QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId, const std::string& thePlaceHolder ) - : ModuleBase_ModelWidget(theParent, theData, theParentId) +: ModuleBase_ModelWidget(theParent, theData) { QVBoxLayout* aMainLay = new QVBoxLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); @@ -223,7 +235,7 @@ ModuleBase_WidgetExprEditor::ModuleBase_WidgetExprEditor( QWidget* theParent, aMainLay->addWidget(myResultLabel); myEditor = new ExpressionEditor(this); myEditor->setMinimumHeight(20); - myEditor->setPlaceHolderText( QString::fromStdString( thePlaceHolder ) ); + myEditor->setPlaceHolderText( translate( thePlaceHolder ) ); aMainLay->addWidget(myEditor); this->setLayout(aMainLay); @@ -249,16 +261,16 @@ void ModuleBase_WidgetExprEditor::initializeValueByActivate() { } -bool ModuleBase_WidgetExprEditor::storeValueCustom() const +bool ModuleBase_WidgetExprEditor::storeValueCustom() { - // A rare case when plugin was not loaded. + // A rare case when plugin was not loaded. if(!myFeature) return false; DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); QString aWidgetValue = myEditor->toPlainText(); - aStringAttr->setValue(aWidgetValue.toStdString()); + aStringAttr->setValue(aWidgetValue.toStdWString()); updateObject(myFeature); // Try to get the value @@ -284,7 +296,7 @@ bool ModuleBase_WidgetExprEditor::storeValueCustom() const bool ModuleBase_WidgetExprEditor::restoreValueCustom() { - // A rare case when plugin was not loaded. + // A rare case when plugin was not loaded. if(!myFeature) return false; DataPtr aData = myFeature->data(); @@ -293,8 +305,12 @@ bool ModuleBase_WidgetExprEditor::restoreValueCustom() bool isBlocked = myEditor->blockSignals(true); QTextCursor aCursor = myEditor->textCursor(); int pos = aCursor.position(); - std::string aRestoredStr = aStringAttr->value(); - myEditor->setPlainText(QString::fromStdString(aRestoredStr)); + QString aRestoredStr; + if (aStringAttr->isUValue()) + aRestoredStr = QString::fromStdWString(Locale::Convert::toWString(aStringAttr->valueU())); + else + aRestoredStr = QString::fromStdString(aStringAttr->value()); + myEditor->setPlainText(aRestoredStr); aCursor.setPosition(pos); myEditor->setTextCursor(aCursor); myEditor->blockSignals(isBlocked);