From 2767ea303c4846c19eb337a1523a0d7f75556796 Mon Sep 17 00:00:00 2001 From: David Borland Date: Thu, 21 Nov 2019 16:39:08 -0500 Subject: [PATCH] Various updates to region table, including region modified column and sorting by column --- MainWindow.cxx | 4 +- Region.cxx | 10 +++++ Region.h | 8 +++- RegionTable.cxx | 79 ++++++++++++++++++++++++++++++-------- RegionTable.h | 7 +++- VisualizationContainer.cxx | 15 +++++++- 6 files changed, 101 insertions(+), 22 deletions(-) diff --git a/MainWindow.cxx b/MainWindow.cxx index e62fa7d..7412eb4 100644 --- a/MainWindow.cxx +++ b/MainWindow.cxx @@ -60,11 +60,11 @@ MainWindow::~MainWindow() { } void MainWindow::UpdateRegionTable(RegionCollection* regions) { - regionTable->Update(regions); + regionTable->update(regions); } void MainWindow::HighlightRegionTable(unsigned short label) { - regionTable->Highlight(label); + regionTable->highlight(label); } void MainWindow::on_actionOpen_Image_File_triggered() { diff --git a/Region.cxx b/Region.cxx index 3087009..145ad41 100644 --- a/Region.cxx +++ b/Region.cxx @@ -16,6 +16,7 @@ #include "RegionVoxelOutlines.h" Region::Region(unsigned short regionLabel, double regionColor[3], vtkImageData* inputData) { + modified = false; done = false; // Input data info @@ -163,6 +164,10 @@ void Region::UpdateExtent() { voi->SetVOI(padExtent); } +void Region::SetModified(bool isModified) { + modified = isModified; +} + void Region::SetDone(bool isDone) { done = isDone; @@ -207,6 +212,11 @@ bool Region::GetDone() { return done; } +bool Region::GetModified() { + return modified; +} + + void Region::ClearLabels() { for (int i = extent[0]; i <= extent[1]; i++) { for (int j = extent[2]; j <= extent[3]; j++) { diff --git a/Region.h b/Region.h index eaaad22..eac16a4 100644 --- a/Region.h +++ b/Region.h @@ -29,18 +29,24 @@ class Region { void SetExtent(int newExtent[6]); void UpdateExtent(int x, int y, int z); - void SetDone(bool done); + + void SetModified(bool isModified); + void SetDone(bool isDone); unsigned short GetLabel(); const double* GetColor(); int GetNumVoxels(); const int* GetExtent(); + + bool GetModified(); bool GetDone(); protected: unsigned short label; double color[3]; int extent[6]; + + bool modified; bool done; vtkSmartPointer data; diff --git a/RegionTable.cxx b/RegionTable.cxx index f766ee9..388fb2f 100644 --- a/RegionTable.cxx +++ b/RegionTable.cxx @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -16,34 +17,44 @@ RegionTable::RegionTable(QWidget* parent) : QTableWidget(parent) { QStringList headers; - headers << "Id" << "Color" << "Size" << "Done" << "Remove"; + headers << "Id" << "Color" << "Size" << "Modified" << "Done" << "Remove"; setColumnCount(headers.length()); setHorizontalHeaderLabels(headers); - resizeColumnsToContents(); verticalHeader()->setVisible(false); + setSortingEnabled(true); + resizeColumnsToContents(); setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + + QObject::connect(horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &RegionTable::on_sort); } -void RegionTable::Update(RegionCollection* regions) { +void RegionTable::update(RegionCollection* regions) { int numRegions = regions->Size(); + // Need to disable sorting + setSortingEnabled(false); + + // Clear table setRowCount(numRegions); // Icon for remove QStyle* style = QApplication::style(); - QIcon removeIcon = style->standardIcon(QStyle::SP_DialogCancelButton); + QIcon removeIcon = style->standardIcon(QStyle::SP_DialogCloseButton); + QIcon modifiedIcon = style->standardIcon(QStyle::SP_MessageBoxWarning); // Grey color double grey[3] = { 0.5, 0.5, 0.5 }; + // Add rows for each region int i = 0; for (RegionCollection::Iterator it = regions->Begin(); it != regions->End(); it++, i++) { Region* region = regions->Get(it); int label = (int)region->GetLabel(); // Id - QTableWidgetItem* idItem = new QTableWidgetItem(QString::number(label)); + QTableWidgetItem* idItem = new QTableWidgetItem(); + idItem->setData(0, label); idItem->setTextAlignment(Qt::AlignCenter); idItem->setFlags(Qt::ItemIsSelectable); @@ -55,20 +66,40 @@ void RegionTable::Update(RegionCollection* regions) { colorItem->setFlags(Qt::ItemIsSelectable); // Size - QTableWidgetItem* sizeItem = new QTableWidgetItem(QString::number(region->GetNumVoxels())); + QTableWidgetItem* sizeItem = new QTableWidgetItem(); + sizeItem->setData(0, region->GetNumVoxels()); sizeItem->setTextAlignment(Qt::AlignCenter); sizeItem->setFlags(Qt::ItemIsSelectable); sizeItem->setTextColor(QColor("black")); - // Checkbox - QCheckBox* checkBox = new QCheckBox(this); - checkBox->setChecked(region->GetDone()); - checkBox->setStyleSheet("margin-left:10%;margin-right:5%;"); - QObject::connect(checkBox, &QCheckBox::stateChanged, [this, label](int state) { + // Modified + QTableWidgetItem* modifiedItem = new QTableWidgetItem(); + modifiedItem->setFlags(Qt::ItemIsSelectable); + modifiedItem->setData(0, region->GetModified()); + modifiedItem->setTextColor(QColor("white")); + + QLabel* modifiedLabel = new QLabel(); + if (region->GetModified()) modifiedLabel->setPixmap(modifiedIcon.pixmap(16, 16)); + modifiedLabel->setAlignment(Qt::AlignCenter); + modifiedLabel->setEnabled(false); + + // Done + QTableWidgetItem* doneItem = new QTableWidgetItem(); + doneItem->setFlags(Qt::ItemIsSelectable); + doneItem->setData(0, region->GetDone()); + doneItem->setTextColor(QColor("white")); + + QCheckBox* doneCheckBox = new QCheckBox(this); + doneCheckBox->setChecked(region->GetDone()); + doneCheckBox->setStyleSheet("margin-left:10%;margin-right:5%;"); + QObject::connect(doneCheckBox, &QCheckBox::stateChanged, [this, label](int state) { regionDone(label, state); }); // Remove button + QTableWidgetItem* removeItem = new QTableWidgetItem(); + removeItem->setFlags(Qt::ItemIsSelectable); + QPushButton* removeButton = new QPushButton(this); removeButton->setIcon(removeIcon); QObject::connect(removeButton, &QPushButton::clicked, [this, label]() { @@ -78,16 +109,30 @@ void RegionTable::Update(RegionCollection* regions) { setItem(i, 0, idItem); setItem(i, 1, colorItem); setItem(i, 2, sizeItem); - setCellWidget(i, 3, checkBox); - setCellWidget(i, 4, removeButton); + + setItem(i, 3, modifiedItem); + setCellWidget(i, 3, modifiedLabel); + + setItem(i, 4, doneItem); + setCellWidget(i, 4, doneCheckBox); + + setItem(i, 5, removeItem); + setCellWidget(i, 5, removeButton); } + // Enable sorting + setSortingEnabled(true); + + // Resize columns resizeColumnsToContents(); - Highlight(0); + // Need to reconnect after disabling and enabling sorting + QObject::connect(horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &RegionTable::on_sort); + + highlight(0); } -void RegionTable::Highlight(unsigned short label) { +void RegionTable::highlight(unsigned short label) { QString labelString = QString::number(label); for (int i = 0; i < rowCount(); i++) { @@ -104,4 +149,8 @@ void RegionTable::Highlight(unsigned short label) { ti->setTextColor(QColor("black")); } } +} + +void RegionTable::on_sort() { + resizeColumnsToContents(); } \ No newline at end of file diff --git a/RegionTable.h b/RegionTable.h index 72c5c78..65fca10 100644 --- a/RegionTable.h +++ b/RegionTable.h @@ -12,8 +12,11 @@ class RegionTable : public QTableWidget { public: RegionTable(QWidget* parent = 0); - void Update(RegionCollection* regions); - void Highlight(unsigned short label); + void update(RegionCollection* regions); + void highlight(unsigned short label); + +public slots: + void on_sort(); signals: void regionDone(int label, bool done); diff --git a/VisualizationContainer.cxx b/VisualizationContainer.cxx index 8679c6f..818413f 100644 --- a/VisualizationContainer.cxx +++ b/VisualizationContainer.cxx @@ -345,6 +345,9 @@ void VisualizationContainer::Paint(int x, int y, int z) { currentRegion->UpdateExtent(x, y, z); SetLabel(x, y, z, currentRegion->GetLabel()); + + currentRegion->SetModified(true); + qtWindow->UpdateRegionTable(regions); } void VisualizationContainer::Erase(int x, int y, int z) { @@ -353,6 +356,9 @@ void VisualizationContainer::Erase(int x, int y, int z) { // TODO: SHRINK EXTENT SetLabel(x, y, z, 0); + + currentRegion->SetModified(true); + qtWindow->UpdateRegionTable(regions); } void VisualizationContainer::PickPointLabel(double x, double y, double z) { @@ -415,6 +421,8 @@ void VisualizationContainer::RelabelCurrentRegion() { RemoveRegion(label); } else { + currentRegion->SetModified(true); + for (int i = 0; i < numComponents; i++) { // Get the extent for this component double* componentExtent = componentExtents->GetTuple(i); @@ -453,6 +461,8 @@ void VisualizationContainer::RelabelCurrentRegion() { regions->Add(newRegion); volumeView->AddRegion(newRegion); sliceView->AddRegion(newRegion); + + newRegion->SetModified(true); } } @@ -496,6 +506,7 @@ void VisualizationContainer::MergeWithCurrentRegion(int x, int y, int z) { } currentRegion->SetExtent(newExtent); + currentRegion->SetModified(true); // Remove region RemoveRegion(label); @@ -712,7 +723,7 @@ void VisualizationContainer::LoadRegionMetadata(std::string fileName) { Region* region = regions->Get(metadata[i].label); if (region) { - //region->SetModified(metadata[i].modified; + region->SetModified(metadata[i].modified); region->SetDone(metadata[i].done); } } @@ -727,7 +738,7 @@ void VisualizationContainer::SaveRegionMetadata(std::string fileName) { Region* region = regions->Get(it); regionMetadata.label = region->GetLabel(); - regionMetadata.modified = false; + regionMetadata.modified = region->GetModified(); regionMetadata.done = region->GetDone(); metadata.push_back(regionMetadata);