From 524550497847c46aa197f58378538053500171d0 Mon Sep 17 00:00:00 2001 From: isn Date: Mon, 2 Nov 2015 17:41:23 +0300 Subject: [PATCH] LCM // Import/Export of SHP p.4 --- src/HYDROData/HYDROData_Document.cxx | 19 ++++ src/HYDROData/HYDROData_Document.h | 5 + .../HYDROGUI_ImportLandCoverMapDlg.cxx | 92 +++++++++++++++---- src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h | 22 +++-- .../HYDROGUI_ImportLandCoverMapOp.cxx | 78 ++++++---------- src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h | 2 - src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx | 22 +---- src/HYDROGUI/HYDROGUI_Wizard.cxx | 49 +++++++--- src/HYDROGUI/HYDROGUI_Wizard.h | 4 + 9 files changed, 186 insertions(+), 107 deletions(-) diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index 93457716..01180868 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include @@ -33,6 +35,7 @@ #include #include #include +#include IMPLEMENT_STANDARD_HANDLE(HYDROData_Document,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared) @@ -868,3 +871,19 @@ NCollection_Sequence HYDROData_Document::GetInterpolato return aNames; } + +QColor HYDROData_Document::GetAssociatedColor(const QString& theStricklerType, + const Handle(HYDROData_StricklerTable)& theTable) +{ + if( !theTable.IsNull() && theTable->HasType( theStricklerType ) ) + return theTable->GetColor( theStricklerType ); + + HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE ); + for( ; anIt.More(); anIt.Next() ) + { + Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); + if( aTable->HasType( theStricklerType ) ) + return aTable->GetColor( theStricklerType ); + } + return QColor(); +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 6f3c8229..910e318f 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -24,6 +24,8 @@ class HYDROData_InterpolatorsFactory; class HYDROData_IProfilesInterpolator; +class Handle(HYDROData_StricklerTable); +class Handle(HYDROData_LandCoverMap); class QFile; class gp_Pnt2d; @@ -223,6 +225,9 @@ public: //! Sets default strickler coefficient HYDRODATA_EXPORT void SetDefaultStricklerCoefficient( double ) const; + HYDRODATA_EXPORT QColor HYDROData_Document::GetAssociatedColor(const QString& theStricklerType, + const Handle(HYDROData_StricklerTable)& theTable); + protected: friend class HYDROData_Iterator; friend class test_HYDROData_Document; diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx index 40add2d8..6b96578c 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.cxx @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include HYDROGUI_ImportLandCoverMapDlg::HYDROGUI_ImportLandCoverMapDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_Wizard( theModule, theTitle ) @@ -67,7 +70,7 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() { aFileNameLayout->addWidget( aFileNameLabel ); aFileNameLayout->addWidget( myFileName ); aFileNameLayout->addWidget( aBrowseBtn ); - + myObjectNameGroup = new QGroupBox( tr( "LANDCOVERMAP_NAME" ) ); QLabel* aLandcoverNameLabel = new QLabel( tr( "NAME" ), myObjectNameGroup ); @@ -90,11 +93,15 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() { aPolygonsLayout->addWidget( myPolygons ); aPolygonsGroup->setLayout( aPolygonsLayout ); - // Layout QVBoxLayout* aPageLayout = new QVBoxLayout; + myAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types" ); //TODO replace with tr() + myAttrCheckBox->setChecked(true); + + // Layout aPageLayout->setMargin( 5 ); aPageLayout->setSpacing( 5 ); aPageLayout->addWidget( myFileNameGroup ); + aPageLayout->addWidget( myAttrCheckBox ); aPageLayout->addWidget( myObjectNameGroup ); aPageLayout->addWidget( aPolygonsGroup ); aPage->setLayout( aPageLayout ); @@ -102,6 +109,7 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage1() { // Conections connect( myPolygons, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) ); connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); + connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool))); return aPage; } @@ -110,17 +118,10 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() { QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); - myAttrNameGroup = new QGroupBox( "Available attributes" ); - - QCheckBox* anAttrCheckBox = new QCheckBox( "Use dBase attributes as a Strickler Types", myAttrNameGroup ); - - QBoxLayout* aFileNameLayout = new QHBoxLayout( myAttrNameGroup ); - aFileNameLayout->setMargin( 5 ); - aFileNameLayout->setSpacing( 5 ); - aFileNameLayout->addWidget( anAttrCheckBox ); - - - myDBFAttr = new QListWidget( aPage ); + myAvAttrLabel = new QLabel(); + myAvAttrLabel->setText("Available attributes"); + + myDBFAttr = new QListWidget( ); myDBFAttr->setSelectionMode( QListWidget::SingleSelection ); myDBFAttr->setEditTriggers( QListWidget::NoEditTriggers ); myDBFAttr->setViewMode( QListWidget::ListMode ); @@ -130,9 +131,10 @@ QWizardPage* HYDROGUI_ImportLandCoverMapDlg::createPage2() { QVBoxLayout* aPageLayout = new QVBoxLayout; aPageLayout->setMargin( 5 ); aPageLayout->setSpacing( 5 ); - aPageLayout->addWidget( myAttrNameGroup ); + aPageLayout->addWidget( myAvAttrLabel ); aPageLayout->addWidget( myDBFAttr ); aPage->setLayout( aPageLayout ); + return aPage; } @@ -259,14 +261,24 @@ QString HYDROGUI_ImportLandCoverMapDlg::getFileName() const } -void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn) +void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstColumn, + const QStringList& theSecondColumn, + const QVector theColors) { int FCSize = theFirstColumn.size(); int SCSize = theSecondColumn.size(); - - myTableW->setRowCount(FCSize); - myTableW->setColumnCount(2); + myStrColors = theColors; + + myTableW->setRowCount(FCSize); + myTableW->setColumnCount(3); + QTableWidgetItem* Header_1 = new QTableWidgetItem(QString("Attribute"), QTableWidgetItem::Type); + QTableWidgetItem* Header_2 = new QTableWidgetItem(QString("Strickler Type"), QTableWidgetItem::Type); + QTableWidgetItem* Header_3 = new QTableWidgetItem(QString("Color"), QTableWidgetItem::Type); + myTableW->setHorizontalHeaderItem(0, Header_1); + myTableW->setHorizontalHeaderItem(1, Header_2); + myTableW->setHorizontalHeaderItem(2, Header_3); + // for (int i = 0; i < FCSize; i++) { QTableWidgetItem* aTWI = new QTableWidgetItem(); @@ -274,13 +286,25 @@ void HYDROGUI_ImportLandCoverMapDlg::FillCorrTable(const QStringList& theFirstCo aTWI->setFlags(Qt::ItemIsUserCheckable); myTableW->setItem(i, 0, aTWI); } - + // + QSignalMapper* signalMap = new QSignalMapper(); for (int i = 0; i < FCSize; i++) { QComboBox* aCB = new QComboBox(); + connect(aCB, SIGNAL(currentIndexChanged(int)), signalMap, SLOT(map())); + signalMap->setMapping(aCB, i); aCB->addItems(theSecondColumn); myTableW->setCellWidget(i, 1, aCB); } + connect(signalMap, SIGNAL(mapped(int)), this, SLOT(OnComboBoxColorChanged(int))); + // + for (int i = 0; i < FCSize; i++) + { + myTableW->setItem(i, 2, new QTableWidgetItem); + //take the first color from array; this color corresponds to the first item in the combo box + myTableW->item(i, 2)->setBackground(myStrColors[0]); + } + } QString HYDROGUI_ImportLandCoverMapDlg::getSelectedFieldName() const @@ -302,12 +326,20 @@ bool HYDROGUI_ImportLandCoverMapDlg::acceptCurrent() const case 0: { if (!myFirstPageState) + { + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "File isn't chosen"); + return false; + } + if (myPolygons->selectedItems().empty()) + { + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "LCM_IMPORT_WARNING" ), "Polygons isn't selected"); return false; + } break; } case 1: { - if (this->myDBFAttr->selectedItems().empty()) + if (myDBFAttr->selectedItems().empty()) return false; break; } @@ -346,4 +378,24 @@ QVector HYDROGUI_ImportLandCoverMapDlg::getSelectedPolygonIndices() const } return aSelectedIndices; +} + +void HYDROGUI_ImportLandCoverMapDlg::onAttrCBChecked( bool theState ) +{ + if (theState) + SetButtonsState ( false ); + else + SetButtonsState ( true ); +} + +bool HYDROGUI_ImportLandCoverMapDlg::getAttrCheckBoxState() const +{ + return myAttrCheckBox->isChecked(); +} + +void HYDROGUI_ImportLandCoverMapDlg::OnComboBoxColorChanged(int theInd) +{ + QComboBox* CB = qobject_cast (myTableW->cellWidget(theInd, 1)); + int CurIndOfCB = CB->currentIndex(); + myTableW->item(theInd, 2)->setBackground(myStrColors[CurIndOfCB]); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h index 6030b8ad..68cbaa6a 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapDlg.h @@ -29,6 +29,7 @@ class QGroupBox; class QComboBox; class QLabel; class QTableWidget; +class QCheckBox; class HYDROGUI_ImportLandCoverMapDlg : public HYDROGUI_Wizard @@ -48,7 +49,9 @@ public: void setAttributeNames( const QStringList& theAttrNames ); - void FillCorrTable(const QStringList& theFirstColumn, const QStringList& theSecondColumn); + void FillCorrTable(const QStringList& theFirstColumn, + const QStringList& theSecondColumn, + const QVector theColors); QStringList getSelectedPolygonNames() const; QString getSelectedFieldName() const; @@ -60,7 +63,7 @@ public: QString getFileName() const; void setFirstPageState(bool bState); - //void setThirdPageState(bool bState); + bool getAttrCheckBoxState() const; void GetAttribute2StricklerCorr(QStringList& AttrValues, QStringList& ST); QVector getSelectedPolygonIndices() const; @@ -71,6 +74,8 @@ signals: protected slots: void onBrowse(); void onItemSelectionChanged(); + void onAttrCBChecked(bool theState); + void OnComboBoxColorChanged(int theInd); protected: bool acceptCurrent() const; @@ -85,23 +90,22 @@ private: QLineEdit* myFileName; QGroupBox* myFileNameGroup; QListWidget* myPolygons; - QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; + QCheckBox* myAttrCheckBox; - //second page - QGroupBox* myAttrNameGroup; + //Second page QListWidget* myDBFAttr; - QGroupBox* myCorrNameGroup; + QLabel* myAvAttrLabel; - //third page + //Third page QLabel* myCLabel; QTableWidget* myTableW; - //State of pages + //State of the first page bool myFirstPageState; - //bool myThirdPageState; + QVector myStrColors; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx index e8303bac..d410018f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.cxx @@ -67,10 +67,7 @@ #include - -//TODO deny to create null-LCM (selected poltgons on the first page = 0) -//TODO erase onBack/onFinish if not needed... - +//TODO add definitions into TS file HYDROGUI_ImportLandCoverMapOp::HYDROGUI_ImportLandCoverMapOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) { @@ -219,12 +216,8 @@ HYDROGUI_InputPanel* HYDROGUI_ImportLandCoverMapOp::createInputPanel() const HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportLandCoverMapDlg( module(), getName() ); connect( aPanel, SIGNAL( FileSelected( const QString& ) ), SLOT( onFileSelected() ) ); - connect( aPanel, SIGNAL( selectionChanged( const QStringList& ) ), this, SLOT( onSelectionChanged( const QStringList& ) ) ); - connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) ); - connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onBack( const int ) ) ); - connect( aPanel, SIGNAL( Finish( const int ) ), SLOT( onFinish( const int ) ) ); return aPanel; } @@ -233,28 +226,15 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ) { - //TODO rewrite this! + HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); if ( !aPanel ) { return false; } Handle(HYDROData_LandCoverMap) aLCM = Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) ); - HYDROData_MapOfFaceToStricklerType aMapFace2ST; - /*QStringList aSelectedPolygons = aPanel->getSelectedPolygonNames(); - aPanel->removePolygonNames( aSelectedPolygons ); - - foreach ( QString aName, aSelectedPolygons ) - { - TopoDS_Shape aShape = myPolygonName2PrsShape.value( aName )->getTopoShape(); - if ( aShape.IsNull() ) - continue; - aMapFace2ST.Add( TopoDS::Face( aShape ), "TODO temp" ); //TODO get from tableW - HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName ); - delete aShapeToDelete; - }*/ QStringList aAttrV_T; QStringList aSTL; aPanel->GetAttribute2StricklerCorr(aAttrV_T, aSTL); @@ -265,24 +245,30 @@ bool HYDROGUI_ImportLandCoverMapOp::processApply( int& theUpdateFlags, TopoDS_Shape aShape = myPolygonFaces(Ind + 1); if ( aShape.IsNull() ) continue; - HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind]; - int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal)); - QString aST = aSTL.at(StricklerTypesInd); + QString aST = ""; + if (aPanel->getAttrCheckBoxState()) + { + HYDROData_ShapeFile::DBF_AttrValue aV = myAttrV[Ind]; + int StricklerTypesInd = aAttrV_T.indexOf(QString(aV.myStrVal)); + aST = aSTL.at(StricklerTypesInd); + } + // else => ST is empty aMapFace2ST.Add( TopoDS::Face( aShape ), aST ); //TODO get from tableW - //HYDROGUI_Shape* aShapeToDelete = myPolygonName2PrsShape.take( aName ); - //delete aShapeToDelete; } // aLCM->StoreLandCovers(aMapFace2ST); + QString ObjName; + if ( !aPanel->getFileName().isEmpty() ) + ObjName = aPanel->getObjectName(); + if( !aLCM.IsNull() ) { - aLCM->SetName( "temp_name" ); - aLCM->SetColor( QColor(0,100,100) ); + aLCM->SetName( ObjName ); + aLCM->SetColor( Qt::gray ); aLCM->Show(); module()->setIsToUpdate( aLCM ); - } module()->update( UF_Model | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init ); @@ -312,14 +298,8 @@ void HYDROGUI_ImportLandCoverMapOp::onSelectionChanged( const QStringList& theSe bool isSelected = theSelectedNames.contains( aName ); if ( ( isSelected && !aCtx->IsSelected( anObject) ) || - ( !isSelected && aCtx->IsSelected( anObject) ) ) { + ( !isSelected && aCtx->IsSelected( anObject) ) ) aCtx->AddOrRemoveSelected( anObject, Standard_False ); - } - /*if (isSelected) - { - HYDROGUI_Shape* aHydroSh = myPolygonName2PrsShape.value( aName ); - aHydroSh->setFillingColor(QColor(0,255,255), true, true); - }*/ } aCtx->UpdateCurrentViewer(); } @@ -328,7 +308,6 @@ void HYDROGUI_ImportLandCoverMapOp::onSelectionChanged( const QStringList& theSe void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() { - // Get panel HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); if ( !aPanel ) { return; @@ -347,9 +326,8 @@ void HYDROGUI_ImportLandCoverMapOp::onViewerSelectionChanged() QStringList aSelectedNames; foreach ( QString aName, myPolygonName2PrsShape.keys() ) { bool isSelected = aCtx->IsSelected( myPolygonName2PrsShape.value(aName)->getAISObject() ); - if ( isSelected ) { + if ( isSelected ) aSelectedNames << aName; - } } aPanel->setSelectedPolygonNames( aSelectedNames ); } @@ -378,10 +356,8 @@ void HYDROGUI_ImportLandCoverMapOp::abortOperation() HYDROGUI_Operation::abortOperation(); } -//TODO take "Use dbf attrs as ST.." into account void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) { - //TODO add acceptor HYDROGUI_ImportLandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); if ( !aPanel ) return; @@ -434,19 +410,24 @@ void HYDROGUI_ImportLandCoverMapOp::onNext( const int theIndex ) } } } - aPanel->FillCorrTable(mySetOfAttrValues.toList(), aSTSet.toList()); + QList SetOfAttrValuesList = mySetOfAttrValues.toList(); + QList aSTSetList = aSTSet.toList(); + QVector STColors; + STColors.reserve(aSTSetList.size()); + foreach (QString str, aSTSetList) + { + QColor col = aDoc->GetAssociatedColor(str, NULL); + STColors.append (col); + } + + aPanel->FillCorrTable(SetOfAttrValuesList, aSTSetList, STColors); } } -void HYDROGUI_ImportLandCoverMapOp::onBack( const int theIndex ) -{ - -} void HYDROGUI_ImportLandCoverMapOp::onApply() { - QApplication::setOverrideCursor( Qt::WaitCursor ); int anUpdateFlags = 0; QString anErrorMsg; @@ -459,6 +440,7 @@ void HYDROGUI_ImportLandCoverMapOp::onApply() } catch (...) { + SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "LCM_IMPORT_ERROR" ), "Cant import choosed polygons"); aResult = false; } diff --git a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h index 1a525fc9..d342380d 100644 --- a/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportLandCoverMapOp.h @@ -58,8 +58,6 @@ protected slots: void onSelectionChanged( const QStringList& theSelectedNames ); void onViewerSelectionChanged (); void onNext( const int theIndex ); - void onBack( const int theIndex ); - private: QMap myPolygonName2PrsShape; diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx index 6f654a6d..5e8a17f6 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx @@ -116,24 +116,12 @@ Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerTy return Quantity_Color(); } - if( !myTable.IsNull() && myTable->HasType( theStricklerType ) ) - { - QColor aColor = myTable->GetColor( theStricklerType ); - return HYDROData_Tool::toOccColor( aColor ); - } + QColor aColor = HYDROData_Document::Document( myLCMap->Label())->GetAssociatedColor(theStricklerType, myTable); - HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE ); - for( ; anIt.More(); anIt.Next() ) - { - Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() ); - if( aTable->HasType( theStricklerType ) ) - { - QColor aColor = aTable->GetColor( theStricklerType ); - return HYDROData_Tool::toOccColor( aColor ); - } - } - - return Quantity_Color(); + if (aColor.isValid()) + return HYDROData_Tool::toOccColor(aColor); + else + return Quantity_Color(); } void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, diff --git a/src/HYDROGUI/HYDROGUI_Wizard.cxx b/src/HYDROGUI/HYDROGUI_Wizard.cxx index fd393ae5..7ad59940 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.cxx +++ b/src/HYDROGUI/HYDROGUI_Wizard.cxx @@ -69,8 +69,9 @@ int HYDROGUI_Wizard::addPage( QWizardPage* thePage ) { if ( myWizard->count() > 0 ) { - myNext->setVisible( true ); - myFinish->setVisible( false ); + SetButtonsState(false); + /*myNext->setVisible( true ); + myFinish->setVisible( false );*/ } return myWizard->addWidget( thePage ); } @@ -85,11 +86,12 @@ void HYDROGUI_Wizard::onNext() myBack->setEnabled( true ); int aCurIdx = myWizard->currentIndex(); - if ( aCurIdx == ( myWizard->count() - 2 ) ) + if ( IsLastPage() ) { // Go to the last page - myNext->setVisible( false ); - myFinish->setVisible( true ); + SetButtonsState( true ); + /*myNext->setVisible( false ); + myFinish->setVisible( true );*/ } myWizard->setCurrentIndex( aCurIdx + 1 ); @@ -103,14 +105,16 @@ void HYDROGUI_Wizard::onBack() if ( myWizard->count() > 1 ) { - myNext->setVisible( true ); - myFinish->setVisible( false ); + /*myNext->setVisible( true ); + myFinish->setVisible( false );*/ + SetButtonsState( false ); } else { // Wizard has a single page - show finish - myNext->setVisible( false ); - myFinish->setVisible( true ); + SetButtonsState( true ); + /*myNext->setVisible( false ); + myFinish->setVisible( true );*/ } int aCurIdx = myWizard->currentIndex(); @@ -129,8 +133,9 @@ void HYDROGUI_Wizard::onBack() void HYDROGUI_Wizard::onFirstPage() { if ( myWizard->count() > 1 ) { - myNext->setVisible( true ); - myFinish->setVisible( false ); + /*myNext->setVisible( true ); + myFinish->setVisible( false );*/ + SetButtonsState( false ); myWizard->setCurrentIndex( 0 ); myBack->setEnabled( false ); emit Back( myWizard->currentIndex() ); @@ -163,4 +168,26 @@ QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const aRes = myHelp; } return aRes; +} + +bool HYDROGUI_Wizard::IsLastPage() +{ + if ( myWizard->currentIndex() == ( myWizard->count() - 2 )) + return true; + else + return false; +} + +void HYDROGUI_Wizard::SetButtonsState (bool IsLastPage) +{ + if (!IsLastPage) + { + myNext->setVisible( true ); + myFinish->setVisible( false ); + } + else + { + myNext->setVisible( false ); + myFinish->setVisible( true ); + } } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Wizard.h b/src/HYDROGUI/HYDROGUI_Wizard.h index c0a88551..8269950c 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.h +++ b/src/HYDROGUI/HYDROGUI_Wizard.h @@ -56,6 +56,10 @@ protected: // Reimplement this method in your subclass to verify user input data. virtual bool acceptCurrent() const; + virtual bool IsLastPage(); + + void SetButtonsState (bool IsLastPage); + private: QStackedWidget* myWizard; QPushButton* myNext; -- 2.39.2