From 5a2cc0b36b1e157aa536ba4ab2a30c17df9b43d0 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Wed, 28 Mar 2012 10:13:57 +0200 Subject: [PATCH] possibility to delete selected landmarks in VV --- vv/qt_ui/vvLandmarksPanel.ui | 2 +- vv/vvLandmarks.cxx | 19 +++++++++++++++++++ vv/vvLandmarks.h | 1 + vv/vvLandmarksPanel.cxx | 30 ++++++++++++++++++++---------- vv/vvLandmarksPanel.h | 2 +- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/vv/qt_ui/vvLandmarksPanel.ui b/vv/qt_ui/vvLandmarksPanel.ui index fd08723..7a64ea6 100644 --- a/vv/qt_ui/vvLandmarksPanel.ui +++ b/vv/qt_ui/vvLandmarksPanel.ui @@ -88,7 +88,7 @@ p, li { white-space: pre-wrap; } - :/common/icons/undo.png:/common/icons/undo.png + :/common/icons/standardbutton-cancel-16.png:/common/icons/standardbutton-cancel-16.png diff --git a/vv/vvLandmarks.cxx b/vv/vvLandmarks.cxx index d44c3be..682398f 100644 --- a/vv/vvLandmarks.cxx +++ b/vv/vvLandmarks.cxx @@ -104,6 +104,25 @@ void vvLandmarks::RemoveLastLandmark() //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +void vvLandmarks::RemoveLandmark(int index) +{ + // erase a vtkPoint by shifiting the array . + // not a problem here because there are no + // pologyons linking the points + int npoints = mPoints[mLandmarks[index].coordinates[3]]->GetNumberOfPoints(); + int t = mLandmarks[index].coordinates[3]; + for (int i = index; i < npoints - 1; i++) + mPoints[t]->InsertPoint(i, mPoints[t]->GetPoint(i+1)); + mPoints[t]->SetNumberOfPoints(npoints-1); + mPolyData->Modified(); + + mLandmarks.erase(mLandmarks.begin() + index); + mIds->RemoveLastTuple(); +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- void vvLandmarks::ChangeComments(int index, std::string comments) { diff --git a/vv/vvLandmarks.h b/vv/vvLandmarks.h index 29995c7..6bfe82e 100644 --- a/vv/vvLandmarks.h +++ b/vv/vvLandmarks.h @@ -43,6 +43,7 @@ public : void AddLandmark(float x,float y,float z,float t,double value); void RemoveLastLandmark(); + void RemoveLandmark(int index); void ChangeComments(int index, std::string comments); float* GetCoordinates(int index); double GetPixelValue(int index); diff --git a/vv/vvLandmarksPanel.cxx b/vv/vvLandmarksPanel.cxx index a2f0799..9e891cd 100644 --- a/vv/vvLandmarksPanel.cxx +++ b/vv/vvLandmarksPanel.cxx @@ -32,12 +32,14 @@ vvLandmarksPanel::vvLandmarksPanel(QWidget * parent):QWidget(parent) setupUi(this); tableWidget->verticalHeader()->hide(); + tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); + tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); loadButton->setEnabled(0); saveButton->setEnabled(0); removeButton->setEnabled(0); connect(loadButton, SIGNAL(clicked()),this,SLOT(Load())); connect(saveButton, SIGNAL(clicked()),this,SLOT(Save())); - connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveLastPoint())); + connect(removeButton, SIGNAL(clicked()),this,SLOT(RemoveSelectedPoints())); connect(tableWidget,SIGNAL(cellChanged(int,int)),this,SLOT(CommentsChanged(int,int))); } @@ -64,11 +66,19 @@ void vvLandmarksPanel::Save() } } -void vvLandmarksPanel::RemoveLastPoint() +void vvLandmarksPanel::RemoveSelectedPoints() { if (tableWidget->rowCount() > 0) { - tableWidget->removeRow(tableWidget->rowCount()-1); - mCurrentLandmarks->RemoveLastLandmark(); + QList items = tableWidget->selectedItems(); + if (items.empty()) { + tableWidget->removeRow(tableWidget->rowCount()-1); + mCurrentLandmarks->RemoveLastLandmark(); + } + else { + // we're using single-selection mode + mCurrentLandmarks->RemoveLandmark(items[0]->row()); + tableWidget->removeRow(items[0]->row()); + } emit UpdateRenderWindows(); } } @@ -84,33 +94,33 @@ void vvLandmarksPanel::AddPoint(int landmarksIndex) tableWidget->setRowCount(rowIndex+1); tableWidget->setRowHeight(rowIndex,20); QTableWidgetItem* iItem = new QTableWidgetItem(QString::number(landmarksIndex)); - iItem->setFlags(Qt::NoItemFlags); + iItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); tableWidget->setItem(rowIndex,0,iItem); QTableWidgetItem* xItem = new QTableWidgetItem( QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[0],'f',1)); - xItem->setFlags(Qt::NoItemFlags); + xItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); tableWidget->setItem(rowIndex,1,xItem); QTableWidgetItem* yItem = new QTableWidgetItem( QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[1],'f',1)); - yItem->setFlags(Qt::NoItemFlags); + yItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); tableWidget->setItem(rowIndex,2,yItem); QTableWidgetItem* zItem = new QTableWidgetItem( QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[2],'f',1)); - zItem->setFlags(Qt::NoItemFlags); + zItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); tableWidget->setItem(rowIndex,3,zItem); QTableWidgetItem* tItem = new QTableWidgetItem( QString::number(mCurrentLandmarks->GetCoordinates(landmarksIndex)[3],'f',1)); - tItem->setFlags(Qt::NoItemFlags); + tItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); tableWidget->setItem(rowIndex,4,tItem); QTableWidgetItem* vItem = new QTableWidgetItem( QString::number(mCurrentLandmarks->GetPixelValue(landmarksIndex),'f',1)); - vItem->setFlags(Qt::NoItemFlags); + vItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); tableWidget->setItem(rowIndex,5,vItem); tableWidget->setItem(rowIndex,6, new QTableWidgetItem(mCurrentLandmarks->GetComments(landmarksIndex).c_str())); diff --git a/vv/vvLandmarksPanel.h b/vv/vvLandmarksPanel.h index 69dd3d2..9966d88 100644 --- a/vv/vvLandmarksPanel.h +++ b/vv/vvLandmarksPanel.h @@ -42,7 +42,7 @@ public: public slots: void Load(); void Save(); - void RemoveLastPoint(); + void RemoveSelectedPoints(); void AddPoint(); void CommentsChanged(int row, int column); signals: -- 2.47.1