implemented a dummy save function (does not actually save anything)

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

@ -4,6 +4,10 @@
CSMDoc::Document::Document()
{
connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool)));
// dummy implementation -> remove when proper save is implemented.
mSaveCount = 0;
connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving()));
}
QUndoStack& CSMDoc::Document::getUndoStack()
@ -18,10 +22,36 @@ int CSMDoc::Document::getState() const
if (!mUndoStack.isClean())
state |= State_Modified;
if (mSaveCount)
state |= State_Locked | State_Saving;
return state;
}
void CSMDoc::Document::save()
{
mSaveCount = 1;
mSaveTimer.start (500);
}
void CSMDoc::Document::abortSave()
{
mSaveTimer.stop();
}
void CSMDoc::Document::modificationStateChanged (bool clean)
{
emit stateChanged (getState(), this);
}
void CSMDoc::Document::saving()
{
++mSaveCount;
if (mSaveCount>15)
{
mSaveCount = 0;
mSaveTimer.stop();
mUndoStack.setClean();
}
}

@ -3,6 +3,7 @@
#include <QUndoStack>
#include <QObject>
#include <QTimer>
namespace CSMDoc
{
@ -14,11 +15,16 @@ namespace CSMDoc
enum State
{
State_Modified = 1
State_Modified = 1,
State_Locked = 2,
State_Saving = 4
};
QUndoStack mUndoStack;
int mSaveCount; ///< dummy implementation -> remove when proper save is implemented.
QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented.
// not implemented
Document (const Document&);
Document& operator= (const Document&);
@ -31,6 +37,10 @@ namespace CSMDoc
int getState() const;
void save();
void abortSave();
signals:
void stateChanged (int state, CSMDoc::Document *document);
@ -38,6 +48,9 @@ namespace CSMDoc
private slots:
void modificationStateChanged (bool clean);
void saving();
///< dummy implementation -> remove when proper save is implemented.
};
}

@ -16,6 +16,15 @@ void CSVDoc::View::closeEvent (QCloseEvent *event)
event->ignore();
}
void CSVDoc::View::setupFileMenu()
{
QMenu *file = menuBar()->addMenu (tr ("&File"));
QAction *save = new QAction (tr ("&Save"), this);
connect (save, SIGNAL (triggered()), this, SLOT (save()));
file->addAction (save);
}
void CSVDoc::View::setupEditMenu()
{
QMenu *edit = menuBar()->addMenu (tr ("&Edit"));
@ -45,6 +54,7 @@ void CSVDoc::View::setupViewMenu()
void CSVDoc::View::setupUi()
{
setupFileMenu();
setupEditMenu();
setupViewMenu();
}
@ -105,4 +115,9 @@ void CSVDoc::View::newView()
void CSVDoc::View::test()
{
mDocument->getUndoStack().push (new QUndoCommand());
}
void CSVDoc::View::save()
{
mDocument->save();
}

@ -31,6 +31,8 @@ namespace CSVDoc
void closeEvent (QCloseEvent *event);
void setupFileMenu();
void setupEditMenu();
void setupViewMenu();
@ -57,6 +59,8 @@ namespace CSVDoc
void newView();
void test();
void save();
};
}

@ -99,4 +99,4 @@ void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *doc
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
if ((*iter)->getDocument()==document)
(*iter)->updateDocumentState();
}
}

Loading…
Cancel
Save