From: rnv Date: Thu, 30 Oct 2008 14:19:06 +0000 (+0000) Subject: Improve NoteBook dialog. X-Git-Tag: TG_DumpPython_Extension_1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ee882876729a8e12d5d9c21f2568f1dc79f45eb1;p=modules%2Fgui.git Improve NoteBook dialog. --- diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index f9757e875..d1f303129 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -240,7 +240,7 @@ void SalomeApp_Application::createActions() //! NoteBook createAction(NoteBookId, tr( "TOT_DESK_FILE_NOTEBOOK" ), QIcon(), tr( "MEN_DESK_FILE_NOTEBOOK" ), tr( "PRP_DESK_FILE_NOTEBOOK" ), - Qt::CTRL+Qt::Key_B, desk, false, this, SLOT(onNoteBook())); + /*Qt::CTRL+Qt::Key_B*/0, desk, false, this, SLOT(onNoteBook())); //! Load script createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIcon(), diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx index b4e551677..c2ffe980d 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.cxx +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.cxx @@ -21,6 +21,7 @@ // Module : GUI #include "SalomeApp_NoteBookDlg.h" +#include #include #include @@ -29,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -37,25 +40,44 @@ using namespace std; #define DEFAULT_MARGIN 11 #define DEFAULT_SPACING 6 -#define SPACER_SIZE 30 -#define COLUMN_SIZE 175 +#define SPACER_SIZE 120 +#define COLUMN_SIZE 180 + +#define NAME_COLUMN 0 +#define VALUE_COLUMN 1 /////////////////////////////////////////////////////////////////////////// // NoteBook_TableRow class // /////////////////////////////////////////////////////////////////////////// +//============================================================================ +/*! Function : NoteBook_TableRow + * Purpose : Constructor + */ +//============================================================================ NoteBook_TableRow::NoteBook_TableRow(QWidget* parent): QWidget(parent), myRowHeader(new QTableWidgetItem()), myVariableName(new QTableWidgetItem()), - myVariableValue(new QTableWidgetItem()) + myVariableValue(new QTableWidgetItem()), + isNameEditable(true) { } +//============================================================================ +/*! Function : ~NoteBook_TableRow + * Purpose : Destructor + */ +//============================================================================ NoteBook_TableRow::~NoteBook_TableRow() { } +//============================================================================ +/*! Function : AddToTable + * Purpose : Add this row to the table theTable + */ +//============================================================================ void NoteBook_TableRow::AddToTable(QTableWidget *theTable) { int aPosition = theTable->rowCount(); @@ -64,35 +86,226 @@ void NoteBook_TableRow::AddToTable(QTableWidget *theTable) myRowHeader->setText(QString::number(aRowCount)); theTable->setVerticalHeaderItem(aPosition,myRowHeader); - theTable->setItem(aPosition,0,myVariableName); - theTable->setItem(aPosition,1,myVariableValue); + theTable->setItem(aPosition, NAME_COLUMN, myVariableName); + theTable->setItem(aPosition, VALUE_COLUMN, myVariableValue); } -void NoteBook_TableRow::setEditable(bool enable) +//============================================================================ +/*! Function : SetNameEditable + * Purpose : Set item with variable name editable/not editable + * and change flag isNameEditable + */ +//============================================================================ +void NoteBook_TableRow::SetNameEditable(bool enable) { + isNameEditable = enable; + Qt::ItemFlags f = myVariableName->flags(); + f = f & (isNameEditable ? Qt::ItemIsEditable : ~Qt::ItemIsEditable); + myVariableName->setFlags(f); + //Mark all not editabe variable names + QFont aFont = QFont(); + aFont.setBold(true); + myVariableName->setFont(aFont); +} + +//============================================================================ +/*! Function : setValueEditable + * Purpose : Set item with variable value editable/not editable + */ +//============================================================================ +void NoteBook_TableRow::setValueEditable(bool enable) +{ + Qt::ItemFlags f = myVariableValue->flags(); + f = enable ? (f | Qt::ItemIsEditable) : (f & ~Qt::ItemIsEditable); + myVariableValue->setFlags(f); +} + +//============================================================================ +/*! Function : setNameEditable + * Purpose : Set item with variable name editable/not editable + */ +//============================================================================ +void NoteBook_TableRow::setNameEditable(bool enable) +{ + if(isNameEditable) { + Qt::ItemFlags f = myVariableName->flags(); + f = enable ? (f | Qt::ItemIsEditable) : (f & ~Qt::ItemIsEditable); + myVariableName->setFlags(f); + } } +//============================================================================ +/*! Function : SetName + * Purpose : + */ +//============================================================================ void NoteBook_TableRow::SetName(const QString theName) { myVariableName->setText(theName); } + +//============================================================================ +/*! Function : SetValue + * Purpose : + */ +//============================================================================ void NoteBook_TableRow::SetValue(const QString theValue) { myVariableValue->setText(theValue); } +//============================================================================ +/*! Function : GetName + * Purpose : Return variable name + */ +//============================================================================ +QString NoteBook_TableRow::GetName() const +{ + return myVariableName->text(); +} + +//============================================================================ +/*! Function : GetValue + * Purpose : Return variable value + */ +//============================================================================ +QString NoteBook_TableRow::GetValue() const +{ + return myVariableValue->text(); +} + +bool NoteBook_TableRow::IsNameEditable() +{ + return isNameEditable; +} + +bool NoteBook_TableRow::CheckName() +{ + bool aResult = false; + QString aName = GetName(); + if( !aName.isEmpty() ) + aResult = true; + + return aResult; +} + +//============================================================================ +/*! Function : GetValue + * Purpose : Return true if variable value correct, otherwise return false + */ +//============================================================================ +bool NoteBook_TableRow::CheckValue() +{ + bool aResult = false; + QString aValue = GetValue(); + if( (!aValue.isEmpty()) && + (IsRealValue(aValue)) || + IsIntegerValue(aValue)|| + IsBooleanValue(aValue)) + aResult = true; + + return aResult; +} + +//============================================================================ +/*! Function : GetVariableItem + * Purpose : + */ +//============================================================================ +QTableWidgetItem* NoteBook_TableRow::GetVariableItem() +{ + return myVariableValue; +} + +//============================================================================ +/*! Function : GetNameItem + * Purpose : + */ +//============================================================================ +QTableWidgetItem* NoteBook_TableRow::GetNameItem() +{ + return myVariableName; +} + +//============================================================================ +/*! Function : IsRealValue + * Purpose : Return true if theValue string is real value, otherwise return + * false + */ +//============================================================================ +bool NoteBook_TableRow::IsRealValue(const QString theValue, double* theResult) +{ + bool aResult = false; + double aDResult = theValue.toDouble(&aResult); + if(theResult) + *theResult = aDResult; + + return aResult; +} + +//============================================================================ +/*! Function : IsBooleanValue + * Purpose : Return true if theValue String is boolean value, otherwise return + * false + */ +//============================================================================ +bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){ + bool aResult = false; + bool aBResult; + if(theValue.compare("True") == 0) { + aBResult = true; + aResult = true; + } + else if(theValue.compare("False") == 0) { + aBResult = false; + aResult = true; + } + if(theResult) + *theResult = aBResult; + + return aResult; +} + +//============================================================================ +/*! Function : IsIntegerValue + * Purpose : Return true if theValue string is integer value, otherwise return + * false + */ +//============================================================================ +bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult) +{ + bool aResult = false; + int anIResult; + anIResult = theValue.toInt(&aResult); + + if(theResult) + *theResult = anIResult; + + return aResult; +} + + /////////////////////////////////////////////////////////////////////////// // NoteBook_Table class // /////////////////////////////////////////////////////////////////////////// +//============================================================================ +/*! Function : NoteBook_Table + * Purpose : Constructor + */ +//============================================================================ NoteBook_Table::NoteBook_Table(QWidget * parent) - :QTableWidget(parent) + :QTableWidget(parent), + isProcessItemChangedSignal(false), + myIncorrectItem(NULL) { setColumnCount(2); - + setSelectionMode(QAbstractItemView::SingleSelection); + //Add Headers Columns - QFont aFont = QFont( "Liberation Sans", 10); + QFont aFont = QFont(); aFont.setBold(true); + aFont.setPointSize(10); //"Name" column QTableWidgetItem * aNameHeader = new QTableWidgetItem(); @@ -110,36 +323,309 @@ NoteBook_Table::NoteBook_Table(QWidget * parent) setSortingEnabled(false); connect(this,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(onItemChanged(QTableWidgetItem*))); + connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(onItemSelectionChanged())); + } +//============================================================================ +/*! Function : ~NoteBook_Table + * Purpose : Destructor + */ +//============================================================================ NoteBook_Table::~NoteBook_Table(){} +//============================================================================ +/*! Function : Init + * Purpose : Add variables in the table from theStudy + */ +//============================================================================ void NoteBook_Table::Init(_PTR(Study) theStudy) { - //Add all variables into the table vector aVariables = theStudy->GetVariableNames(); for(int iVar = 0; iVar < aVariables.size() ; iVar++ ) { NoteBook_TableRow* aRow = new NoteBook_TableRow(this); aRow->SetName(QString(aVariables[iVar].c_str())); + aRow->SetValue( Variable2String(aVariables[iVar],theStudy) ); + aRow->SetNameEditable(false); aRow->AddToTable(this); + myRows.append(aRow); } //Add empty row + AddEmptyRow(); + isProcessItemChangedSignal = true; +} + +//============================================================================ +/*! Function : Variable2String + * Purpose : Convert variable values to QString + */ +//============================================================================ +QString NoteBook_Table::Variable2String(const string& theVarName, + _PTR(Study) theStudy) +{ + QString aResult; + if( theStudy->IsReal(theVarName) ) + aResult = QString::number(theStudy->GetReal(theVarName)); + else if( theStudy->IsInteger(theVarName) ) + aResult = QString::number(theStudy->GetInteger(theVarName)); + else if( theStudy->IsBoolean(theVarName) ) + aResult = theStudy->GetBoolean(theVarName) ? QString("True") : QString("False"); + + return aResult; +} + +//============================================================================ +/*! Function : SetIncorrectItem + * Purpose : + */ +//============================================================================ +void NoteBook_Table::SetIncorrectItem(QTableWidgetItem* theItem) +{ + if(!theItem) + return; + + myIncorrectItem = theItem; + isProcessItemChangedSignal = false; + NoteBook_TableRow* except = GetRowByItem(myIncorrectItem); + + for (int i = 0; i < myRows.size(); i++) { + myRows[i]->setNameEditable(false); + myRows[i]->setValueEditable(false); + } + if(except) { + if(column(theItem) == NAME_COLUMN ) + except->setNameEditable(true); + else if(column(theItem) == VALUE_COLUMN) + except->setValueEditable(true); + } + isProcessItemChangedSignal = true; + emit incorrectItemAdded(); +} - NoteBook_TableRow* aRow = new NoteBook_TableRow(this); +//============================================================================ +/*! Function : RemoveIncorrectItem + * Purpose : + */ +//============================================================================ +void NoteBook_Table::RemoveIncorrectItem() +{ + if(!myIncorrectItem) + return; + + isProcessItemChangedSignal = false; + for (int i = 0; i < myRows.size(); i++) { + myRows[i]->setNameEditable(true); + myRows[i]->setValueEditable(true); + } + + myIncorrectItem = NULL; + isProcessItemChangedSignal = true; + emit incorrectItemRemoved(); +} + +void NoteBook_Table::AddEmptyRow() +{ + isProcessItemChangedSignal = false; + NoteBook_TableRow* aRow = new NoteBook_TableRow(); + aRow->SetName(QString()); + aRow->SetValue(QString()); aRow->AddToTable(this); + myRows.append(aRow); + isProcessItemChangedSignal = true; } +//============================================================================ +/*! Function : GetRowByItem + * Purpose : + */ +//============================================================================ +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); +} + +//============================================================================ +/*! Function : IsLastRow + * Purpose : Return true if theRow is last row in the table + */ +//============================================================================ +bool NoteBook_Table::IsLastRow(const NoteBook_TableRow* theRow) const +{ + return (myRows.last() == theRow); +} + +//============================================================================ +/*! Function : onItemChanged + * Purpose : [slot] called then table item changed + */ +//============================================================================ void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem) { + if(isProcessItemChangedSignal) { + NoteBook_TableRow* aRow = GetRowByItem(theItem); + if(aRow) { + int aCurrentColumn = column(theItem); + bool IsVariableComplited = false; + + //Case then varible name changed. + if(aCurrentColumn == NAME_COLUMN) { + bool isVarNameCorrect = aRow->CheckName(); + if(!isVarNameCorrect) { + SUIT_MessageBox::warning((QWidget*)parent(), + tr( "WARNING" ), + tr( "VARNAME_INCORRECT" ).arg(aRow->GetName())); + SetIncorrectItem(theItem); + return; + } + if(!IsUniqueName(aRow)){ + SUIT_MessageBox::warning((QWidget*)parent(), + tr( "WARNING" ), + tr( "VARNAME_EXISTS" ).arg(aRow->GetName())); + SetIncorrectItem(theItem); + return; + } + IsVariableComplited = isVarNameCorrect & aRow->CheckValue(); + } + + //Case then varible value changed. + else if(aCurrentColumn == VALUE_COLUMN){ + bool isVarValueCorrect = aRow->CheckValue(); + if(!isVarValueCorrect) { + SUIT_MessageBox::warning((QWidget*)parent(), + tr( "WARNING" ), + tr( "VARVALUE_INCORRECT" ).arg(aRow->GetValue())); + SetIncorrectItem(theItem); + return; + } + IsVariableComplited = isVarValueCorrect & aRow->CheckName(); + } + + if(myIncorrectItem) + RemoveIncorrectItem(); + + if(IsVariableComplited && IsLastRow(aRow)) + AddEmptyRow(); + } + } +} +//============================================================================ +/*! Function : IsUniqueName + * Purpose : Return true if theName is unique name of the Variable + */ +//============================================================================ +bool NoteBook_Table::IsUniqueName(const NoteBook_TableRow* theRow) const +{ + for(int i=0; iGetName().compare(theRow->GetName()) == 0) + return false; + } + return true; } +//============================================================================ +/*! Function : onItemSelectionChanged + * Purpose : [slot] + */ +//============================================================================ +void NoteBook_Table::onItemSelectionChanged() +{ + bool aResult = true; + QList aSelectedItems = selectedItems(); + aResult &= (aSelectedItems.size() > 0); + + if(aResult) { + for(int i=0; i < aSelectedItems.size(); i++ ) { + NoteBook_TableRow* aRow = GetRowByItem(aSelectedItems[i]); + if(aRow) + aResult &= aRow->IsNameEditable(); + } + } + emit selectionChanged(aResult); +} + +//============================================================================ +/*! Function : RemoveSelected + * Purpose : Remove selected rows in the table + */ +//============================================================================ +void NoteBook_Table::RemoveSelected() +{ + isProcessItemChangedSignal = false; + QList aSelectedItems = selectedItems(); + if( !(aSelectedItems.size() > 0)) { + isProcessItemChangedSignal = true; + return; + } + + for(int i=0; i < aSelectedItems.size(); i++ ) { + NoteBook_TableRow* aRow = GetRowByItem(aSelectedItems[i]); + if(aRow) { + if(IsLastRow(aRow)) { + aRow->SetName(QString()); + aRow->SetValue(QString()); + } + else { + int nRow = row(aSelectedItems[i]); + removeRow(nRow); + myRows.removeAt(nRow); + } + if(aRow->GetVariableItem() == myIncorrectItem || + aRow->GetNameItem() == myIncorrectItem ) { + RemoveIncorrectItem(); + } + } + } + isProcessItemChangedSignal = true; +} + +//============================================================================ +/*! Function : SetProcessItemChangedSignalFlag + * Purpose : + */ +//============================================================================ +void NoteBook_Table::SetProcessItemChangedSignalFlag(const bool enable) +{ + isProcessItemChangedSignal = enable; +} + +//============================================================================ +/*! Function : GetProcessItemChangedSignalFlag + * Purpose : + */ +//============================================================================ +bool NoteBook_Table::GetProcessItemChangedSignalFlag() const +{ + return isProcessItemChangedSignal; +} + +//============================================================================ +/*! Function : GetRows + * Purpose : + */ +//============================================================================ +QList NoteBook_Table::GetRows() const +{ + return myRows; +} /////////////////////////////////////////////////////////////////////////// // SalomeApp_NoteBookDlg class // /////////////////////////////////////////////////////////////////////////// +//============================================================================ +/*! Function : SalomeApp_NoteBookDlg + * Purpose : Constructor + */ +//============================================================================ SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg(QWidget * parent, _PTR(Study) theStudy): QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), myStudy(theStudy) @@ -153,48 +639,154 @@ SalomeApp_NoteBookDlg::SalomeApp_NoteBookDlg(QWidget * parent, _PTR(Study) theSt //Table myTable = new NoteBook_Table(this); - aLayout->addWidget(myTable, 0, 0, 1, 5); + aLayout->addWidget(myTable, 0, 0, 1, 3); //Buttons - myOkBtn = new QPushButton(tr("BUT_OK")); - aLayout->addWidget(myOkBtn, 1, 0, 1, 1); - - myApplyBtn = new QPushButton(tr("BUT_APPLY")); - aLayout->addWidget(myApplyBtn, 1, 1, 1, 1); + myRemoveButton = new QPushButton(tr("BUT_REMOVE")); + aLayout->addWidget(myRemoveButton, 1, 0, 1, 1); + + QSpacerItem* spacer = + new QSpacerItem(SPACER_SIZE, 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); + QGroupBox* groupBox = new QGroupBox(this); - QSpacerItem* spacer = - new QSpacerItem(SPACER_SIZE, SPACER_SIZE, QSizePolicy::Expanding, QSizePolicy::Minimum); - aLayout->addItem(spacer, 1, 3, 1, 1); + QGridLayout* aLayout1 = new QGridLayout(groupBox); + + aLayout1->setMargin(DEFAULT_MARGIN); + aLayout1->setSpacing(DEFAULT_SPACING); + + myOkBtn = new QPushButton(tr("BUT_OK")); + aLayout1->addWidget(myOkBtn, 0, 0, 1, 1); + + myApplyBtn = new QPushButton(tr("BUT_APPLY")); + aLayout1->addWidget(myApplyBtn, 0, 1, 1, 1); + + QSpacerItem* spacer1 = + new QSpacerItem(SPACER_SIZE, 5, QSizePolicy::Expanding, QSizePolicy::Minimum); + aLayout1->addItem(spacer1, 0, 2, 1, 1); myCancelBtn = new QPushButton(tr("BUT_CANCEL")); - aLayout->addWidget(myCancelBtn, 1, 4, 1, 1); + aLayout1->addWidget(myCancelBtn, 0, 3, 1, 1); + + aLayout->addWidget(groupBox, 2, 0, 1, 3); connect( myOkBtn, SIGNAL(clicked()), this, SLOT(onOK()) ); connect( myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()) ); connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) ); connect( myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()) ); + connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove())); + + connect( myTable, SIGNAL(incorrectItemAdded()), this, SLOT(onIncorrectItemAdded())); + connect( myTable, SIGNAL(incorrectItemRemoved()), this, SLOT(onIncorrectItemRemoved())); + connect( myTable, SIGNAL(selectionChanged(bool)),this, SLOT(onTableSelectionChanged(bool))); myTable->Init(myStudy); + myUpdateStudyBtn->setEnabled(false); } - +//============================================================================ +/*! Function : ~SalomeApp_NoteBookDlg + * Purpose : Destructor + */ +//============================================================================ SalomeApp_NoteBookDlg::~SalomeApp_NoteBookDlg(){} -void SalomeApp_NoteBookDlg::onOK() + +//============================================================================ +/*! Function : onIncorrectItemAdded + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onIncorrectItemAdded() { + myOkBtn->setEnabled(false); + myApplyBtn->setEnabled(false); +} +//============================================================================ +/*! Function : onIncorrectItemRemoved + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onIncorrectItemRemoved() +{ + myOkBtn->setEnabled(true); + myApplyBtn->setEnabled(true); } -void SalomeApp_NoteBookDlg::onApply() +//============================================================================ +/*! Function : onTableSelectionChanged + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onTableSelectionChanged(bool flag) +{ + myRemoveButton->setEnabled(flag); +} + +//============================================================================ +/*! Function : onRemove + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onRemove() +{ + myTable->RemoveSelected(); +} + +//============================================================================ +/*! Function : onOK + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onOK() { + onApply(); + hide(); +} +//============================================================================ +/*! Function : onApply + * Purpose : [slot] + */ +//============================================================================ +void SalomeApp_NoteBookDlg::onApply() +{ + QList aRows = myTable->GetRows(); + double aDVal; + int anIVal; + bool aBVal; + int i = 0; + myTable->SetProcessItemChangedSignalFlag(false); + + for(;iGetValue(),&anIVal) ) + myStudy->SetInteger(string(aRows[i]->GetName().toLatin1().constData()),anIVal); + + else if( NoteBook_TableRow::IsRealValue(aRows[i]->GetValue(),&aDVal) ) + myStudy->SetReal(string(aRows[i]->GetName().toLatin1().constData()),aDVal); + + else if( NoteBook_TableRow::IsBooleanValue(aRows[i]->GetValue(),&aBVal) ) + myStudy->SetBoolean(string(aRows[i]->GetName().toLatin1().constData()),aBVal); + + if( aRows[i]->IsNameEditable()) + aRows[i]->SetNameEditable(false); + } + myTable->SetProcessItemChangedSignalFlag(true); } + +//============================================================================ +/*! Function : onUpdateStudy + * Purpose : [slot] + */ +//============================================================================ void SalomeApp_NoteBookDlg::onUpdateStudy() { diff --git a/src/SalomeApp/SalomeApp_NoteBookDlg.h b/src/SalomeApp/SalomeApp_NoteBookDlg.h index fc0f33480..8dc19261e 100644 --- a/src/SalomeApp/SalomeApp_NoteBookDlg.h +++ b/src/SalomeApp/SalomeApp_NoteBookDlg.h @@ -30,29 +30,47 @@ #include #include - +#include class QWidget; class QPushButton; class QTableWidgetItem; - class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget { public: NoteBook_TableRow(QWidget* parent=0); virtual ~NoteBook_TableRow(); - void setEditable(bool enable); + void SetNameEditable(bool enable); + bool IsNameEditable(); + void AddToTable(QTableWidget *theTable); void SetName(const QString theName); void SetValue(const QString theValue); + + QString GetValue() const; + QString GetName() const; + + bool CheckName(); + bool CheckValue(); + + void setValueEditable(bool enable); + void setNameEditable(bool enable); + + QTableWidgetItem* GetVariableItem(); + QTableWidgetItem* GetNameItem(); + + 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); private: QTableWidgetItem* myRowHeader; QTableWidgetItem* myVariableName; QTableWidgetItem* myVariableValue; + bool isNameEditable; }; @@ -64,12 +82,37 @@ class SALOMEAPP_EXPORT NoteBook_Table : public QTableWidget virtual ~NoteBook_Table(); void Init(_PTR(Study) theStudy); + static QString Variable2String(const std::string& theVarName, + _PTR(Study) theStudy); + void AddEmptyRow(); + NoteBook_TableRow* GetRowByItem(const QTableWidgetItem* theItem) const; + bool IsLastRow(const NoteBook_TableRow* aRow) const; + + void RemoveSelected(); + + void SetIncorrectItem(QTableWidgetItem* theItem); + void RemoveIncorrectItem(); + + void SetProcessItemChangedSignalFlag(const bool enable); + bool GetProcessItemChangedSignalFlag()const; + + bool IsUniqueName(const NoteBook_TableRow* theRow) const; + QList GetRows() const; public slots: void onItemChanged(QTableWidgetItem* theItem); + void onItemSelectionChanged(); + + + signals: + void incorrectItemAdded(); + void incorrectItemRemoved(); + void selectionChanged(bool); private: - bool isInitialized; + bool isProcessItemChangedSignal; + QTableWidgetItem* myIncorrectItem; + QList myRows; }; class SALOMEAPP_EXPORT SalomeApp_NoteBookDlg : public QDialog @@ -83,15 +126,20 @@ class SALOMEAPP_EXPORT SalomeApp_NoteBookDlg : public QDialog void onOK(); void onApply(); void onUpdateStudy(); + void onRemove(); + void onIncorrectItemAdded(); + void onIncorrectItemRemoved(); + void onTableSelectionChanged(bool flag); private: NoteBook_Table* myTable; + QPushButton* myRemoveButton; + QPushButton* myUpdateStudyBtn; QPushButton* myOkBtn; QPushButton* myApplyBtn; QPushButton* myCancelBtn; - QPushButton* myUpdateStudyBtn; - _PTR(Study) myStudy; + _PTR(Study) myStudy; }; diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index ebb4d0508..b693741ca 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -346,10 +346,22 @@ Do you want to reload it ? VARNAME_COLUMN Variable Name - + VARVALUE_COLUMN Variable Value + + VARVALUE_INCORRECT + Variable Value Incorrect: %1 + + + VARNAME_INCORRECT + Valiable Name Incorrect :%1 + + + VARNAME_EXISTS + Valiable with name "%1" exists + SalomeApp_NoteBookDlg @@ -359,7 +371,11 @@ Do you want to reload it ? BUT_UPDATE_STUDY - Update Studyy + Update Study + + + BUT_REMOVE + Remove