From 6fa98a41c5b6f87e44b3b927e99a310979b2c6e6 Mon Sep 17 00:00:00 2001 From: dmv Date: Fri, 23 Apr 2010 07:56:17 +0000 Subject: [PATCH] IPAL21703 TC5.1.4: Salome NoteBook dialog validation --- src/SalomeApp/SalomeApp_NoteBookDlg.cxx | 33 ++++++++++++++++++++----- src/SalomeApp/SalomeApp_NoteBookDlg.h | 9 ++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index 1586e89b6..061976175 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -74,8 +74,9 @@ using namespace std; * Purpose : Constructor */ //============================================================================ -NoteBook_TableRow::NoteBook_TableRow(int index, QWidget* parent): +NoteBook_TableRow::NoteBook_TableRow(int index, NoteBook_Table* parentTable, QWidget* parent): QWidget(parent), + myParentTable(parentTable), myIndex(index), myRowHeader(new QTableWidgetItem()), myVariableName(new QTableWidgetItem()), @@ -280,7 +281,28 @@ bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult) //============================================================================ bool NoteBook_TableRow::IsValidStringValue(const QString theValue) { - return true; + int aNumRows = myParentTable->myRows.count(); + if( aNumRows == 0 ) + return true; + + bool aLastRowIsEmpty = myParentTable->myRows[ aNumRows - 1 ]->GetName().isEmpty() && + myParentTable->myRows[ aNumRows - 1 ]->GetValue().isEmpty(); + + SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); + PyConsole_Console* pyConsole = app->pythonConsole(); + PyConsole_Interp* pyInterp = pyConsole->getInterp(); + PyLockWrapper aLock = pyInterp->GetLockWrapper(); + string command = "import salome_notebook ; "; + command += "salome_notebook.checkThisNoteBook("; + for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ ) { + command += myParentTable->myRows[i]->GetName().toStdString(); + command += "=\""; + command += myParentTable->myRows[i]->GetValue().toStdString(); + command += "\", "; + } + command += ") "; + bool aResult = pyInterp->run(command.c_str()); + return !aResult; } /////////////////////////////////////////////////////////////////////////// @@ -451,8 +473,7 @@ bool NoteBook_Table::IsValid() const } command += ")"; bool aResult = pyInterp->run(command.c_str()); - aResult = !aResult; - return aResult; + return !aResult; } //============================================================================ @@ -474,7 +495,7 @@ void NoteBook_Table::RenamberRowItems(){ void NoteBook_Table::AddRow(const QString& theName, const QString& theValue) { int anIndex = getUniqueIndex(); - NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this); + NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this, this); aRow->SetName(theName); aRow->SetValue(theValue); aRow->AddToTable(this); @@ -920,7 +941,7 @@ void SalomeApp_NoteBookDlg::onApply() else if( NoteBook_TableRow::IsBooleanValue(aValue,&aBVal) ) myStudy->SetBoolean(string(aName.toLatin1().constData()),aBVal); - else if( NoteBook_TableRow::IsValidStringValue(aValue) ) + else myStudy->SetString(string(aName.toLatin1().constData()),aValue.toStdString()); } } diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index ea11b050c..5fbfa2d74 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -36,6 +36,7 @@ class QWidget; class QPushButton; class QTableWidgetItem; +class NoteBook_Table; struct NoteBoox_Variable { @@ -54,7 +55,7 @@ typedef QMap< int, NoteBoox_Variable > VariableMap; class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget { public: - NoteBook_TableRow(int, QWidget* parent=0); + NoteBook_TableRow(int, NoteBook_Table* parentTable, QWidget* parent=0 ); virtual ~NoteBook_TableRow(); int GetIndex() const { return myIndex; } @@ -77,10 +78,11 @@ class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget 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); + bool IsValidStringValue(const QString theName); private: int myIndex; + NoteBook_Table* myParentTable; QTableWidgetItem* myRowHeader; QTableWidgetItem* myVariableName; QTableWidgetItem* myVariableValue; @@ -120,6 +122,8 @@ class SALOMEAPP_EXPORT NoteBook_Table : public QTableWidget void ResetMaps(); + QList myRows; + public slots: void onItemChanged(QTableWidgetItem* theItem); @@ -128,7 +132,6 @@ class SALOMEAPP_EXPORT NoteBook_Table : public QTableWidget private: bool isProcessItemChangedSignal; - QList myRows; bool myIsModified; QList myRemovedRows; -- 2.39.2