2012-11-21 16:31:18 +00:00
|
|
|
|
|
|
|
#include "document.hpp"
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
CSMDoc::Document::Document()
|
|
|
|
{
|
|
|
|
connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool)));
|
2012-11-22 23:36:01 +00:00
|
|
|
|
|
|
|
// dummy implementation -> remove when proper save is implemented.
|
|
|
|
mSaveCount = 0;
|
|
|
|
connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving()));
|
2012-11-22 22:42:17 +00:00
|
|
|
}
|
2012-11-22 14:54:31 +00:00
|
|
|
|
|
|
|
QUndoStack& CSMDoc::Document::getUndoStack()
|
|
|
|
{
|
|
|
|
return mUndoStack;
|
2012-11-22 22:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int CSMDoc::Document::getState() const
|
|
|
|
{
|
|
|
|
int state = 0;
|
|
|
|
|
|
|
|
if (!mUndoStack.isClean())
|
|
|
|
state |= State_Modified;
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
if (mSaveCount)
|
2012-11-23 09:25:34 +00:00
|
|
|
state |= State_Locked | State_Saving | State_Progress;
|
2012-11-22 23:36:01 +00:00
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
void CSMDoc::Document::save()
|
|
|
|
{
|
|
|
|
mSaveCount = 1;
|
|
|
|
mSaveTimer.start (500);
|
2012-11-22 23:51:04 +00:00
|
|
|
emit stateChanged (getState(), this);
|
2012-11-23 09:25:34 +00:00
|
|
|
emit progress (1, 16, this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Document::abortSave()
|
|
|
|
{
|
|
|
|
mSaveTimer.stop();
|
2012-11-22 23:51:04 +00:00
|
|
|
emit stateChanged (getState(), this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
void CSMDoc::Document::modificationStateChanged (bool clean)
|
|
|
|
{
|
|
|
|
emit stateChanged (getState(), this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::Document::saving()
|
|
|
|
{
|
|
|
|
++mSaveCount;
|
|
|
|
|
2012-11-23 09:25:34 +00:00
|
|
|
emit progress (mSaveCount, 16, this);
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
if (mSaveCount>15)
|
|
|
|
{
|
|
|
|
mSaveCount = 0;
|
|
|
|
mSaveTimer.stop();
|
|
|
|
mUndoStack.setClean();
|
2012-11-22 23:51:04 +00:00
|
|
|
emit stateChanged (getState(), this);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
2012-11-22 14:54:31 +00:00
|
|
|
}
|