From 91946859198bc4b3ea726f535a49197fa95478b2 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 9 Dec 2009 08:36:29 +0000 Subject: [PATCH] Debug --- src/SalomeApp/SalomeApp_NoteBookDlg.cxx | 56 +++++++++---------------- src/SalomeApp/SalomeApp_NoteBookDlg.h | 3 +- src/SalomeApp/SalomeApp_Notebook.cxx | 43 +++++++++++++++++-- src/SalomeApp/SalomeApp_Notebook.h | 7 +++- 4 files changed, 66 insertions(+), 43 deletions(-) diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index eaf946f94..c76ec171e 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -424,28 +424,12 @@ void NoteBook_Table::updateValues() if( NoteBook_TableRow* aRow = myRows[ i ] ) { QString aName = aRow->getVariable(); - QString aValue = myNoteBook->get( aName ).toString(); - aRow->setValue( aValue ); - } - } - blockSignals( isBlocked ); -} -//============================================================================ -/*! Function : updateValidity - * Purpose : Update validity status of myNoteBook data - */ -//============================================================================ -void NoteBook_Table::updateValidity() -{ - bool isBlocked = blockSignals( true ); - for( int i = 0, n = myRows.size(); i < n; i++ ) - { - if( NoteBook_TableRow* aRow = myRows[ i ] ) - { - QString aName = aRow->getVariable(); bool isValid = myNoteBook->isValid( aName ); markRow( aRow, isValid ); + + QString aValue = myNoteBook->get( aName ).toString(); + aRow->setValue( isValid ? aValue : QString::null ); } } blockSignals( isBlocked ); @@ -537,12 +521,12 @@ bool NoteBook_Table::renameVariable( const QString& theOldName, * Purpose : Try to update notebook */ //============================================================================ -bool NoteBook_Table::updateNoteBook( bool theOnlyParameters ) +bool NoteBook_Table::updateNoteBook() { QString anErrorType, anErrorMessage; try { - myNoteBook->update( theOnlyParameters ); + myNoteBook->update(); } catch( const SALOME::NotebookError& ex ) { anErrorType = tr( "NOTEBOOK_ERROR" ); @@ -580,21 +564,24 @@ void NoteBook_Table::init( SalomeApp_Notebook* theNoteBook ) clear(); myVariableMap.clear(); + QMap aRecentValues; + // Add all variables into the table QStringList aVariables = myNoteBook->parameters(); QStringListIterator anIter( aVariables ); while( anIter.hasNext() ) { QString aVariable = anIter.next(); - if( aVariable.left( 2 ).compare( "__" ) == 0 ) // tmp variable - continue; - QString aVariableValue = myNoteBook->expression( aVariable ); - addRow( aVariable, aVariableValue ); + QString anExpression = myNoteBook->expression( aVariable ); + addRow( aVariable, anExpression ); + aRecentValues.insert( aVariable, true ); } // Add empty row addRow(); + myNoteBook->setRecentValues( aRecentValues ); + updateValues(); blockSignals( isBlocked ); @@ -704,7 +691,7 @@ void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem ) { int aColumn = column( theItem ); processItemChanged( aRow, aColumn ); - updateValidity(); + updateValues(); } } @@ -733,10 +720,13 @@ void NoteBook_Table::processItemChanged( NoteBook_TableRow* theRow, int theColum aVariable.Name = aName; aVariable.Expression = anExpression; - if( theColumn == VARIABLE_COLUMN && isCompletePrevious && isCorrectPrevious && aName != aNamePrevious ) + if( theColumn == VARIABLE_COLUMN && isCompletePrevious /*&& isCorrectPrevious*/ && aName != aNamePrevious ) { if( !renameVariable( aNamePrevious, aName ) ) + { + aVariable.Name = aNamePrevious; return; + } updateExpressions( anIndex ); return; // it is not necessary to update notebook data after renaming } @@ -744,8 +734,6 @@ void NoteBook_Table::processItemChanged( NoteBook_TableRow* theRow, int theColum { if( !setExpression( aName, anExpression, !isCompletePrevious ) ) return; - updateNoteBook( true ); - updateValues(); } if( isLastRow( theRow ) && isComplete ) @@ -796,6 +784,7 @@ void NoteBook_Table::removeSelected() for( int i = 0, n = myRows.size(); i < n; i++ ) myRows[i]->getRowHeaderItem()->setText( QString::number( i+1 ) ); } + updateValues(); blockSignals( isBlocked ); } @@ -946,7 +935,7 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() QApplication::setOverrideCursor( Qt::WaitCursor ); - myTable->updateNoteBook( false ); + myTable->updateNoteBook(); // tmp code if( !updateStudy() ) @@ -963,16 +952,11 @@ void SalomeApp_NoteBookDlg::onUpdateStudy() //============================================================================ void SalomeApp_NoteBookDlg::onClose() { - bool isTableValid = myTable->isValid(); - if( !isTableValid && + if( !myTable->isValid() && SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA_ON_CLOSE" ), tr( "OK" ), tr( "CANCEL" ), 0, 1 ) == 1 ) return; - // update only variables - if( isTableValid && !myTable->updateNoteBook( true ) ) - return; - accept(); } diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index 25cbdcf9e..0beccceee 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -97,7 +97,7 @@ public: void removeSelected(); - bool updateNoteBook( bool theOnlyParameters ); + bool updateNoteBook(); protected slots: void onItemChanged( QTableWidgetItem* theItem ); @@ -111,7 +111,6 @@ private: bool checkRow( NoteBook_TableRow* theRow ) const; void updateExpressions( int theBaseRowIndex ); void updateValues(); - void updateValidity(); bool setExpression( const QString& theName, const QString& theExpression, diff --git a/src/SalomeApp/SalomeApp_Notebook.cxx b/src/SalomeApp/SalomeApp_Notebook.cxx index 3b02213ef..d4bc435a8 100644 --- a/src/SalomeApp/SalomeApp_Notebook.cxx +++ b/src/SalomeApp/SalomeApp_Notebook.cxx @@ -56,6 +56,7 @@ void SalomeApp_Notebook::set( const QString& theName, const QVariant& theValue, SALOME::Parameter_ptr aParam = myNotebook->GetParameter( theName.toLatin1().constData() ); bool isNew = CORBA::is_nil( aParam ) || theIsNew; + myRecentValues[ theName ] = false; switch( theValue.type() ) { case QVariant::Int: @@ -90,6 +91,7 @@ void SalomeApp_Notebook::set( const QString& theName, const QVariant& theValue, break; } } + myRecentValues[ theName ] = true; } QVariant SalomeApp_Notebook::get( const QString& theName ) const @@ -111,8 +113,25 @@ QVariant SalomeApp_Notebook::calculate( const QString& theExpr ) bool SalomeApp_Notebook::isValid( const QString& theName ) const { + QMap::const_iterator it = myRecentValues.find( theName ); + if( it != myRecentValues.end() ) + if( !it.value() ) + return false; + SALOME::Parameter_var aParam = myNotebook->GetParameter( theName.toLatin1().constData() ); - return CORBA::is_nil( aParam ) ? false : aParam->IsValid(); + if( CORBA::is_nil( aParam ) ) + return false; + + if( !aParam->IsValid() ) + return false; + + QStringList aDependencies = getParameters( theName ); + QStringListIterator anIter( aDependencies ); + while( anIter.hasNext() ) + if( !isValid( anIter.next() ) ) + return false; + + return true; } QVariant SalomeApp_Notebook::convert( SALOME::Parameter_ptr theParam ) const @@ -145,11 +164,17 @@ void SalomeApp_Notebook::update() void SalomeApp_Notebook::remove( const QString& theParamName ) { myNotebook->Remove( theParamName.toLatin1().constData() ); + QMap::iterator it = myRecentValues.find( theParamName ); + if( it != myRecentValues.end() ) + myRecentValues.erase( it ); } void SalomeApp_Notebook::rename( const QString& theOldName, const QString& theNewName ) { myNotebook->Rename( theOldName.toLatin1().constData(), theNewName.toLatin1().constData() ); + QMap::iterator it = myRecentValues.find( theOldName ); + if( it != myRecentValues.end() ) + myRecentValues.insert( theNewName, myRecentValues.take( theOldName ) ); } QStringList SalomeApp_Notebook::convert( SALOME::StringArray* theList ) const @@ -229,10 +254,20 @@ void SalomeApp_Notebook::setParameters( SALOME::ParameterizedObject_ptr theObjec theObject->SetParameters( myNotebook.in(), aParams ); } -QString SalomeApp_Notebook::getParameters( const QString& theComponent, const QString& theEntry ) +QStringList SalomeApp_Notebook::getObjectParameters( const QString& theComponent, const QString& theEntry ) const +{ + return convert( myNotebook->GetObjectParameters( theComponent.toLatin1().constData(), + theEntry.toLatin1().constData() ) ); +} + +QStringList SalomeApp_Notebook::getParameters( const QString& theParamName ) const +{ + return convert( myNotebook->GetParameters( theParamName.toLatin1().constData() ) ); +} + +void SalomeApp_Notebook::setRecentValues( const QMap& theRecentValues ) { - return QString( myNotebook->GetParameters( theComponent.toLatin1().constData(), - theEntry.toLatin1().constData() ) ); + myRecentValues = theRecentValues; } char* SalomeApp_Notebook::dump() diff --git a/src/SalomeApp/SalomeApp_Notebook.h b/src/SalomeApp/SalomeApp_Notebook.h index 78417a26f..5507daa67 100644 --- a/src/SalomeApp/SalomeApp_Notebook.h +++ b/src/SalomeApp/SalomeApp_Notebook.h @@ -30,6 +30,7 @@ #include CORBA_CLIENT_HEADER( SALOME_Notebook ) #include +#include class SalomeApp_Study; class QString; @@ -68,7 +69,10 @@ public: void setParameters( SALOME::ParameterizedObject_ptr theObject, QList theSpinList ); void setParameters( SALOME::ParameterizedObject_ptr theObject, const QStringList& theParameters ); - QString getParameters( const QString& theComponent, const QString& theEntry ); + QStringList getObjectParameters( const QString& theComponent, const QString& theEntry ) const; + QStringList getParameters( const QString& theParamName ) const; + + void setRecentValues( const QMap& theRecentValues ); char* dump(); @@ -78,6 +82,7 @@ protected: private: SALOME::Notebook_var myNotebook; + QMap myRecentValues; }; #endif -- 2.39.2