Skip to content

Commit

Permalink
Initial implementation for undo/redo on efficiency field
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Oct 30, 2020
1 parent 9e2a81f commit cd48493
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ SET( brewtarget_SRCS
${SRCDIR}/RangedSlider.cpp
${SRCDIR}/recipe.cpp
${SRCDIR}/RecipeFormatter.cpp
${SRCDIR}/RecipeUndoableUpdate.cpp
${SRCDIR}/RefractoDialog.cpp
${SRCDIR}/salt.cpp
${SRCDIR}/SaltTableModel.cpp
Expand Down
14 changes: 13 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "MiscTableModel.h"
#include "style.h"
#include "recipe.h"
#include "RecipeUndoableUpdate.h"
#include "MainWindow.h"
#include "AboutDialog.h"
#include "database.h"
Expand Down Expand Up @@ -1256,7 +1257,10 @@ void MainWindow::updateRecipeEfficiency()
if( recipeObs == nullptr )
return;

recipeObs->setEfficiency_pct( lineEdit_efficiency->toSI() );
this->doOrRedoUpdate(new RecipeUndoableUpdate(*this->recipeObs,
RecipeUndoableUpdate::Attribute::Efficiency,
lineEdit_efficiency->toSI()));
return;
}

void MainWindow::addFermentableToRecipe(Fermentable* ferm)
Expand Down Expand Up @@ -1331,6 +1335,14 @@ void MainWindow::setUndoRedoEnable()
return;
}

void MainWindow::doOrRedoUpdate(QUndoCommand * update)
{
Q_ASSERT(this->undoStack != 0);
this->undoStack->push(update);
this->setUndoRedoEnable();
return;
}

// For undo/redo, we use Qt's Undo framework
void MainWindow::editUndo()
{
Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ private slots:

//! \brief Set whether undo / redo commands are enabled
void setUndoRedoEnable();
void doOrRedoUpdate(QUndoCommand * update);

private:
Recipe* recipeObs;
Expand Down

0 comments on commit cd48493

Please sign in to comment.