From 26c427c3c298fdf0a3e23cfaf1c44bbfb3e8802a Mon Sep 17 00:00:00 2001 From: akl Date: Mon, 28 Oct 2013 06:50:13 +0000 Subject: [PATCH] *** empty log message *** --- src/CurveCreator/CurveCreator_ICurve.cxx | 6 +- src/CurveCreator/CurveCreator_TreeView.cxx | 9 +- src/CurveCreator/CurveCreator_TreeView.h | 1 + src/CurveCreator/CurveCreator_Widget.cxx | 98 +++++++++++++--------- 4 files changed, 70 insertions(+), 44 deletions(-) diff --git a/src/CurveCreator/CurveCreator_ICurve.cxx b/src/CurveCreator/CurveCreator_ICurve.cxx index 1cf2869d8..a52e34001 100644 --- a/src/CurveCreator/CurveCreator_ICurve.cxx +++ b/src/CurveCreator/CurveCreator_ICurve.cxx @@ -216,7 +216,8 @@ void CurveCreator_ICurve::removeSection(const int theISection) delete *anIterRm; mySections.erase(anIterRm); } - myListener->sectionRemoved(theISection); + if( myListener ) + myListener->sectionRemoved(theISection); } //======================================================================= @@ -268,7 +269,8 @@ void CurveCreator_ICurve::removePoints(const int theISection, aSection->myPoints.end() : anIterBegin + toICoord(theNbPoints)); aSection->myPoints.erase(anIterBegin, anIterEnd); - myListener->pointRemoved(theISection, theIPnt, theNbPoints ); + if( myListener ) + myListener->pointRemoved(theISection, theIPnt, theNbPoints ); } //======================================================================= diff --git a/src/CurveCreator/CurveCreator_TreeView.cxx b/src/CurveCreator/CurveCreator_TreeView.cxx index d7b49f9c7..18704810c 100755 --- a/src/CurveCreator/CurveCreator_TreeView.cxx +++ b/src/CurveCreator/CurveCreator_TreeView.cxx @@ -160,6 +160,11 @@ QModelIndex CurveCreator_TreeViewModel::sectionIndex( int theSection ) const return createIndex( theSection, 0, ID_SECTION ); } +QModelIndex CurveCreator_TreeViewModel::nbPointsIndex( int theSection ) const +{ + return createIndex( theSection, 1, ID_SECTION ); +} + QModelIndex CurveCreator_TreeViewModel::pointIndex( int theSection, int thePoint ) const { return createIndex( thePoint, 0, theSection ); @@ -203,9 +208,10 @@ CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_Curve* theCurve, QWid CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this); setModel(aModel); setSelectionBehavior(SelectRows); - setSelectionMode(ExtendedSelection); + setSelectionMode(SingleSelection); setRootIsDecorated(false); setItemsExpandable(false); + setAllColumnsShowFocus(true); connect( selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SIGNAL(selectionChanged()) ); connect( this, SIGNAL(activated(QModelIndex)), this, SLOT(onActivated(QModelIndex))); @@ -235,6 +241,7 @@ void CurveCreator_TreeView::pointsAdded( int theSection, int thePoint, int thePo QModelIndex aSectIndx = aModel->sectionIndex( theSection ); rowsInserted(aSectIndx, thePoint, thePoint + thePointsCnt - 1 ); // expand( aSectIndx ); + update( aModel->nbPointsIndex( theSection ) ); } } diff --git a/src/CurveCreator/CurveCreator_TreeView.h b/src/CurveCreator/CurveCreator_TreeView.h index aab39b6af..57dce8652 100755 --- a/src/CurveCreator/CurveCreator_TreeView.h +++ b/src/CurveCreator/CurveCreator_TreeView.h @@ -18,6 +18,7 @@ public: // virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole); QModelIndex sectionIndex( int theSection ) const; + QModelIndex nbPointsIndex( int theSection ) const; QModelIndex pointIndex( int theSection, int thePoint ) const; bool isSection( const QModelIndex& theIndx ) const; diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index 32950c120..f5399e414 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -226,11 +226,6 @@ void CurveCreator_Widget::onSelectionChanged() QList anEnabledAct; if( myCurve ){ anEnabledAct << NEW_SECTION_ID; - int aSectCnt = myCurve->getNbPoints(); - if( aSectCnt > 0 ) - anEnabledAct << CLEAR_ALL_ID; - if( aSectCnt > 1 ) - anEnabledAct << JOIN_ALL_ID; QList aSelSections = mySectionView->getSelectedSections(); QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints(); CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); @@ -239,22 +234,40 @@ void CurveCreator_Widget::onSelectionChanged() break; } case CurveCreator_TreeView::ST_SECTIONS:{ - if( aSelSections.size() > 1 ){ - anEnabledAct << JOIN_ID; - } - if( aSelSections[0] > 0 ){ + /*if( aSelSections[0] > 0 ){ anEnabledAct << UP_ID; - } + }*/ if( aSelSections.size() == 1 ){ anEnabledAct << CREATION_MODE_ID << EDITION_MODE_ID << DETECTION_MODE_ID; } - if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){ - anEnabledAct << DOWN_ID; + if (myActionMap[CREATION_MODE_ID]->isChecked()) { + mySection = -1; + myPointNum = -1; + QList aSelSection = mySectionView->getSelectedSections(); + if( aSelSection.size() > 0 ){ + mySection = aSelSection[0]; + myPointNum = myCurve->getNbPoints(mySection); + } + } else if (myActionMap[EDITION_MODE_ID]->isChecked()) { + anEnabledAct << REMOVE_ID; + anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID; + int aSectCnt = myCurve->getNbSections(); + if( aSectCnt > 0 ) + anEnabledAct << CLEAR_ALL_ID; + if( aSectCnt > 1 ) + anEnabledAct << JOIN_ALL_ID; + if( aSelSections.size() > 1 ){ + anEnabledAct << JOIN_ID; + } + } else if (myActionMap[DETECTION_MODE_ID]->isChecked()) { + } else { //no active mode } - anEnabledAct << CLOSE_SECTIONS_ID << UNCLOSE_SECTIONS_ID << SET_SECTIONS_POLYLINE_ID << SET_SECTIONS_SPLINE_ID; + /*if( aSelSections[ aSelSections.size() - 1 ] < ( myCurve->getNbSections() - 1 ) ){ + anEnabledAct << DOWN_ID; + }*/ break; } - case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{ + /*case CurveCreator_TreeView::ST_POINTS_ONE_SECTION:{ if( aSelPoints[0].second > 0 ){ anEnabledAct << UP_ID; } @@ -267,15 +280,17 @@ void CurveCreator_Widget::onSelectionChanged() anEnabledAct << INSERT_POINT_BEFORE_ID << INSERT_POINT_AFTER_ID; } break; + }*/ + } - } - int aSelObjsCnt = aSelPoints.size() + aSelSections.size(); + + /*int aSelObjsCnt = aSelPoints.size() + aSelSections.size(); if( aSelObjsCnt > 0 ){ anEnabledAct << REMOVE_ID; } if( (myCurve->getNbSections() + myCurve->getNbPoints()) > 0 ){ anEnabledAct << REMOVE_ALL_ID; - } + }*/ if( myCurve->getNbSections() > 1 ){ anEnabledAct << JOIN_ALL_ID; } @@ -356,29 +371,30 @@ void CurveCreator_Widget::onDetectPoints(bool checked) void CurveCreator_Widget::onModeChanged(bool checked) { - if (!checked) - return; - QAction* anAction = (QAction*)sender(); - switch(myActionMap.key(anAction)) { - case CREATION_MODE_ID: - if (myActionMap[EDITION_MODE_ID]->isChecked()) - myActionMap[EDITION_MODE_ID]->trigger(); - else if (myActionMap[DETECTION_MODE_ID]->isChecked()) - myActionMap[DETECTION_MODE_ID]->trigger(); - break; - case EDITION_MODE_ID: - if (myActionMap[CREATION_MODE_ID]->isChecked()) - myActionMap[CREATION_MODE_ID]->trigger(); - else if (myActionMap[DETECTION_MODE_ID]->isChecked()) - myActionMap[DETECTION_MODE_ID]->trigger(); - break; - case DETECTION_MODE_ID: - if (myActionMap[CREATION_MODE_ID]->isChecked()) - myActionMap[CREATION_MODE_ID]->trigger(); - else if (myActionMap[EDITION_MODE_ID]->isChecked()) - myActionMap[EDITION_MODE_ID]->trigger(); - break; + if (checked) { + QAction* anAction = (QAction*)sender(); + switch(myActionMap.key(anAction)) { + case CREATION_MODE_ID: + if (myActionMap[EDITION_MODE_ID]->isChecked()) + myActionMap[EDITION_MODE_ID]->trigger(); + else if (myActionMap[DETECTION_MODE_ID]->isChecked()) + myActionMap[DETECTION_MODE_ID]->trigger(); + break; + case EDITION_MODE_ID: + if (myActionMap[CREATION_MODE_ID]->isChecked()) + myActionMap[CREATION_MODE_ID]->trigger(); + else if (myActionMap[DETECTION_MODE_ID]->isChecked()) + myActionMap[DETECTION_MODE_ID]->trigger(); + break; + case DETECTION_MODE_ID: + if (myActionMap[CREATION_MODE_ID]->isChecked()) + myActionMap[CREATION_MODE_ID]->trigger(); + else if (myActionMap[EDITION_MODE_ID]->isChecked()) + myActionMap[EDITION_MODE_ID]->trigger(); + break; + } } + onSelectionChanged(); } void CurveCreator_Widget::onAddNewPoint() @@ -387,8 +403,8 @@ void CurveCreator_Widget::onAddNewPoint() return; CurveCreator::Coordinates aCoords = myNewPointEditor->getCoordinates(); myEdit->insertPoints(aCoords, mySection, myPointNum ); -// mySectionView->pointsAdded( mySection, myPointNum ); -// myNewPointEditor->clear(); + mySectionView->pointsAdded( mySection, myPointNum ); + myNewPointEditor->clear(); myPointNum++; onSelectionChanged(); updateUndoRedo(); -- 2.39.2