From: ouv Date: Wed, 2 Dec 2009 09:57:08 +0000 (+0000) Subject: Notebook: automatic variable definition. X-Git-Tag: PHASE_17_Part1_V1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8a2c7ef628644b473d3611531f696d47e017de1f;p=modules%2Fgui.git Notebook: automatic variable definition. --- diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index e273bcbbb..4776a7395 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -730,19 +730,7 @@ void SalomeApp_Application::onDumpStudy( ) /*!Private SLOT. On NoteBook*/ void SalomeApp_Application::onNoteBook() { - SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); - if ( appStudy ) { - if(!myNoteBook) { - myNoteBook = new SalomeApp_NoteBookDlg(desktop(),appStudy); - } - else if(!myNoteBook->isVisible()){ - myNoteBook->Init(appStudy); - myNoteBook->adjustSize(); - myNoteBook->move((int)(desktop()->x() + desktop()->width()/2 - myNoteBook->frameGeometry().width()/2), - (int)(desktop()->y() + desktop()->height()/2 - myNoteBook->frameGeometry().height()/2)); - } - myNoteBook->show(); - } + showNoteBook( QStringList() ); } /*!Private SLOT. On load script.*/ @@ -1498,3 +1486,61 @@ SalomeApp_NoteBookDlg* SalomeApp_Application::getNoteBook() const return myNoteBook; } +/*! Define absent NoteBook parameters */ +bool SalomeApp_Application::defineAbsentParameters( const QStringList& theParameters ) +{ + if( theParameters.isEmpty() ) + return false; + + QStringList aParameters; + QStringListIterator anIter( theParameters ); + while( anIter.hasNext() ) + { + QString aParameter = anIter.next(); + if( !aParameters.contains( aParameter ) ) + aParameters << aParameter; + } + + QString aParametersString = aParameters.join( "\", \"" ); + aParametersString.prepend( "\"" ); + aParametersString.append( "\"" ); + + if( SUIT_MessageBox::question( desktop(), + QObject::tr( "WRN_WARNING" ), + QObject::tr( "ERR_NO_VARIABLE" ).arg( aParametersString ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::No ) == SUIT_MessageBox::Yes ) + { + showNoteBook( aParameters, true ); + return true; + } + return false; +} + +/*! Show NoteBook dialog with additional parameters */ +void SalomeApp_Application::showNoteBook( const QStringList& theParameters, bool theIsModal ) +{ + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if( !appStudy ) + return; + + if( !myNoteBook ) + myNoteBook = new SalomeApp_NoteBookDlg( desktop(), appStudy ); + else if( !myNoteBook->isVisible() ) + { + myNoteBook->init( appStudy ); + myNoteBook->adjustSize(); + myNoteBook->move( (int)( desktop()->x() + desktop()->width()/2 - myNoteBook->frameGeometry().width()/2 ), + (int)( desktop()->y() + desktop()->height()/2 - myNoteBook->frameGeometry().height()/2 ) ); + } + + myNoteBook->addUndefinedParameters( theParameters ); + + if( theIsModal ) + myNoteBook->exec(); + else + { + myNoteBook->setModal( false ); + myNoteBook->show(); + } +} diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 3f18e6806..e6a584330 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -103,6 +103,8 @@ public: virtual void setNoteBook(SalomeApp_NoteBookDlg* theNoteBook); virtual SalomeApp_NoteBookDlg* getNoteBook() const; + virtual bool defineAbsentParameters( const QStringList& ); + public slots: virtual void onLoadDoc(); virtual bool onLoadDoc( const QString& ); @@ -138,6 +140,8 @@ protected: virtual QMap activateModuleActions() const; virtual void moduleActionSelected( const int ); + virtual void showNoteBook( const QStringList&, bool = false ); + void objectBrowserColumnsVisibility(); private slots: diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index 9ead23dc4..df0a0a36b 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -140,7 +140,8 @@ void SalomeApp_DoubleSpinBox::onTextChanged( const QString& text ) myTextValue = text; double value = 0; - if( isValid( text, value ) == Acceptable ) + QStringList absent; + if( isValid( text, value, absent ) == Acceptable ) myCorrectValue = text; } @@ -153,7 +154,8 @@ void SalomeApp_DoubleSpinBox::onTextChanged( const QString& text ) double SalomeApp_DoubleSpinBox::valueFromText( const QString& text ) const { double value = 0; - if( isValid( text, value ) == Acceptable ) + QStringList absent; + if( isValid( text, value, absent ) == Acceptable ) return value; return defaultValue(); @@ -187,11 +189,11 @@ QValidator::State SalomeApp_DoubleSpinBox::validate( QString& str, int& pos ) co \brief This function is used to determine whether input is valid. \return validating operation result */ -bool SalomeApp_DoubleSpinBox::isValid( QString& msg, bool toCorrect ) +bool SalomeApp_DoubleSpinBox::isValid( QString& msg, QStringList& absentParams, bool toCorrect ) { double value; - QString absent; - State aState = isValid( text(), value, &absent ); + QStringList absent; + State aState = isValid( text(), value, absent ); if( aState != Acceptable ) { @@ -200,7 +202,11 @@ bool SalomeApp_DoubleSpinBox::isValid( QString& msg, bool toCorrect ) if( aState == Incompatible ) msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; else if( aState == NoVariable && !absent.isEmpty() ) - msg += tr( "ERR_NO_VARIABLE" ).arg( absent ) + "\n"; + { + // this kind of error should be processed by the external module + absentParams << absent; + return false; + } else if( aState == Invalid ) msg += tr( "ERR_INVALID_VALUE" ) + "\n"; @@ -209,6 +215,15 @@ bool SalomeApp_DoubleSpinBox::isValid( QString& msg, bool toCorrect ) return false; } + // workaround (to update the spin-box value after automatic variable definition) + // in this case the spin-box should behave as its value has been changed but + // at the same time its text should not be changed + bool isBlocked = blockSignals( true ); + QString aText = text(); + setValue( value ); + setText( aText ); + blockSignals( isBlocked ); + return true; } @@ -260,7 +275,7 @@ void SalomeApp_DoubleSpinBox::setText( const QString& value ) \brief This function is used to determine whether input is valid. \return validating operation result */ -SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& text, double& value, QString* absent ) const +SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& text, double& value, QStringList& absent ) const { SearchState aSearchState = findVariable( text, value, absent ); if( aSearchState == NotFound ) @@ -309,7 +324,7 @@ bool SalomeApp_DoubleSpinBox::checkRange( const double value ) const \brief This function is used to determine whether input is a variable name and to get its value. \return status of search operation */ -SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value, QString* absent ) const +SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( const QString& name, double& value, QStringList& absent ) const { value = 0; if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) @@ -320,8 +335,7 @@ SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( cons QStringList anAbsentParameters = aNotebook.absentParameters( name ); if( !anAbsentParameters.isEmpty() ) { - if( absent ) - *absent = anAbsentParameters.join( "\", \"" ); + absent << anAbsentParameters; return NotFound; } @@ -350,8 +364,7 @@ SalomeApp_DoubleSpinBox::SearchState SalomeApp_DoubleSpinBox::findVariable( cons return IncorrectType; } } - if( absent ) - *absent = name; + absent << name; return NotFound; } diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.h b/src/SalomeApp/SalomeApp_DoubleSpinBox.h index 66da0ab6d..90c4d99ae 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.h +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.h @@ -46,7 +46,7 @@ public: virtual QValidator::State validate( QString&, int& ) const; - virtual bool isValid( QString& msg, bool = false ); + virtual bool isValid( QString& msg, QStringList& absentParams, bool = false ); virtual void setDefaultValue( const double ); @@ -59,12 +59,12 @@ signals: void textChanged( const QString& ); protected: - State isValid( const QString&, double&, QString* = 0 ) const; + State isValid( const QString&, double&, QStringList& ) const; double defaultValue() const; bool checkRange( const double ) const; - SearchState findVariable( const QString&, double&, QString* = 0 ) const; + SearchState findVariable( const QString&, double&, QStringList& ) const; protected: virtual void keyPressEvent( QKeyEvent* ); diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx index 99746baeb..914db5821 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -110,7 +110,8 @@ void SalomeApp_IntSpinBox::onTextChanged( const QString& text ) myTextValue = text; int value = 0; - if( isValid( text, value ) == Acceptable ) + QStringList absent; + if( isValid( text, value, absent ) == Acceptable ) myCorrectValue = text; } @@ -123,7 +124,8 @@ void SalomeApp_IntSpinBox::onTextChanged( const QString& text ) int SalomeApp_IntSpinBox::valueFromText( const QString& text ) const { int value = 0; - if( isValid( text, value ) == Acceptable ) + QStringList absent; + if( isValid( text, value, absent ) == Acceptable ) return value; return defaultValue(); @@ -157,11 +159,11 @@ QValidator::State SalomeApp_IntSpinBox::validate( QString& str, int& pos ) const \brief This function is used to determine whether input is valid. \return validating operation result */ -bool SalomeApp_IntSpinBox::isValid( QString& msg, bool toCorrect ) +bool SalomeApp_IntSpinBox::isValid( QString& msg, QStringList& absentParams, bool toCorrect ) { int value; - QString absent; - State aState = isValid( text(), value, &absent ); + QStringList absent; + State aState = isValid( text(), value, absent ); if( aState != Acceptable ) { @@ -170,7 +172,11 @@ bool SalomeApp_IntSpinBox::isValid( QString& msg, bool toCorrect ) if( aState == Incompatible ) msg += tr( "ERR_INCOMPATIBLE_TYPE" ).arg( text() ) + "\n"; else if( aState == NoVariable && !absent.isEmpty() ) - msg += tr( "ERR_NO_VARIABLE" ).arg( absent ) + "\n"; + { + // this kind of error should be processed by the external module + absentParams << absent; + return false; + } else if( aState == Invalid ) msg += tr( "ERR_INVALID_VALUE" ) + "\n"; @@ -179,6 +185,15 @@ bool SalomeApp_IntSpinBox::isValid( QString& msg, bool toCorrect ) return false; } + // workaround (to update the spin-box value after automatic variable definition) + // in this case the spin-box should behave as its value has been changed but + // at the same time its text should not be changed + bool isBlocked = blockSignals( true ); + QString aText = text(); + setValue( value ); + setText( aText ); + blockSignals( isBlocked ); + return true; } @@ -216,7 +231,7 @@ void SalomeApp_IntSpinBox::setText( const QString& value ) \brief This function is used to determine whether input is valid. \return validating operation result */ -SalomeApp_IntSpinBox::State SalomeApp_IntSpinBox::isValid( const QString& text, int& value, QString* absent ) const +SalomeApp_IntSpinBox::State SalomeApp_IntSpinBox::isValid( const QString& text, int& value, QStringList& absent ) const { SearchState aSearchState = findVariable( text, value, absent ); if( aSearchState == NotFound ) @@ -267,7 +282,7 @@ bool SalomeApp_IntSpinBox::checkRange( const int value ) const \brief This function is used to determine whether input is a variable name and to get its value. \return status of search operation */ -SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QString& name, int& value, QString* absent ) const +SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QString& name, int& value, QStringList& absent ) const { value = 0; if( SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ) ) @@ -278,8 +293,7 @@ SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QStr QStringList anAbsentParameters = aNotebook.absentParameters( name ); if( !anAbsentParameters.isEmpty() ) { - if( absent ) - *absent = anAbsentParameters.join( "\", \"" ); + absent << anAbsentParameters; return NotFound; } @@ -308,8 +322,7 @@ SalomeApp_IntSpinBox::SearchState SalomeApp_IntSpinBox::findVariable( const QStr return IncorrectType; } } - if( absent ) - *absent = name; + absent << name; return NotFound; } diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.h b/src/SalomeApp/SalomeApp_IntSpinBox.h index 5df15d3ae..498b470dc 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.h +++ b/src/SalomeApp/SalomeApp_IntSpinBox.h @@ -45,7 +45,7 @@ public: virtual QValidator::State validate( QString&, int& ) const; - virtual bool isValid( QString& msg, bool = false ); + virtual bool isValid( QString& msg, QStringList& absentParams, bool = false ); virtual void setDefaultValue( const int ); @@ -57,12 +57,12 @@ signals: void textChanged( const QString& ); protected: - State isValid( const QString&, int&, QString* = 0 ) const; + State isValid( const QString&, int&, QStringList& ) const; int defaultValue() const; bool checkRange( const int ) const; - SearchState findVariable( const QString&, int&, QString* = 0 ) const; + SearchState findVariable( const QString&, int&, QStringList& ) const; protected: virtual void keyPressEvent( QKeyEvent* ); diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index b9a172008..1614ce758 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -74,11 +74,11 @@ NoteBook_TableRow::~NoteBook_TableRow() } //============================================================================ -/*! Function : AddToTable +/*! Function : addToTable * Purpose : Add this row to the table theTable */ //============================================================================ -void NoteBook_TableRow::AddToTable( QTableWidget *theTable ) +void NoteBook_TableRow::addToTable( QTableWidget *theTable ) { int aPosition = theTable->rowCount(); int aRowCount = aPosition+1; @@ -92,72 +92,72 @@ void NoteBook_TableRow::AddToTable( QTableWidget *theTable ) } //============================================================================ -/*! Function : SetVariable +/*! Function : setVariable * Purpose : */ //============================================================================ -void NoteBook_TableRow::SetVariable( const QString& theVariable ) +void NoteBook_TableRow::setVariable( const QString& theVariable ) { myVariableItem->setText( theVariable ); } //============================================================================ -/*! Function : SetExpression +/*! Function : setExpression * Purpose : */ //============================================================================ -void NoteBook_TableRow::SetExpression( const QString& theExpression ) +void NoteBook_TableRow::setExpression( const QString& theExpression ) { myExpressionItem->setText( theExpression ); } //============================================================================ -/*! Function : SetValue +/*! Function : setValue * Purpose : */ //============================================================================ -void NoteBook_TableRow::SetValue( const QString& theValue ) +void NoteBook_TableRow::setValue( const QString& theValue ) { myValueItem->setText( theValue ); } //============================================================================ -/*! Function : GetVariable +/*! Function : getVariable * Purpose : Return variable name */ //============================================================================ -QString NoteBook_TableRow::GetVariable() const +QString NoteBook_TableRow::getVariable() const { return myVariableItem->text(); } //============================================================================ -/*! Function : GetExpression +/*! Function : getExpression * Purpose : Return variable expression */ //============================================================================ -QString NoteBook_TableRow::GetExpression() const +QString NoteBook_TableRow::getExpression() const { return myExpressionItem->text(); } //============================================================================ -/*! Function : GetValue +/*! Function : getValue * Purpose : Return variable value */ //============================================================================ -QString NoteBook_TableRow::GetValue() const +QString NoteBook_TableRow::getValue() const { return myValueItem->text(); } //============================================================================ -/*! Function : IsRealValue +/*! Function : isRealValue * Purpose : Return true if theValue string is real value, otherwise return * false */ //============================================================================ -bool NoteBook_TableRow::IsRealValue( const QString theValue, double* theResult ) +bool NoteBook_TableRow::isRealValue( const QString theValue, double* theResult ) { bool aResult = false; double aDResult = theValue.toDouble( &aResult ); @@ -168,12 +168,12 @@ bool NoteBook_TableRow::IsRealValue( const QString theValue, double* theResult ) } //============================================================================ -/*! Function : IsBooleanValue +/*! Function : isBooleanValue * Purpose : Return true if theValue String is boolean value, otherwise return * false */ //============================================================================ -bool NoteBook_TableRow::IsBooleanValue( const QString theValue, bool* theResult ) +bool NoteBook_TableRow::isBooleanValue( const QString theValue, bool* theResult ) { bool aResult = false; bool aBResult; @@ -194,12 +194,12 @@ bool NoteBook_TableRow::IsBooleanValue( const QString theValue, bool* theResult } //============================================================================ -/*! Function : IsIntegerValue +/*! Function : isIntegerValue * Purpose : Return true if theValue string is integer value, otherwise return * false */ //============================================================================ -bool NoteBook_TableRow::IsIntegerValue( const QString theValue, int* theResult ) +bool NoteBook_TableRow::isIntegerValue( const QString theValue, int* theResult ) { bool aResult = false; int anIResult; @@ -212,14 +212,14 @@ bool NoteBook_TableRow::IsIntegerValue( const QString theValue, int* theResult ) } //============================================================================ -/*! Function : IsValidStringValue +/*! Function : isValidStringValue * Purpose : Return true if theValue string is valid, otherwise return * false * The string are always valid for the moment * The whole notebook is verified on apply */ //============================================================================ -bool NoteBook_TableRow::IsValidStringValue( const QString theValue ) +bool NoteBook_TableRow::isValidStringValue( const QString theValue ) { return true; } @@ -311,7 +311,7 @@ int NoteBook_Table::getUniqueIndex() const int anIndex = 0; if( !myRows.isEmpty() ) if( NoteBook_TableRow* aRow = myRows.last() ) - anIndex = aRow->GetIndex(); + anIndex = aRow->getIndex(); anIndex++; return anIndex; @@ -326,8 +326,8 @@ int NoteBook_Table::getUniqueIndex() const void NoteBook_Table::markItem( NoteBook_TableRow* theRow, int theColumn, bool theIsCorrect ) { if( QTableWidgetItem* anItem = - theColumn == VARIABLE_COLUMN ? theRow->GetVariableItem() : - theColumn == EXPRESSION_COLUMN ? theRow->GetExpressionItem() : theRow->GetValueItem() ) + theColumn == VARIABLE_COLUMN ? theRow->getVariableItem() : + theColumn == EXPRESSION_COLUMN ? theRow->getExpressionItem() : theRow->getValueItem() ) { bool isBlocked = blockSignals( true ); anItem->setForeground( QBrush( theIsCorrect ? Qt::black : Qt::red ) ); @@ -356,9 +356,9 @@ void NoteBook_Table::markRow( NoteBook_TableRow* theRow, bool theIsCorrect ) bool NoteBook_Table::checkItem( NoteBook_TableRow* theRow, int theColumn ) const { if( QTableWidgetItem* anItem = - theColumn == VARIABLE_COLUMN ? theRow->GetVariableItem() : - theColumn == EXPRESSION_COLUMN ? theRow->GetExpressionItem() : theRow->GetValueItem() ) - return anItem->foreground().color() == Qt::black; + theColumn == VARIABLE_COLUMN ? theRow->getVariableItem() : + theColumn == EXPRESSION_COLUMN ? theRow->getExpressionItem() : theRow->getValueItem() ) + return ( anItem->foreground().color() == Qt::black && !anItem->text().isEmpty() ); return false; } @@ -385,9 +385,9 @@ void NoteBook_Table::correctData( int theBaseRowIndex ) { if( NoteBook_TableRow* aRow = myRows[ i ] ) { - if( aRow->GetIndex() != theBaseRowIndex ) + if( aRow->getIndex() != theBaseRowIndex ) { - QString aName = aRow->GetVariable(); + QString aName = aRow->getVariable(); QString anExpression = myNoteBook->expression( aName ); } } @@ -407,11 +407,11 @@ void NoteBook_Table::updateExpressions( int theBaseRowIndex ) { if( NoteBook_TableRow* aRow = myRows[ i ] ) { - if( aRow->GetIndex() != theBaseRowIndex ) + if( aRow->getIndex() != theBaseRowIndex ) { - QString aName = aRow->GetVariable(); + QString aName = aRow->getVariable(); QString anExpression = myNoteBook->expression( aName ); - aRow->SetExpression( anExpression ); + aRow->setExpression( anExpression ); } } } @@ -430,9 +430,9 @@ void NoteBook_Table::updateValues() { if( NoteBook_TableRow* aRow = myRows[ i ] ) { - QString aName = aRow->GetVariable(); + QString aName = aRow->getVariable(); QVariant aValue = myNoteBook->get( aName ); - aRow->SetValue( aValue.toString() ); + aRow->setValue( aValue.toString() ); } } blockSignals( isBlocked ); @@ -457,13 +457,13 @@ bool NoteBook_Table::setExpression( const QString& theName, bool bVal; try { - if( NoteBook_TableRow::IsIntegerValue( theExpression, &iVal ) ) + if( NoteBook_TableRow::isIntegerValue( theExpression, &iVal ) ) myNoteBook->set( theName, iVal, theIsNew ); - else if( NoteBook_TableRow::IsRealValue( theExpression, &dVal ) ) + else if( NoteBook_TableRow::isRealValue( theExpression, &dVal ) ) myNoteBook->set( theName, dVal, theIsNew ); - else if( NoteBook_TableRow::IsBooleanValue( theExpression, &bVal ) ) + else if( NoteBook_TableRow::isBooleanValue( theExpression, &bVal ) ) myNoteBook->set( theName, bVal, theIsNew ); - else if( NoteBook_TableRow::IsValidStringValue( theExpression ) ) + else if( NoteBook_TableRow::isValidStringValue( theExpression ) ) myNoteBook->set( theName, theExpression, theIsNew ); } catch( const SALOME::NotebookError& ex ) { @@ -518,11 +518,11 @@ bool NoteBook_Table::renameVariable( const QString& theOldName, } //============================================================================ -/*! Function : Init +/*! Function : init * Purpose : Add variables in the table from theNoteBook */ //============================================================================ -void NoteBook_Table::Init( SalomeApp_Notebook* theNoteBook ) +void NoteBook_Table::init( SalomeApp_Notebook* theNoteBook ) { myNoteBook = theNoteBook; @@ -539,12 +539,12 @@ void NoteBook_Table::Init( SalomeApp_Notebook* theNoteBook ) QString aVariable = anIter.next(); if( aVariable.left( 2 ).compare( "__" ) == 0 ) // tmp variable continue; - QString aVariableValue = myNoteBook->expression(aVariable); - AddRow( aVariable, aVariableValue ); + QString aVariableValue = myNoteBook->expression( aVariable ); + addRow( aVariable, aVariableValue ); } // Add empty row - AddRow(); + addRow(); updateValues(); @@ -552,22 +552,51 @@ void NoteBook_Table::Init( SalomeApp_Notebook* theNoteBook ) } //============================================================================ -/*! Function : IsValid +/*! Function : addUndefinedParameters + * Purpose : Add undefined parameters + */ +//============================================================================ +void NoteBook_Table::addUndefinedParameters( const QStringList& theParameters ) +{ + int aNumParams = theParameters.count(); + if( aNumParams == 0 ) + return; + + int aNumRows = myRows.count(); + if( aNumRows == 0 ) + return; + + bool isBlocked = blockSignals( true ); + + QStringListIterator anIter( theParameters ); + while( anIter.hasNext() ) + { + QString aVariable = anIter.next(); + if( NoteBook_TableRow* aRow = myRows.last() ) + aRow->setVariable( aVariable ); + addRow(); + } + + blockSignals( isBlocked ); +} + +//============================================================================ +/*! Function : isValid * Purpose : Check validity of the table data */ //============================================================================ -bool NoteBook_Table::IsValid() const +bool NoteBook_Table::isValid() const { int aNumRows = myRows.count(); if( aNumRows == 0 ) return true; - if( !myRows[ aNumRows - 1 ]->GetVariable().isEmpty() || - !myRows[ aNumRows - 1 ]->GetExpression().isEmpty() || - !myRows[ aNumRows - 1 ]->GetValue().isEmpty() ) + if( !myRows[ aNumRows - 1 ]->getVariable().isEmpty() || + !myRows[ aNumRows - 1 ]->getExpression().isEmpty() || + !myRows[ aNumRows - 1 ]->getValue().isEmpty() ) return false; - for( int i = 0, n = myRows.size(); i < n; i++ ) + for( int i = 0, n = myRows.size()-1; i < n; i++ ) if( NoteBook_TableRow* aRow = myRows[ i ] ) if( !checkRow( aRow ) ) return false; @@ -576,28 +605,28 @@ bool NoteBook_Table::IsValid() const } //============================================================================ -/*! Function : AddRow +/*! Function : addRow * Purpose : Add a row into the table */ //============================================================================ -void NoteBook_Table::AddRow( const QString& theName, const QString& theExpression ) +void NoteBook_Table::addRow( const QString& theName, const QString& theExpression ) { int anIndex = getUniqueIndex(); NoteBook_TableRow* aRow = new NoteBook_TableRow( anIndex, this ); - aRow->SetVariable( theName ); - aRow->SetExpression( theExpression ); - aRow->AddToTable( this ); + aRow->setVariable( theName ); + aRow->setExpression( theExpression ); + aRow->addToTable( this ); myRows.append( aRow ); myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theExpression ) ); } //============================================================================ -/*! Function : GetRowByItem +/*! Function : getRowByItem * Purpose : */ //============================================================================ -NoteBook_TableRow* NoteBook_Table::GetRowByItem( const QTableWidgetItem* theItem ) const +NoteBook_TableRow* NoteBook_Table::getRowByItem( const QTableWidgetItem* theItem ) const { int aCurrentRow = row( theItem ); if( aCurrentRow >= 0 && aCurrentRow < myRows.size() ) @@ -606,11 +635,11 @@ NoteBook_TableRow* NoteBook_Table::GetRowByItem( const QTableWidgetItem* theItem } //============================================================================ -/*! Function : IsLastRow +/*! Function : isLastRow * Purpose : Return true if theRow is last row in the table */ //============================================================================ -bool NoteBook_Table::IsLastRow( const NoteBook_TableRow* theRow ) const +bool NoteBook_Table::isLastRow( const NoteBook_TableRow* theRow ) const { return theRow == myRows.last(); } @@ -622,11 +651,11 @@ bool NoteBook_Table::IsLastRow( const NoteBook_TableRow* theRow ) const //============================================================================ void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) { - NoteBook_TableRow* aRow = GetRowByItem( theItem ); + NoteBook_TableRow* aRow = getRowByItem( theItem ); if( !aRow ) return; - int anIndex = aRow->GetIndex(); + int anIndex = aRow->getIndex(); if( !myVariableMap.contains( anIndex ) ) return; @@ -638,8 +667,8 @@ void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) bool isCorrectPrevious = checkRow( aRow ); markRow( aRow, true ); - QString aName = aRow->GetVariable(); - QString anExpression = aRow->GetExpression(); + QString aName = aRow->getVariable(); + QString anExpression = aRow->getExpression(); bool isComplete = !aName.isEmpty() && !anExpression.isEmpty(); aVariable.Name = aName; @@ -672,20 +701,20 @@ void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) updateValues(); } - if( IsLastRow( aRow ) && isComplete ) + if( isLastRow( aRow ) && isComplete ) { bool isBlocked = blockSignals( true ); - AddRow(); + addRow(); blockSignals( isBlocked ); } } //============================================================================ -/*! Function : RemoveSelected +/*! Function : removeSelected * Purpose : Remove selected rows in the table */ //============================================================================ -void NoteBook_Table::RemoveSelected() +void NoteBook_Table::removeSelected() { bool isBlocked = blockSignals( true ); @@ -693,17 +722,17 @@ void NoteBook_Table::RemoveSelected() if( aSelectedItems.size() == 1 ) { QTableWidgetItem* anItem = aSelectedItems.first(); - if( NoteBook_TableRow* aRow = GetRowByItem( anItem ) ) + if( NoteBook_TableRow* aRow = getRowByItem( anItem ) ) { - if( IsLastRow( aRow ) ) + if( isLastRow( aRow ) ) { - aRow->SetVariable( QString() ); - aRow->SetExpression( QString() ); + aRow->setVariable( QString() ); + aRow->setExpression( QString() ); } else { - int anIndex = aRow->GetIndex(); - QString aName = aRow->GetVariable(); + int anIndex = aRow->getIndex(); + QString aName = aRow->getVariable(); if( myVariableMap.contains( anIndex ) ) myVariableMap.remove( anIndex ); @@ -718,7 +747,7 @@ void NoteBook_Table::RemoveSelected() // renumber header items for( int i = 0, n = myRows.size(); i < n; i++ ) - myRows[i]->GetRowHeaderItem()->setText( QString::number( i+1 ) ); + myRows[i]->getRowHeaderItem()->setText( QString::number( i+1 ) ); } blockSignals( isBlocked ); @@ -736,7 +765,6 @@ SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg( QWidget* parent, SalomeApp_Study* : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), myNoteBook( 0 ) { - setModal( false ); setWindowTitle( tr( "NOTEBOOK_TITLE" ) ); // Table @@ -793,7 +821,7 @@ SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg( QWidget* parent, SalomeApp_Study* //aDumpBtn->hide(); - Init( theStudy ); + init( theStudy ); } //============================================================================ @@ -811,11 +839,11 @@ SalomeApp_NoteBookDlg::~SalomeApp_NoteBookDlg() } //============================================================================ -/*! Function : Init() - * Purpose : init variable table +/*! Function : init + * Purpose : Init variable table */ //============================================================================ -void SalomeApp_NoteBookDlg::Init( SalomeApp_Study* theStudy ) +void SalomeApp_NoteBookDlg::init( SalomeApp_Study* theStudy ) { // delete the current notebook (if can based on another study) if( myNoteBook ) @@ -823,7 +851,17 @@ void SalomeApp_NoteBookDlg::Init( SalomeApp_Study* theStudy ) // create new notebook based on the given study myNoteBook = new SalomeApp_Notebook( theStudy ); - myTable->Init( myNoteBook ); + myTable->init( myNoteBook ); +} + +//============================================================================ +/*! Function : addUndefinedParameters + * Purpose : Add undefined parameters + */ +//============================================================================ +void SalomeApp_NoteBookDlg::addUndefinedParameters( const QStringList& theParameters ) +{ + myTable->addUndefinedParameters( theParameters ); } //============================================================================ @@ -833,7 +871,7 @@ void SalomeApp_NoteBookDlg::Init( SalomeApp_Study* theStudy ) //============================================================================ void SalomeApp_NoteBookDlg::onRemove() { - myTable->RemoveSelected(); + myTable->removeSelected(); } //============================================================================ @@ -853,7 +891,7 @@ void SalomeApp_NoteBookDlg::onDump() //============================================================================ void SalomeApp_NoteBookDlg::onUpdateStudy() { - if( !myTable->IsValid() ) + if( !myTable->isValid() ) { SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "INCORRECT_DATA_ON_UPDATE" ) ); return; @@ -871,7 +909,7 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() //============================================================================ void SalomeApp_NoteBookDlg::onClose() { - if( !myTable->IsValid() && + if( !myTable->isValid() && SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA_ON_CLOSE" ), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) != QMessageBox::Ok ) diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index f2e4e3c30..90d0c2e52 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -49,30 +49,30 @@ typedef QMap< int, NoteBoox_Variable > VariableMap; class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget { public: - NoteBook_TableRow(int, QWidget* parent=0); + NoteBook_TableRow( int, QWidget* parent = 0 ); virtual ~NoteBook_TableRow(); - int GetIndex() const { return myIndex; } + int getIndex() const { return myIndex; } - void AddToTable( QTableWidget *theTable ); + void addToTable( QTableWidget *theTable ); - void SetVariable( const QString& theVariable ); - void SetExpression( const QString& theExpression ); - void SetValue( const QString& theValue ); - - QString GetVariable() const; - QString GetExpression() const; - QString GetValue() const; - - QTableWidgetItem* GetRowHeaderItem() { return myRowHeaderItem; } - QTableWidgetItem* GetVariableItem() { return myVariableItem; } - QTableWidgetItem* GetExpressionItem() { return myExpressionItem; } - QTableWidgetItem* GetValueItem() { return myValueItem; } - - static bool IsRealValue( const QString theValue, double* theResult = 0 ); - static bool IsIntegerValue( const QString theValue, int* theResult = 0 ); - static bool IsBooleanValue( const QString theValue, bool* theResult = 0 ); - static bool IsValidStringValue( const QString theName ); + void setVariable( const QString& theVariable ); + void setExpression( const QString& theExpression ); + void setValue( const QString& theValue ); + + QString getVariable() const; + QString getExpression() const; + QString getValue() const; + + QTableWidgetItem* getRowHeaderItem() { return myRowHeaderItem; } + QTableWidgetItem* getVariableItem() { return myVariableItem; } + QTableWidgetItem* getExpressionItem() { return myExpressionItem; } + QTableWidgetItem* getValueItem() { return myValueItem; } + + static bool isRealValue( const QString theValue, double* theResult = 0 ); + static bool isIntegerValue( const QString theValue, int* theResult = 0 ); + static bool isBooleanValue( const QString theValue, bool* theResult = 0 ); + static bool isValidStringValue( const QString theName ); private: int myIndex; @@ -90,17 +90,12 @@ public: NoteBook_Table( QWidget* parent = 0 ); virtual ~NoteBook_Table(); - void Init( SalomeApp_Notebook* theNoteBook ); + void init( SalomeApp_Notebook* theNoteBook ); + void addUndefinedParameters( const QStringList& theParameters ); - bool IsValid() const; + bool isValid() const; - void AddRow( const QString& theName = QString::null, - const QString& theExpression = QString::null ); - - NoteBook_TableRow* GetRowByItem( const QTableWidgetItem* theItem ) const; - bool IsLastRow( const NoteBook_TableRow* aRow ) const; - - void RemoveSelected(); + void removeSelected(); protected slots: void onItemChanged( QTableWidgetItem* theItem ); @@ -127,6 +122,12 @@ private: QString& theErrorType, QString& theErrorMessage ); + void addRow( const QString& theName = QString::null, + const QString& theExpression = QString::null ); + + NoteBook_TableRow* getRowByItem( const QTableWidgetItem* theItem ) const; + bool isLastRow( const NoteBook_TableRow* aRow ) const; + private: QList myRows; @@ -143,9 +144,10 @@ public: SalomeApp_NoteBookDlg( QWidget* parent, SalomeApp_Study* theStudy ); virtual ~SalomeApp_NoteBookDlg(); - void Init( SalomeApp_Study* theStudy ); + void init( SalomeApp_Study* theStudy ); + void addUndefinedParameters( const QStringList& theParameters ); -public slots: +protected slots: void onRemove(); void onDump(); void onUpdateStudy(); diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index 0b543362a..a62694ab7 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -91,7 +91,9 @@ Python file must include only letters, digits and underscores and start from let ERR_NO_VARIABLE - These variables have to be defined: "%1" + The following variables are not defined: +%1 +Do you want to define them by the notebook?