Skip to content

Commit

Permalink
Add command for ResetView so that the scaling/translation for a widget
Browse files Browse the repository at this point in the history
cannot be messed up by doing scaling, reset view, and then undoing the
command.
  • Loading branch information
addisonElliott committed Feb 6, 2017
1 parent e44b4c2 commit 11e5422
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
43 changes: 43 additions & 0 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,49 @@ bool CoronalScaleCommand::mergeWith(const QUndoCommand *command)
return true;
}

// ResetViewCommand
// --------------------------------------------------------------------------------------------------------------------
ResetViewCommand::ResetViewCommand(AxialSliceWidget *axialWidget, CoronalSliceWidget *coronalWidget, QUndoCommand *parent) : QUndoCommand(parent),
oldAxialTranslate(axialWidget->rtranslation()), oldAxialScaling(axialWidget->rscaling()), oldCoronalTranslate(coronalWidget->rtranslation()),
oldCoronalScaling(coronalWidget->rscaling()), axialWidget(axialWidget), coronalWidget(coronalWidget)
{
// Updates text that is shown on QUndoView
setText(QObject::tr("Reset view"));
}

void ResetViewCommand::undo()
{
axialWidget->rtranslation() = oldAxialTranslate;
axialWidget->rscaling() = oldAxialScaling;

coronalWidget->rtranslation() = oldCoronalTranslate;
coronalWidget->rscaling() = oldCoronalScaling;

// Tell the screen to draw itself since the scene changed
axialWidget->update();
coronalWidget->update();
}

void ResetViewCommand::redo()
{
// Reset the view for the axial and coronal widget
axialWidget->resetView();
coronalWidget->resetView();

// Tell the screen to draw itself since the scene changed
axialWidget->update();
coronalWidget->update();
}

bool ResetViewCommand::mergeWith(const QUndoCommand *command)
{
(void)command;

// Do nothing

return true;
}

// LocationChangeCommand
// --------------------------------------------------------------------------------------------------------------------
LocationChangeCommand::LocationChangeCommand(QVector4D newLocation, AxialSliceWidget *axialWidget, CoronalSliceWidget *coronalWidget,
Expand Down
22 changes: 22 additions & 0 deletions commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class CommandID : int
CoronalMoveEnd = 20,
AxialScale,
CoronalScale,
ResetView,
LocationChange,
BrightnessChange,
BrightnessThresChange,
Expand Down Expand Up @@ -100,6 +101,27 @@ class CoronalScaleCommand : public QUndoCommand
int id() const override { return (int)CommandID::CoronalScale; }
};

class ResetViewCommand : public QUndoCommand
{
private:
QVector3D oldAxialTranslate;
float oldAxialScaling;

QVector3D oldCoronalTranslate;
float oldCoronalScaling;

AxialSliceWidget *axialWidget;
CoronalSliceWidget *coronalWidget;

public:
ResetViewCommand(AxialSliceWidget *axialWidget, CoronalSliceWidget *coronalWidget, QUndoCommand *parent = NULL);

void undo() override;
void redo() override;
bool mergeWith(const QUndoCommand *command) override;
int id() const override { return (int)CommandID::ResetView; }
};

class LocationChangeCommand : public QUndoCommand
{
private:
Expand Down
11 changes: 10 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ void MainWindow::on_actionExit_triggered()
void MainWindow::on_actionAbout_triggered()
{
QMessageBox aboutBox(QMessageBox::Information, "About the Program",
QObject::tr("<html><head/><body><p><span style=\" font-weight:600;\">Visceral Fat Validation v%1</span></p><p><span style=\" font-weight:600;\">Creator:</span> Addison Elliott</p><p><span style=\" font-weight:600;\">Release Date: </span>1/19/2017</p><p><span style=\" font-weight:600;\">Advisor:</span> Jon Klingensmith</p><p><span style=\" font-weight:600;\">School:</span> Southern Illinois University Edwardsville</p></body></html>")
QObject::tr("<p><span style=\"font-weight: 600;\">Visceral Fat Validation v%1</span></p>"
"<p><span style=\"font-weight: 600;\">Creator:</span> Addison Elliott</p>"
"<p><span style=\"font-weight: 600;\">Release Date: </span>2/06/2017</p>"
"<p><span style=\"font-weight: 600;\">Advisor:</span> Jon Klingensmith</p>"
"<p><span style=\"font-weight: 600;\">School:</span> Southern Illinois University Edwardsville</p>"
"<p><strong>Thanks To:&nbsp;</strong></p>"
"<ul>"
"<li><a href=\"https://thenounproject.com/terrence.k.oleary\" data-reactid=\".2.2:$row=10.$hero.0.$hero=1meta=13715.$hero=13715=1meta=1info.0.1.1\">Terrence Kevin Oleary</a>&nbsp;- Eraser icon in Tracing tab</li>"
"<li><a href=\"https://thenounproject.com/latyshevaanastasia1\" data-reactid=\".3.2:$row=10.$hero.0.$hero=1meta=1811391.$hero=1811391=1meta=1info.0.1.1\">Anastasia Latysheva</a>&nbsp;- Pencil icon in Tracing tab</li>"
"</ul>")
.arg(QCoreApplication::applicationVersion()),
QMessageBox::Ok, this);
aboutBox.setTextFormat(Qt::RichText);
Expand Down
3 changes: 1 addition & 2 deletions view_axialcoronalhires.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,7 @@ void viewAxialCoronalHiRes::on_waterFatRadioBtn_toggled(bool checked)

void viewAxialCoronalHiRes::on_resetViewBtn_clicked()
{
ui->glWidgetAxial->resetView();
ui->glWidgetCoronal->resetView();
undoStack->push(new ResetViewCommand(ui->glWidgetAxial, ui->glWidgetCoronal));
}

void viewAxialCoronalHiRes::changeTracingLayer(TracingLayer newLayer)
Expand Down
3 changes: 1 addition & 2 deletions view_axialcoronallores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@ void viewAxialCoronalLoRes::on_waterFatRadioBtn_toggled(bool checked)

void viewAxialCoronalLoRes::on_resetViewBtn_clicked()
{
ui->glWidgetAxial->resetView();
ui->glWidgetCoronal->resetView();
undoStack->push(new ResetViewCommand(ui->glWidgetAxial, ui->glWidgetCoronal));
}

void viewAxialCoronalLoRes::changeTracingLayer(TracingLayer newLayer)
Expand Down

0 comments on commit 11e5422

Please sign in to comment.