#include <QLayout>
#include <QPushButton>
-#define DEFAULT_MARGIN 11
-#define DEFAULT_SPACING 6
-#define COLUMN_SIZE 180
-
-#define NAME_COLUMN 0
-#define VALUE_COLUMN 1
+#define VARIABLE_COLUMN 0
+#define EXPRESSION_COLUMN 1
+#define VALUE_COLUMN 2
+#define VARIABLE_COLUMN_SIZE 120
+#define EXPRESSION_COLUMN_SIZE 180
+#define VALUE_COLUMN_SIZE 100
+#define GAP_SIZE 80
///////////////////////////////////////////////////////////////////////////
// NoteBook_TableRow class //
* Purpose : Constructor
*/
//============================================================================
-NoteBook_TableRow::NoteBook_TableRow(int index, QWidget* parent):
- QWidget(parent),
- myIndex(index),
- myRowHeader(new QTableWidgetItem()),
- myVariableName(new QTableWidgetItem()),
- myVariableValue(new QTableWidgetItem())
+NoteBook_TableRow::NoteBook_TableRow( int index, QWidget* parent ):
+ QWidget( parent ),
+ myIndex( index ),
+ myRowHeaderItem( new QTableWidgetItem() ),
+ myVariableItem( new QTableWidgetItem() ),
+ myExpressionItem( new QTableWidgetItem() ),
+ myValueItem( new QTableWidgetItem() )
{
+ Qt::ItemFlags aFlags = myValueItem->flags();
+ myValueItem->setFlags( aFlags ^ Qt::ItemIsEditable );
}
//============================================================================
* 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;
- theTable->setRowCount(aRowCount);
- myRowHeader->setText(QString::number(aRowCount));
+ theTable->setRowCount( aRowCount );
+ myRowHeaderItem->setText( QString::number( aRowCount ) );
- theTable->setVerticalHeaderItem(aPosition,myRowHeader);
- theTable->setItem(aPosition, NAME_COLUMN, myVariableName);
- theTable->setItem(aPosition, VALUE_COLUMN, myVariableValue);
+ theTable->setVerticalHeaderItem( aPosition, myRowHeaderItem );
+ theTable->setItem( aPosition, VARIABLE_COLUMN, myVariableItem );
+ theTable->setItem( aPosition, EXPRESSION_COLUMN, myExpressionItem );
+ theTable->setItem( aPosition, VALUE_COLUMN, myValueItem );
}
//============================================================================
-/*! Function : SetName
+/*! Function : SetVariable
* Purpose :
*/
//============================================================================
-void NoteBook_TableRow::SetName(const QString theName)
+void NoteBook_TableRow::SetVariable( const QString& theVariable )
{
- myVariableName->setText(theName);
+ myVariableItem->setText( theVariable );
}
//============================================================================
-/*! Function : SetValue
+/*! Function : SetExpression
* Purpose :
*/
//============================================================================
-void NoteBook_TableRow::SetValue(const QString theValue)
+void NoteBook_TableRow::SetExpression( const QString& theExpression )
{
- myVariableValue->setText(theValue);
+ myExpressionItem->setText( theExpression );
}
//============================================================================
-/*! Function : GetName
- * Purpose : Return variable name
- */
-//============================================================================
-QString NoteBook_TableRow::GetName() const
-{
- return myVariableName->text();
-}
-
-//============================================================================
-/*! Function : GetValue
- * Purpose : Return variable value
+/*! Function : SetValue
+ * Purpose :
*/
//============================================================================
-QString NoteBook_TableRow::GetValue() const
+void NoteBook_TableRow::SetValue( const QString& theValue )
{
- return myVariableValue->text();
+ myValueItem->setText( theValue );
}
//============================================================================
-/*! Function : GetVariableItem
- * Purpose :
+/*! Function : GetVariable
+ * Purpose : Return variable name
*/
//============================================================================
-QTableWidgetItem* NoteBook_TableRow::GetVariableItem()
+QString NoteBook_TableRow::GetVariable() const
{
- return myVariableValue;
+ return myVariableItem->text();
}
//============================================================================
-/*! Function : GetNameItem
- * Purpose :
+/*! Function : GetExpression
+ * Purpose : Return variable expression
*/
//============================================================================
-QTableWidgetItem* NoteBook_TableRow::GetNameItem()
+QString NoteBook_TableRow::GetExpression() const
{
- return myVariableName;
+ return myExpressionItem->text();
}
//============================================================================
-/*! Function : GetHeaderItem
- * Purpose :
+/*! Function : GetValue
+ * Purpose : Return variable value
*/
//============================================================================
-QTableWidgetItem* NoteBook_TableRow::GetHeaderItem()
+QString NoteBook_TableRow::GetValue() const
{
- return myRowHeader;
+ return myValueItem->text();
}
//============================================================================
* 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);
- if(aResult && theResult)
+ double aDResult = theValue.toDouble( &aResult );
+ if( aResult && theResult )
*theResult = aDResult;
return aResult;
* false
*/
//============================================================================
-bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){
+bool NoteBook_TableRow::IsBooleanValue( const QString theValue, bool* theResult )
+{
bool aResult = false;
bool aBResult;
- if(theValue.compare("True") == 0) {
+ if( theValue.compare( "True" ) == 0 )
+ {
aBResult = true;
aResult = true;
}
- else if(theValue.compare("False") == 0) {
+ else if( theValue.compare( "False" ) == 0 )
+ {
aBResult = false;
aResult = true;
}
- if(aResult && theResult)
+ if( aResult && theResult )
*theResult = aBResult;
return aResult;
* false
*/
//============================================================================
-bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult)
+bool NoteBook_TableRow::IsIntegerValue( const QString theValue, int* theResult )
{
bool aResult = false;
int anIResult;
- anIResult = theValue.toInt(&aResult);
+ anIResult = theValue.toInt( &aResult );
- if(aResult && theResult)
+ if( aResult && theResult )
*theResult = anIResult;
return aResult;
* The whole notebook is verified on apply
*/
//============================================================================
-bool NoteBook_TableRow::IsValidStringValue(const QString theValue)
+bool NoteBook_TableRow::IsValidStringValue( const QString theValue )
{
return true;
}
* Purpose : Constructor
*/
//============================================================================
-NoteBook_Table::NoteBook_Table(QWidget * parent)
- :QTableWidget(parent)
+NoteBook_Table::NoteBook_Table( QWidget* parent )
+ : QTableWidget( parent )
{
- setColumnCount(2);
- setSelectionMode(QAbstractItemView::SingleSelection);
+ setColumnCount( 3 );
+ setSelectionMode( QAbstractItemView::SingleSelection );
- //Add Headers Columns
+ // Add headers columns
QFont aFont = QFont();
- aFont.setBold(true);
- aFont.setPointSize(10);
+ aFont.setBold( true );
+ aFont.setPointSize( 10 );
- //"Name" column
- QTableWidgetItem * aNameHeader = new QTableWidgetItem();
- aNameHeader->setText(tr("VARNAME_COLUMN"));
- aNameHeader->setFont(aFont);
- setHorizontalHeaderItem(0,aNameHeader);
- setColumnWidth ( 0, COLUMN_SIZE);
-
- //"Value" Column
- QTableWidgetItem * aValueHeader = new QTableWidgetItem();
- aValueHeader->setText(tr("VARVALUE_COLUMN"));
- aValueHeader->setFont(aFont);
- setHorizontalHeaderItem(1,aValueHeader);
- setColumnWidth ( 1, COLUMN_SIZE);
- setSortingEnabled(false);
+ // "Variable" column
+ QTableWidgetItem* aVariableHeader = new QTableWidgetItem();
+ aVariableHeader->setText( tr( "VARIABLE" ) );
+ aVariableHeader->setFont( aFont );
+ setHorizontalHeaderItem( VARIABLE_COLUMN, aVariableHeader );
+ setColumnWidth( VARIABLE_COLUMN, VARIABLE_COLUMN_SIZE );
+
+ // "Expression" column
+ QTableWidgetItem* anExpressionHeader = new QTableWidgetItem();
+ anExpressionHeader->setText( tr( "EXPRESSION" ) );
+ anExpressionHeader->setFont( aFont );
+ setHorizontalHeaderItem( EXPRESSION_COLUMN, anExpressionHeader );
+ setColumnWidth( EXPRESSION_COLUMN, EXPRESSION_COLUMN_SIZE );
+ setSortingEnabled( false );
+
+ // "Value" column
+ QTableWidgetItem* aValueHeader = new QTableWidgetItem();
+ aValueHeader->setText( tr( "VALUE" ) );
+ aValueHeader->setFont( aFont );
+ setHorizontalHeaderItem( VALUE_COLUMN, aValueHeader );
+ setColumnWidth( VALUE_COLUMN, VALUE_COLUMN_SIZE );
+ setSortingEnabled( false );
- connect(this,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(onItemChanged(QTableWidgetItem*)));
+ connect( this, SIGNAL( itemChanged( QTableWidgetItem* ) ),
+ this, SLOT( onItemChanged( QTableWidgetItem* ) ) );
}
//============================================================================
* Purpose : Destructor
*/
//============================================================================
-NoteBook_Table::~NoteBook_Table(){}
+NoteBook_Table::~NoteBook_Table()
+{
+ clear();
+}
-void NoteBook_Table::printVariableMap()
+//============================================================================
+/*! Function : clear
+ * Purpose : Clear contents of the table
+ */
+//============================================================================
+void NoteBook_Table::clear()
{
- printf( "VariableMap:\n" );
- VariableMap::const_iterator it = myVariableMap.constBegin(), itEnd = myVariableMap.constEnd();
- for( ; it != itEnd; ++it )
+ bool isBlocked = blockSignals( true );
+ for( int i = 0, n = myRows.size(); i < n; i++ )
{
- int anIndex = it.key();
- const NoteBoox_Variable& aVariable = it.value();
- QString aName = aVariable.Name;
- QString aValue = aVariable.Value;
- printf( "%d - %s - %s\n", anIndex, aName.toLatin1().constData(), aValue.toLatin1().constData() );
+ if( NoteBook_TableRow* aRow = myRows[ i ] )
+ {
+ delete aRow;
+ aRow = 0;
+ }
}
+ myRows.clear();
+ setRowCount( 0 );
+ blockSignals( isBlocked );
}
//============================================================================
void NoteBook_Table::markItem( NoteBook_TableRow* theRow, int theColumn, bool theIsCorrect )
{
if( QTableWidgetItem* anItem =
- theColumn == NAME_COLUMN ? theRow->GetNameItem() : theRow->GetVariableItem() )
+ theColumn == VARIABLE_COLUMN ? theRow->GetVariableItem() :
+ theColumn == EXPRESSION_COLUMN ? theRow->GetExpressionItem() : theRow->GetValueItem() )
{
bool isBlocked = blockSignals( true );
anItem->setForeground( QBrush( theIsCorrect ? Qt::black : Qt::red ) );
}
}
+//============================================================================
+/*! Function : markRow
+ * Purpose : Mark the given row by red or black color
+ * (red color means incorrect value, black - correct)
+ */
+//============================================================================
+void NoteBook_Table::markRow( NoteBook_TableRow* theRow, bool theIsCorrect )
+{
+ markItem( theRow, VARIABLE_COLUMN, theIsCorrect );
+ markItem( theRow, EXPRESSION_COLUMN, theIsCorrect );
+ markItem( theRow, VALUE_COLUMN, theIsCorrect );
+}
+
//============================================================================
/*! Function : checkItem
- * Purpose : Check validity of item by its color
+ * Purpose : Check validity of the item by its color
*/
//============================================================================
-bool NoteBook_Table::checkItem( QTableWidgetItem* theItem ) const
+bool NoteBook_Table::checkItem( NoteBook_TableRow* theRow, int theColumn ) const
{
- return theItem->foreground().color() == Qt::black;
+ if( QTableWidgetItem* anItem =
+ theColumn == VARIABLE_COLUMN ? theRow->GetVariableItem() :
+ theColumn == EXPRESSION_COLUMN ? theRow->GetExpressionItem() : theRow->GetValueItem() )
+ return anItem->foreground().color() == Qt::black;
+ return false;
}
//============================================================================
-/*! Function : Init
- * Purpose : Add variables in the table from theNoteBook
+/*! Function : checkRow
+ * Purpose : Check validity of the row by a color of its first item
*/
//============================================================================
-void NoteBook_Table::Init(SalomeApp_Notebook* theNoteBook)
+bool NoteBook_Table::checkRow( NoteBook_TableRow* theRow ) const
{
- bool isBlocked = blockSignals( true );
+ return checkItem( theRow, VARIABLE_COLUMN ) &&
+ checkItem( theRow, EXPRESSION_COLUMN ) &&
+ checkItem( theRow, VALUE_COLUMN );
+}
- int aNumRows = myRows.count();
- if( aNumRows > 0 )
+//============================================================================
+/*! Function : correctData
+ * Purpose : Try to correct data of the table
+ */
+//============================================================================
+void NoteBook_Table::correctData( int theBaseRowIndex )
+{
+ for( int i = 0, n = myRows.size(); i < n; i++ )
{
- for( int i = 0; i < myRows.size(); i++ )
+ if( NoteBook_TableRow* aRow = myRows[ i ] )
{
- NoteBook_TableRow* aRow = myRows[ i ];
- if( aRow )
+ if( aRow->GetIndex() != theBaseRowIndex )
{
- delete aRow;
- aRow = 0;
+ QString aName = aRow->GetVariable();
+ QString anExpression = myNoteBook->expression( aName );
}
}
- myRows.clear();
}
- setRowCount( 0 );
+}
+
+//============================================================================
+/*! Function : updateExpressions
+ * Purpose : Update variable expressions according to myNoteBook data
+ * (used after renaming or removing of some variable)
+ */
+//============================================================================
+void NoteBook_Table::updateExpressions( int theBaseRowIndex )
+{
+ bool isBlocked = blockSignals( true );
+ for( int i = 0, n = myRows.size(); i < n; i++ )
+ {
+ if( NoteBook_TableRow* aRow = myRows[ i ] )
+ {
+ if( aRow->GetIndex() != theBaseRowIndex )
+ {
+ QString aName = aRow->GetVariable();
+ QString anExpression = myNoteBook->expression( aName );
+ aRow->SetExpression( anExpression );
+ }
+ }
+ }
+ blockSignals( isBlocked );
+}
+
+//============================================================================
+/*! Function : updateValues
+ * Purpose : Update variable values according to myNoteBook data
+ */
+//============================================================================
+void NoteBook_Table::updateValues()
+{
+ bool isBlocked = blockSignals( true );
+ for( int i = 0, n = myRows.size(); i < n; i++ )
+ {
+ if( NoteBook_TableRow* aRow = myRows[ i ] )
+ {
+ QString aName = aRow->GetVariable();
+ QVariant aValue = myNoteBook->get( aName );
+ aRow->SetValue( aValue.toString() );
+ }
+ }
+ blockSignals( isBlocked );
+}
+
+//============================================================================
+/*! Function : setExpression
+ * Purpose : Try to set expression of the variable
+ */
+//============================================================================
+bool NoteBook_Table::setExpression( const QString& theName,
+ const QString& theExpression,
+ bool theIsNew,
+ QString& theErrorType,
+ QString& theErrorMessage )
+{
+ theErrorType.clear();
+ theErrorMessage.clear();
+ int iVal;
+ double dVal;
+ bool bVal;
+ try
+ {
+ if( NoteBook_TableRow::IsIntegerValue( theExpression, &iVal ) )
+ myNoteBook->set( theName, iVal, theIsNew );
+ else if( NoteBook_TableRow::IsRealValue( theExpression, &dVal ) )
+ myNoteBook->set( theName, dVal, theIsNew );
+ else if( NoteBook_TableRow::IsBooleanValue( theExpression, &bVal ) )
+ myNoteBook->set( theName, bVal, theIsNew );
+ else if( NoteBook_TableRow::IsValidStringValue( theExpression ) )
+ myNoteBook->set( theName, theExpression, theIsNew );
+ }
+ catch( const SALOME::NotebookError& ex ) {
+ theErrorType = tr( "NOTEBOOK_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ } catch( const SALOME::ExpressionError& ex ) {
+ theErrorType = tr( "EXPRESSION_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ } catch( const SALOME::CalculationError& ex ) {
+ theErrorType = tr( "CALCULATION_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ } catch( const SALOME::TypeError& ex ) {
+ theErrorType = tr( "TYPE_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ }
+
+ return theErrorType.isEmpty();
+}
+
+//============================================================================
+/*! Function : setExpression
+ * Purpose : Try to rename the variable
+ */
+//============================================================================
+bool NoteBook_Table::renameVariable( const QString& theOldName,
+ const QString& theNewName,
+ QString& theErrorType,
+ QString& theErrorMessage )
+{
+ theErrorType.clear();
+ theErrorMessage.clear();
+
+ try
+ {
+ myNoteBook->rename( theOldName, theNewName );
+ }
+ catch( const SALOME::NotebookError& ex ) {
+ theErrorType = tr( "NOTEBOOK_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ } catch( const SALOME::ExpressionError& ex ) {
+ theErrorType = tr( "EXPRESSION_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ } catch( const SALOME::CalculationError& ex ) {
+ theErrorType = tr( "CALCULATION_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ } catch( const SALOME::TypeError& ex ) {
+ theErrorType = tr( "TYPE_ERROR" );
+ theErrorMessage = ex.Reason.in();
+ }
+
+ return theErrorType.isEmpty();
+}
+
+//============================================================================
+/*! Function : Init
+ * Purpose : Add variables in the table from theNoteBook
+ */
+//============================================================================
+void NoteBook_Table::Init( SalomeApp_Notebook* theNoteBook )
+{
+ myNoteBook = theNoteBook;
+
+ bool isBlocked = blockSignals( true );
+
+ clear();
myVariableMap.clear();
- //Add all variables into the table
- QStringList aVariables = theNoteBook->parameters();
+ // Add all variables into the table
+ QStringList aVariables = myNoteBook->parameters();
QStringListIterator anIter( aVariables );
while( anIter.hasNext() )
{
QString aVariable = anIter.next();
- QString aVariableValue = theNoteBook->get(aVariable).toString();
+ if( aVariable.left( 2 ).compare( "__" ) == 0 ) // tmp variable
+ continue;
+ QString aVariableValue = myNoteBook->expression(aVariable);
AddRow( aVariable, aVariableValue );
}
- //Add empty row
+ // Add empty row
AddRow();
- myNoteBook = theNoteBook;
+ updateValues();
blockSignals( isBlocked );
}
if( aNumRows == 0 )
return true;
- if( !myRows[ aNumRows - 1 ]->GetName().isEmpty() ||
+ if( !myRows[ aNumRows - 1 ]->GetVariable().isEmpty() ||
+ !myRows[ aNumRows - 1 ]->GetExpression().isEmpty() ||
!myRows[ aNumRows - 1 ]->GetValue().isEmpty() )
return false;
- for( int aRow = 0, aRowCount = rowCount(); aRow < aRowCount; aRow++ )
- for( int aCol = 0, aColCount = columnCount(); aCol < aColCount; aCol++ )
- if( QTableWidgetItem* anItem = item( aRow, aCol ) )
- if( !checkItem( anItem ) )
- return false;
+ for( int i = 0, n = myRows.size(); i < n; i++ )
+ if( NoteBook_TableRow* aRow = myRows[ i ] )
+ if( !checkRow( aRow ) )
+ return false;
return true;
}
* Purpose : Add a row into the table
*/
//============================================================================
-void NoteBook_Table::AddRow(const QString& theName, const QString& theValue)
+void NoteBook_Table::AddRow( const QString& theName, const QString& theExpression )
{
int anIndex = getUniqueIndex();
- NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this);
- aRow->SetName(theName);
- aRow->SetValue(theValue);
- aRow->AddToTable(this);
- myRows.append(aRow);
+ NoteBook_TableRow* aRow = new NoteBook_TableRow( anIndex, this );
+ aRow->SetVariable( theName );
+ aRow->SetExpression( theExpression );
+ aRow->AddToTable( this );
+ myRows.append( aRow );
- myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theValue ) );
+ myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theExpression ) );
}
//============================================================================
* Purpose :
*/
//============================================================================
-NoteBook_TableRow* NoteBook_Table::GetRowByItem(const QTableWidgetItem* theItem) const
+NoteBook_TableRow* NoteBook_Table::GetRowByItem( const QTableWidgetItem* theItem ) const
{
- int aCurrentRow = row(theItem);
-
- if( (myRows.size() <= aCurrentRow ) && (aCurrentRow < 0))
- return NULL;
- else
- return myRows.at(aCurrentRow);
+ int aCurrentRow = row( theItem );
+ if( aCurrentRow >= 0 && aCurrentRow < myRows.size() )
+ return myRows.at( aCurrentRow );
+ return NULL;
}
//============================================================================
* 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 (myRows.last() == theRow);
+ return theRow == myRows.last();
}
//============================================================================
* Purpose : [slot] called then table item changed
*/
//============================================================================
-void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem)
+void NoteBook_Table::onItemChanged( QTableWidgetItem* theItem )
{
- //printf( "onItemChanged( %d, %d )\n", theItem->row(), theItem->column() );
-
- //printf( "Before:\n" );
- //printVariableMap();
-
NoteBook_TableRow* aRow = GetRowByItem( theItem );
if( !aRow )
return;
return;
NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];
+ QString aNamePrevious = aVariable.Name;
+ QString anExpressionPrevious = aVariable.Expression;
+ bool isCompletePrevious = !aVariable.Name.isEmpty() && !aVariable.Expression.isEmpty();
+
+ bool isCorrectPrevious = checkRow( aRow );
+ markRow( aRow, true );
+
+ QString aName = aRow->GetVariable();
+ QString anExpression = aRow->GetExpression();
+ bool isComplete = !aName.isEmpty() && !anExpression.isEmpty();
- QString aName = aRow->GetName();
- QString aValue = aRow->GetValue();
- bool isComplete = !aName.isEmpty() && !aValue.isEmpty();
+ aVariable.Name = aName;
+ aVariable.Expression = anExpression;
QString anErrorType, anErrorMessage;
int aCurrentColumn = column( theItem );
- if( aCurrentColumn == NAME_COLUMN )
+ if( aCurrentColumn == VARIABLE_COLUMN && isCompletePrevious && isCorrectPrevious && aName != aNamePrevious )
{
- if( !aVariable.Name.isEmpty() && !aVariable.Value.isEmpty() && aName != aVariable.Name)
- { // just rename and return
- try
- {
- myNoteBook->rename( aVariable.Name, aName );
- }
- catch( const SALOME::NotebookError& ex ) {
- anErrorType = tr( "NOTEBOOK_ERROR" );
- anErrorMessage = ex.Reason.in();
- } catch( const SALOME::ExpressionError& ex ) {
- anErrorType = tr( "EXPRESSION_ERROR" );
- anErrorMessage = ex.Reason.in();
- } catch( const SALOME::CalculationError& ex ) {
- anErrorType = tr( "CALCULATION_ERROR" );
- anErrorMessage = ex.Reason.in();
- } catch( const SALOME::TypeError& ex ) {
- anErrorType = tr( "TYPE_ERROR" );
- anErrorMessage = ex.Reason.in();
- }
-
- if( !anErrorType.isEmpty() )
- {
- SUIT_MessageBox::warning( this, anErrorType, anErrorMessage );
-
- //aRow->SetValue( aVariable.Value );
- markItem( aRow, aCurrentColumn, false );
-
- return;
- }
+ if( !renameVariable( aNamePrevious, aName, anErrorType, anErrorMessage ) )
+ {
+ SUIT_MessageBox::warning( this, anErrorType, anErrorMessage );
+ markRow( aRow, false );
+ return;
}
- aVariable.Name = aName;
- return;
+ updateExpressions( anIndex );
+ return; // not necessary to update notebook data after renaming
}
if( isComplete )
{
- int iVal;
- double dVal;
- bool bVal;
- QString anErrorType, anErrorMessage;
- try
- {
- //printf( "myNoteBook->set( %s, %s )\n", aName.toLatin1().constData(), aValue.toLatin1().constData() );
- if( NoteBook_TableRow::IsIntegerValue( aValue, &iVal ) )
- myNoteBook->set( aName, iVal );
- else if( NoteBook_TableRow::IsRealValue( aValue, &dVal ) )
- myNoteBook->set( aName, dVal );
- else if( NoteBook_TableRow::IsBooleanValue( aValue, &bVal ) )
- myNoteBook->set( aName, bVal );
- else if( NoteBook_TableRow::IsValidStringValue( aValue ) )
- myNoteBook->set( aName, aValue );
- aVariable.Value = aValue;
- }
- catch( const SALOME::NotebookError& ex ) {
- anErrorType = tr( "NOTEBOOK_ERROR" );
- anErrorMessage = ex.Reason.in();
- } catch( const SALOME::ExpressionError& ex ) {
- anErrorType = tr( "EXPRESSION_ERROR" );
- anErrorMessage = ex.Reason.in();
- } catch( const SALOME::CalculationError& ex ) {
- anErrorType = tr( "CALCULATION_ERROR" );
- anErrorMessage = ex.Reason.in();
- } catch( const SALOME::TypeError& ex ) {
- anErrorType = tr( "TYPE_ERROR" );
- anErrorMessage = ex.Reason.in();
- }
-
- if( !anErrorType.isEmpty() )
+ if( !setExpression( aName, anExpression, !isCompletePrevious, anErrorType, anErrorMessage ) )
{
SUIT_MessageBox::warning( this, anErrorType, anErrorMessage );
-
- //aRow->SetValue( aVariable.Value );
- markItem( aRow, aCurrentColumn, false );
-
+ markRow( aRow, false );
return;
}
+ myNoteBook->update( true );
+ updateValues();
}
- markItem( aRow, NAME_COLUMN, true );
- markItem( aRow, VALUE_COLUMN, true );
-
- if( IsLastRow( aRow ) ) // && isComplete
+ if( IsLastRow( aRow ) && isComplete )
{
bool isBlocked = blockSignals( true );
AddRow();
blockSignals( isBlocked );
}
-
- //printf( "After:\n" );
- //printVariableMap();
}
//============================================================================
{
if( IsLastRow( aRow ) )
{
- aRow->SetName( QString() );
- aRow->SetValue( QString() );
+ aRow->SetVariable( QString() );
+ aRow->SetExpression( QString() );
}
else
{
- int nRow = row( anItem );
- int index = aRow->GetIndex();
-
- QString aName = aRow->GetName();
- if( myVariableMap.contains( index ) )
- myVariableMap.remove( index );
+ int anIndex = aRow->GetIndex();
+ QString aName = aRow->GetVariable();
+ if( myVariableMap.contains( anIndex ) )
+ myVariableMap.remove( anIndex );
+ int nRow = row( anItem );
removeRow( nRow );
myRows.removeAt( nRow );
myNoteBook->remove( aName );
+ updateExpressions( anIndex );
}
}
// renumber header items
- for( int i = 0; i < myRows.size(); i++ )
- myRows[i]->GetHeaderItem()->setText( QString::number( i+1 ) );
+ for( int i = 0, n = myRows.size(); i < n; i++ )
+ myRows[i]->GetRowHeaderItem()->setText( QString::number( i+1 ) );
}
blockSignals( isBlocked );
* Purpose : Constructor
*/
//============================================================================
-SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg(QWidget* parent, SalomeApp_Study* theStudy):
- QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
- myNoteBook(0)
+SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg( QWidget* parent, SalomeApp_Study* theStudy )
+ : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
+ myNoteBook( 0 )
{
- setModal(false);
- setObjectName("SalomeApp_NoteBookDlg");
- setWindowTitle(tr("NOTEBOOK_TITLE"));
+ setModal( false );
+ setWindowTitle( tr( "NOTEBOOK_TITLE" ) );
- QGridLayout* aLayout = new QGridLayout(this);
- aLayout->setMargin(DEFAULT_MARGIN);
- aLayout->setSpacing(DEFAULT_SPACING);
-
- //Table
- myTable = new NoteBook_Table(this);
- aLayout->addWidget(myTable, 0, 0, 1, 3);
+ // Table
+ myTable = new NoteBook_Table( this );
- //Buttons
- myRemoveButton = new QPushButton(tr("BUT_REMOVE"));
- aLayout->addWidget(myRemoveButton, 1, 0, 1, 1);
-
- QSpacerItem* spacer =
- new QSpacerItem(DEFAULT_SPACING, 5 , QSizePolicy::Expanding, QSizePolicy::Minimum);
- aLayout->addItem(spacer, 1, 1, 2, 1);
-
- myUpdateStudyBtn = new QPushButton(tr("BUT_UPDATE_STUDY"));
- aLayout->addWidget(myUpdateStudyBtn, 1, 2, 1, 1);
+ // Buttons
+ QPushButton* aRemoveBtn = new QPushButton( tr( "BUT_REMOVE" ) );
+ QSpacerItem* aSpacer1 = new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ QPushButton* aDumpBtn = new QPushButton( tr( "BUT_DUMP" ) );
+ QPushButton* anUpdateStudyBtn = new QPushButton( tr( "BUT_UPDATE_STUDY" ) );
- QGroupBox* groupBox = new QGroupBox(this);
-
- QBoxLayout* aLayout1 = new QHBoxLayout(groupBox);
-
- aLayout1->setMargin(DEFAULT_MARGIN);
- aLayout1->setSpacing(DEFAULT_SPACING);
-
- myCloseBtn = new QPushButton(tr("BUT_CLOSE"));
- aLayout1->addWidget(myCloseBtn);
-
- QSpacerItem* spacer1 =
- new QSpacerItem(DEFAULT_SPACING, 5, QSizePolicy::Expanding, QSizePolicy::Minimum);
- aLayout1->addItem(spacer1);
-
- myHelpBtn = new QPushButton(tr("BUT_HELP"));
- aLayout1->addWidget(myHelpBtn);
+ QGroupBox* aGroupBox = new QGroupBox( this );
+
+ QPushButton* aCloseBtn = new QPushButton( tr( "BUT_CLOSE" ) );
+ QSpacerItem* aSpacer2 = new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ QPushButton* aHelpBtn = new QPushButton( tr( "BUT_HELP" ) );
+
+ QBoxLayout* aLayout = new QHBoxLayout( aGroupBox );
+ aLayout->setMargin( 11 );
+ aLayout->setSpacing( 6 );
+ aLayout->addWidget( aCloseBtn );
+ aLayout->addItem( aSpacer2 );
+ aLayout->addWidget( aHelpBtn );
- aLayout->addWidget(groupBox, 2, 0, 1, 3);
-
- setMinimumWidth( 2 * COLUMN_SIZE + 50 );
+ QGridLayout* aTopLayout = new QGridLayout( this );
+ aTopLayout->setMargin( 11 );
+ aTopLayout->setSpacing( 6 );
+ aTopLayout->addWidget( myTable, 0, 0, 1, 4 );
+ aTopLayout->addWidget( aRemoveBtn, 1, 0, 1, 1 );
+ aTopLayout->addItem( aSpacer1, 1, 1, 2, 1 );
+ aTopLayout->addWidget( aDumpBtn, 1, 2, 1, 1 );
+ aTopLayout->addWidget( anUpdateStudyBtn, 1, 3, 1, 1 );
+ aTopLayout->addWidget( aGroupBox, 2, 0, 1, 4 );
+
+ setMinimumWidth( VARIABLE_COLUMN_SIZE +
+ EXPRESSION_COLUMN_SIZE +
+ VALUE_COLUMN_SIZE +
+ GAP_SIZE );
QWidgetList aWidgetList;
aWidgetList.append( myTable );
- aWidgetList.append( myRemoveButton );
- aWidgetList.append( myUpdateStudyBtn );
- aWidgetList.append( myCloseBtn );
- aWidgetList.append( myHelpBtn );
+ aWidgetList.append( aRemoveBtn );
+ aWidgetList.append( aDumpBtn );
+ aWidgetList.append( anUpdateStudyBtn );
+ aWidgetList.append( aCloseBtn );
+ aWidgetList.append( aHelpBtn );
Qtx::setTabOrder( aWidgetList );
- connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
- connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) );
- connect( myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()) );
- connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
+ connect( aRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemove() ) );
+ connect( aDumpBtn, SIGNAL( clicked() ), this, SLOT( onDump() ) );
+ connect( anUpdateStudyBtn, SIGNAL( clicked() ), this, SLOT( onUpdateStudy() ) );
+ connect( aCloseBtn, SIGNAL( clicked() ), this, SLOT( onClose() ) );
+ connect( aHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
+ //aDumpBtn->hide();
+
Init( theStudy );
}
* 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 )
myTable->RemoveSelected();
}
+//============================================================================
+/*! Function : onDump
+ * Purpose : [slot]
+ */
+//============================================================================
+void SalomeApp_NoteBookDlg::onDump()
+{
+ SUIT_MessageBox::information( this, tr( "NOTEBOOK_TITLE" ), QString( myNoteBook->dump() ) );
+}
+
//============================================================================
/*! Function : onUpdateStudy
* Purpose : [slot]
//============================================================================
void SalomeApp_NoteBookDlg::onUpdateStudy()
{
- //printf( "Notebook:\n%s", myNoteBook->dump() );
- //printf( "-----------------------------------------\n" );
- //return;
-
- //onApply();
if( !myTable->IsValid() )
+ {
+ SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "INCORRECT_DATA_ON_UPDATE" ) );
return;
+ }
QApplication::setOverrideCursor( Qt::WaitCursor );
-
myNoteBook->update( false );
- //SUIT_MessageBox::warning( this, tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) );
-
QApplication::restoreOverrideCursor();
}
void SalomeApp_NoteBookDlg::onClose()
{
if( !myTable->IsValid() &&
- SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA" ),
- QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) != QMessageBox::Ok )
+ SUIT_MessageBox::question( this, tr( "CLOSE_CAPTION" ), tr( "INCORRECT_DATA_ON_CLOSE" ),
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel ) != QMessageBox::Ok )
return;
+
+ // update only variables
+ myNoteBook->update( true );
+
accept();
}
//============================================================================
void SalomeApp_NoteBookDlg::onHelp()
{
- QString aHelpFileName("using_notebook.html");
- LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
- if (app)
- app->onHelpContextModule("GUI",aHelpFileName);
- else {
+ QString aHelpFileName( "using_notebook.html" );
+ LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
+ if( app )
+ app->onHelpContextModule( "GUI", aHelpFileName );
+ else
+ {
QString platform;
#ifdef WIN32
platform = "winapplication";
#else
platform = "application";
#endif
- SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
- tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
- arg(app->resourceMgr()->stringValue("ExternalBrowser",
- platform)).
- arg(aHelpFileName));
+ SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
+ tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
+ arg( app->resourceMgr()->stringValue("ExternalBrowser", platform ) ).
+ arg( aHelpFileName ) );
}
}