implemented edit locking (used during saves)

pull/16/head
Marc Zinnschlag 12 years ago
parent 5838929371
commit 931eb08114

@ -32,11 +32,13 @@ void CSMDoc::Document::save()
{ {
mSaveCount = 1; mSaveCount = 1;
mSaveTimer.start (500); mSaveTimer.start (500);
emit stateChanged (getState(), this);
} }
void CSMDoc::Document::abortSave() void CSMDoc::Document::abortSave()
{ {
mSaveTimer.stop(); mSaveTimer.stop();
emit stateChanged (getState(), this);
} }
void CSMDoc::Document::modificationStateChanged (bool clean) void CSMDoc::Document::modificationStateChanged (bool clean)
@ -53,5 +55,6 @@ void CSMDoc::Document::saving()
mSaveCount = 0; mSaveCount = 0;
mSaveTimer.stop(); mSaveTimer.stop();
mUndoStack.setClean(); mUndoStack.setClean();
emit stateChanged (getState(), this);
} }
} }

@ -23,24 +23,26 @@ void CSVDoc::View::setupFileMenu()
QAction *save = new QAction (tr ("&Save"), this); QAction *save = new QAction (tr ("&Save"), this);
connect (save, SIGNAL (triggered()), this, SLOT (save())); connect (save, SIGNAL (triggered()), this, SLOT (save()));
file->addAction (save); file->addAction (save);
mEditingActions.push_back (save);
} }
void CSVDoc::View::setupEditMenu() void CSVDoc::View::setupEditMenu()
{ {
QMenu *edit = menuBar()->addMenu (tr ("&Edit")); QMenu *edit = menuBar()->addMenu (tr ("&Edit"));
QAction *undo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo")); mUndo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo"));
undo->setShortcuts (QKeySequence::Undo); mUndo->setShortcuts (QKeySequence::Undo);
edit->addAction (undo); edit->addAction (mUndo);
QAction *redo = mDocument->getUndoStack().createRedoAction (this, tr("&Redo")); mRedo= mDocument->getUndoStack().createRedoAction (this, tr("&Redo"));
redo->setShortcuts (QKeySequence::Redo); mRedo->setShortcuts (QKeySequence::Redo);
edit->addAction (redo); edit->addAction (mRedo);
// test // test
QAction *test = new QAction (tr ("&Test Command"), this); QAction *test = new QAction (tr ("&Test Command"), this);
connect (test, SIGNAL (triggered()), this, SLOT (test())); connect (test, SIGNAL (triggered()), this, SLOT (test()));
edit->addAction (test); edit->addAction (test);
mEditingActions.push_back (test);
} }
void CSVDoc::View::setupViewMenu() void CSVDoc::View::setupViewMenu()
@ -74,6 +76,17 @@ void CSVDoc::View::updateTitle()
setWindowTitle (stream.str().c_str()); setWindowTitle (stream.str().c_str());
} }
void CSVDoc::View::updateActions()
{
bool editing = !(mDocument->getState() & CSMDoc::Document::State_Locked);
for (std::vector<QAction *>::iterator iter (mEditingActions.begin()); iter!=mEditingActions.end(); ++iter)
(*iter)->setEnabled (editing);
mUndo->setEnabled (editing & mDocument->getUndoStack().canUndo());
mRedo->setEnabled (editing & mDocument->getUndoStack().canRedo());
}
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews) CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews)
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews) : mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews)
{ {
@ -105,6 +118,7 @@ void CSVDoc::View::setIndex (int viewIndex, int totalViews)
void CSVDoc::View::updateDocumentState() void CSVDoc::View::updateDocumentState()
{ {
updateTitle(); updateTitle();
updateActions();
} }
void CSVDoc::View::newView() void CSVDoc::View::newView()

@ -1,6 +1,8 @@
#ifndef CSV_DOC_VIEW_H #ifndef CSV_DOC_VIEW_H
#define CSV_DOC_VIEW_H #define CSV_DOC_VIEW_H
#include <vector>
#include <QMainWindow> #include <QMainWindow>
class QAction; class QAction;
@ -22,6 +24,9 @@ namespace CSVDoc
CSMDoc::Document *mDocument; CSMDoc::Document *mDocument;
int mViewIndex; int mViewIndex;
int mViewTotal; int mViewTotal;
QAction *mUndo;
QAction *mRedo;
std::vector<QAction *> mEditingActions;
// not implemented // not implemented
View (const View&); View (const View&);
@ -41,6 +46,8 @@ namespace CSVDoc
void updateTitle(); void updateTitle();
void updateActions();
public: public:
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews); View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);

Loading…
Cancel
Save