Skip to content

Commit

Permalink
Various updates to region table, including region modified column and…
Browse files Browse the repository at this point in the history
… sorting by column
  • Loading branch information
davidborland committed Nov 21, 2019
1 parent 57ae254 commit 2767ea3
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 22 deletions.
4 changes: 2 additions & 2 deletions MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions Region.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "RegionVoxelOutlines.h"

Region::Region(unsigned short regionLabel, double regionColor[3], vtkImageData* inputData) {
modified = false;
done = false;

// Input data info
Expand Down Expand Up @@ -163,6 +164,10 @@ void Region::UpdateExtent() {
voi->SetVOI(padExtent);
}

void Region::SetModified(bool isModified) {
modified = isModified;
}

void Region::SetDone(bool isDone) {
done = isDone;

Expand Down Expand Up @@ -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++) {
Expand Down
8 changes: 7 additions & 1 deletion Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<vtkImageData> data;
Expand Down
79 changes: 64 additions & 15 deletions RegionTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QHeaderView>
#include <QTableWidgetItem>
#include <QIcon>
#include <QLabel>
#include <QStyle>
#include <QPushButton>
#include <QSignalMapper>
Expand All @@ -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);

Expand All @@ -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]() {
Expand All @@ -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++) {
Expand All @@ -104,4 +149,8 @@ void RegionTable::Highlight(unsigned short label) {
ti->setTextColor(QColor("black"));
}
}
}

void RegionTable::on_sort() {
resizeColumnsToContents();
}
7 changes: 5 additions & 2 deletions RegionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -453,6 +461,8 @@ void VisualizationContainer::RelabelCurrentRegion() {
regions->Add(newRegion);
volumeView->AddRegion(newRegion);
sliceView->AddRegion(newRegion);

newRegion->SetModified(true);
}
}

Expand Down Expand Up @@ -496,6 +506,7 @@ void VisualizationContainer::MergeWithCurrentRegion(int x, int y, int z) {
}

currentRegion->SetExtent(newExtent);
currentRegion->SetModified(true);

// Remove region
RemoveRegion(label);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down

0 comments on commit 2767ea3

Please sign in to comment.