Skip to content

Commit 11e5422

Browse files
Add command for ResetView so that the scaling/translation for a widget
cannot be messed up by doing scaling, reset view, and then undoing the command.
1 parent e44b4c2 commit 11e5422

5 files changed

Lines changed: 77 additions & 5 deletions

File tree

commands.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,49 @@ bool CoronalScaleCommand::mergeWith(const QUndoCommand *command)
199199
return true;
200200
}
201201

202+
// ResetViewCommand
203+
// --------------------------------------------------------------------------------------------------------------------
204+
ResetViewCommand::ResetViewCommand(AxialSliceWidget *axialWidget, CoronalSliceWidget *coronalWidget, QUndoCommand *parent) : QUndoCommand(parent),
205+
oldAxialTranslate(axialWidget->rtranslation()), oldAxialScaling(axialWidget->rscaling()), oldCoronalTranslate(coronalWidget->rtranslation()),
206+
oldCoronalScaling(coronalWidget->rscaling()), axialWidget(axialWidget), coronalWidget(coronalWidget)
207+
{
208+
// Updates text that is shown on QUndoView
209+
setText(QObject::tr("Reset view"));
210+
}
211+
212+
void ResetViewCommand::undo()
213+
{
214+
axialWidget->rtranslation() = oldAxialTranslate;
215+
axialWidget->rscaling() = oldAxialScaling;
216+
217+
coronalWidget->rtranslation() = oldCoronalTranslate;
218+
coronalWidget->rscaling() = oldCoronalScaling;
219+
220+
// Tell the screen to draw itself since the scene changed
221+
axialWidget->update();
222+
coronalWidget->update();
223+
}
224+
225+
void ResetViewCommand::redo()
226+
{
227+
// Reset the view for the axial and coronal widget
228+
axialWidget->resetView();
229+
coronalWidget->resetView();
230+
231+
// Tell the screen to draw itself since the scene changed
232+
axialWidget->update();
233+
coronalWidget->update();
234+
}
235+
236+
bool ResetViewCommand::mergeWith(const QUndoCommand *command)
237+
{
238+
(void)command;
239+
240+
// Do nothing
241+
242+
return true;
243+
}
244+
202245
// LocationChangeCommand
203246
// --------------------------------------------------------------------------------------------------------------------
204247
LocationChangeCommand::LocationChangeCommand(QVector4D newLocation, AxialSliceWidget *axialWidget, CoronalSliceWidget *coronalWidget,

commands.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum class CommandID : int
3030
CoronalMoveEnd = 20,
3131
AxialScale,
3232
CoronalScale,
33+
ResetView,
3334
LocationChange,
3435
BrightnessChange,
3536
BrightnessThresChange,
@@ -100,6 +101,27 @@ class CoronalScaleCommand : public QUndoCommand
100101
int id() const override { return (int)CommandID::CoronalScale; }
101102
};
102103

104+
class ResetViewCommand : public QUndoCommand
105+
{
106+
private:
107+
QVector3D oldAxialTranslate;
108+
float oldAxialScaling;
109+
110+
QVector3D oldCoronalTranslate;
111+
float oldCoronalScaling;
112+
113+
AxialSliceWidget *axialWidget;
114+
CoronalSliceWidget *coronalWidget;
115+
116+
public:
117+
ResetViewCommand(AxialSliceWidget *axialWidget, CoronalSliceWidget *coronalWidget, QUndoCommand *parent = NULL);
118+
119+
void undo() override;
120+
void redo() override;
121+
bool mergeWith(const QUndoCommand *command) override;
122+
int id() const override { return (int)CommandID::ResetView; }
123+
};
124+
103125
class LocationChangeCommand : public QUndoCommand
104126
{
105127
private:

mainwindow.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ void MainWindow::on_actionExit_triggered()
8989
void MainWindow::on_actionAbout_triggered()
9090
{
9191
QMessageBox aboutBox(QMessageBox::Information, "About the Program",
92-
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>")
92+
QObject::tr("<p><span style=\"font-weight: 600;\">Visceral Fat Validation v%1</span></p>"
93+
"<p><span style=\"font-weight: 600;\">Creator:</span> Addison Elliott</p>"
94+
"<p><span style=\"font-weight: 600;\">Release Date: </span>2/06/2017</p>"
95+
"<p><span style=\"font-weight: 600;\">Advisor:</span> Jon Klingensmith</p>"
96+
"<p><span style=\"font-weight: 600;\">School:</span> Southern Illinois University Edwardsville</p>"
97+
"<p><strong>Thanks To:&nbsp;</strong></p>"
98+
"<ul>"
99+
"<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>"
100+
"<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>"
101+
"</ul>")
93102
.arg(QCoreApplication::applicationVersion()),
94103
QMessageBox::Ok, this);
95104
aboutBox.setTextFormat(Qt::RichText);

view_axialcoronalhires.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,7 @@ void viewAxialCoronalHiRes::on_waterFatRadioBtn_toggled(bool checked)
742742

743743
void viewAxialCoronalHiRes::on_resetViewBtn_clicked()
744744
{
745-
ui->glWidgetAxial->resetView();
746-
ui->glWidgetCoronal->resetView();
745+
undoStack->push(new ResetViewCommand(ui->glWidgetAxial, ui->glWidgetCoronal));
747746
}
748747

749748
void viewAxialCoronalHiRes::changeTracingLayer(TracingLayer newLayer)

view_axialcoronallores.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@ void viewAxialCoronalLoRes::on_waterFatRadioBtn_toggled(bool checked)
743743

744744
void viewAxialCoronalLoRes::on_resetViewBtn_clicked()
745745
{
746-
ui->glWidgetAxial->resetView();
747-
ui->glWidgetCoronal->resetView();
746+
undoStack->push(new ResetViewCommand(ui->glWidgetAxial, ui->glWidgetCoronal));
748747
}
749748

750749
void viewAxialCoronalLoRes::changeTracingLayer(TracingLayer newLayer)

0 commit comments

Comments
 (0)