Add menu entries for undo/redo

Add an edit menu with undo and redo submenus, and connect them to
the UndoBuffer class. The submenus are only enabled when needed.

Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Grace Karanja 2015-02-09 09:24:32 +01:00 committed by Dirk Hohndel
parent 853dfa6673
commit c5138b2090
3 changed files with 49 additions and 1 deletions

View file

@ -31,6 +31,7 @@
#include "usermanual.h" #include "usermanual.h"
#endif #endif
#include <QNetworkProxy> #include <QNetworkProxy>
#include "undobuffer.h"
MainWindow *MainWindow::m_Instance = NULL; MainWindow *MainWindow::m_Instance = NULL;
@ -77,6 +78,7 @@ MainWindow::MainWindow() : QMainWindow(),
connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated())); connect(DivePlannerPointsModel::instance(), SIGNAL(planCreated()), this, SLOT(planCreated()));
connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled())); connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled()));
connect(ui.printPlan, SIGNAL(pressed()), ui.divePlannerWidget, SLOT(printDecoPlan())); connect(ui.printPlan, SIGNAL(pressed()), ui.divePlannerWidget, SLOT(printDecoPlan()));
connect(ui.menu_Edit, SIGNAL(aboutToShow()), this, SLOT(checkForUndoAndRedo()));
#ifdef NO_PRINTING #ifdef NO_PRINTING
ui.printPlan->hide(); ui.printPlan->hide();
#endif #endif
@ -152,6 +154,7 @@ MainWindow::MainWindow() : QMainWindow(),
toolBar->setContentsMargins(zeroMargins); toolBar->setContentsMargins(zeroMargins);
updateManager = new UpdateManager(this); updateManager = new UpdateManager(this);
undoBuffer = new UndoBuffer(this);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -1466,3 +1469,19 @@ void MainWindow::on_actionFilterTags_triggered()
else else
ui.multiFilter->setVisible(true); ui.multiFilter->setVisible(true);
} }
void MainWindow::on_action_Undo_triggered()
{
undoBuffer->undo();
}
void MainWindow::on_action_Redo_triggered()
{
undoBuffer->redo();
}
void MainWindow::checkForUndoAndRedo()
{
ui.action_Undo->setEnabled(undoBuffer->canUndo());
ui.action_Redo->setEnabled(undoBuffer->canRedo());
}

View file

@ -30,6 +30,7 @@ class QWebView;
class QSettings; class QSettings;
class UpdateManager; class UpdateManager;
class UserManual; class UserManual;
class UndoBuffer;
enum MainWindowTitleFormat { enum MainWindowTitleFormat {
MWTF_DEFAULT, MWTF_DEFAULT,
@ -82,6 +83,7 @@ public:
void setPlanNotes(const char *notes); void setPlanNotes(const char *notes);
void printPlan(); void printPlan();
void checkSurvey(QSettings *s); void checkSurvey(QSettings *s);
UndoBuffer *undoBuffer;
private private
slots: slots:
/* file menu action */ /* file menu action */
@ -151,6 +153,9 @@ slots:
void on_paste_triggered(); void on_paste_triggered();
void on_actionFilterTags_triggered(); void on_actionFilterTags_triggered();
void on_actionConfigure_Dive_Computer_triggered(); void on_actionConfigure_Dive_Computer_triggered();
void on_action_Undo_triggered();
void on_action_Redo_triggered();
void checkForUndoAndRedo();
protected: protected:
void closeEvent(QCloseEvent *); void closeEvent(QCloseEvent *);

View file

@ -195,7 +195,7 @@ p, li { white-space: pre-wrap; }
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1682</width> <width>1682</width>
<height>27</height> <height>25</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -271,7 +271,15 @@ p, li { white-space: pre-wrap; }
<addaction name="actionDownloadWeb"/> <addaction name="actionDownloadWeb"/>
<addaction name="actionDivelogs_de"/> <addaction name="actionDivelogs_de"/>
</widget> </widget>
<widget class="QMenu" name="menu_Edit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="action_Undo"/>
<addaction name="action_Redo"/>
</widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menu_Edit"/>
<addaction name="menuImport"/> <addaction name="menuImport"/>
<addaction name="menuLog"/> <addaction name="menuLog"/>
<addaction name="menuView"/> <addaction name="menuView"/>
@ -813,6 +821,22 @@ p, li { white-space: pre-wrap; }
<string>User &amp;survey</string> <string>User &amp;survey</string>
</property> </property>
</action> </action>
<action name="action_Undo">
<property name="text">
<string>&amp;Undo</string>
</property>
<property name="shortcut">
<string>Ctrl+Z</string>
</property>
</action>
<action name="action_Redo">
<property name="text">
<string>&amp;Redo</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+Z</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>