mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
replaced dummy save implementation with a threaded dummy save implementation
This commit is contained in:
parent
d71d282952
commit
8326ac9b6f
@ -5,11 +5,11 @@ opencs_units (. editor)
|
||||
set (CMAKE_BUILD_TYPE DEBUG)
|
||||
|
||||
opencs_units (model/doc
|
||||
document operation
|
||||
document operation saving
|
||||
)
|
||||
|
||||
opencs_units_noqt (model/doc
|
||||
documentmanager stage
|
||||
documentmanager stage savingstate savingstages
|
||||
)
|
||||
|
||||
opencs_hdrs_noqt (model/doc
|
||||
|
@ -2141,7 +2141,7 @@ void CSMDoc::Document::createBase()
|
||||
|
||||
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
|
||||
const boost::filesystem::path& savePath, bool new_)
|
||||
: mSavePath (savePath), mTools (mData)
|
||||
: mSavePath (savePath), mTools (mData), mSaving (*this)
|
||||
{
|
||||
if (files.empty())
|
||||
throw std::runtime_error ("Empty content file sequence");
|
||||
@ -2166,9 +2166,8 @@ CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
|
||||
connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
|
||||
connect (&mTools, SIGNAL (done (int)), this, SLOT (operationDone (int)));
|
||||
|
||||
// dummy implementation -> remove when proper save is implemented.
|
||||
mSaveCount = 0;
|
||||
connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving()));
|
||||
connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
|
||||
connect (&mSaving, SIGNAL (done (int)), this, SLOT (operationDone (int)));
|
||||
}
|
||||
|
||||
CSMDoc::Document::~Document()
|
||||
@ -2187,7 +2186,7 @@ int CSMDoc::Document::getState() const
|
||||
if (!mUndoStack.isClean())
|
||||
state |= State_Modified;
|
||||
|
||||
if (mSaveCount)
|
||||
if (mSaving.isRunning())
|
||||
state |= State_Locked | State_Saving | State_Operation;
|
||||
|
||||
if (int operations = mTools.getRunningOperations())
|
||||
@ -2203,10 +2202,13 @@ const boost::filesystem::path& CSMDoc::Document::getSavePath() const
|
||||
|
||||
void CSMDoc::Document::save()
|
||||
{
|
||||
mSaveCount = 1;
|
||||
mSaveTimer.start (500);
|
||||
if (mSaving.isRunning())
|
||||
throw std::logic_error (
|
||||
"Failed to initiate save, because a save operation is already running.");
|
||||
|
||||
mSaving.start();
|
||||
|
||||
emit stateChanged (getState(), this);
|
||||
emit progress (1, 16, State_Saving, 1, this);
|
||||
}
|
||||
|
||||
CSMWorld::UniversalId CSMDoc::Document::verify()
|
||||
@ -2218,17 +2220,12 @@ CSMWorld::UniversalId CSMDoc::Document::verify()
|
||||
|
||||
void CSMDoc::Document::abortOperation (int type)
|
||||
{
|
||||
mTools.abortOperation (type);
|
||||
|
||||
if (type==State_Saving)
|
||||
{
|
||||
mSaveCount=0;
|
||||
mSaveTimer.stop();
|
||||
emit stateChanged (getState(), this);
|
||||
}
|
||||
mSaving.abort();
|
||||
else
|
||||
mTools.abortOperation (type);
|
||||
}
|
||||
|
||||
|
||||
void CSMDoc::Document::modificationStateChanged (bool clean)
|
||||
{
|
||||
emit stateChanged (getState(), this);
|
||||
@ -2240,24 +2237,6 @@ void CSMDoc::Document::operationDone (int type)
|
||||
emit stateChanged (getState(), this);
|
||||
}
|
||||
|
||||
void CSMDoc::Document::saving()
|
||||
{
|
||||
++mSaveCount;
|
||||
|
||||
emit progress (mSaveCount, 16, State_Saving, 1, this);
|
||||
|
||||
if (mSaveCount>15)
|
||||
{
|
||||
//clear the stack before resetting the save state
|
||||
//to avoid emitting incorrect states
|
||||
mUndoStack.setClean();
|
||||
|
||||
mSaveCount = 0;
|
||||
mSaveTimer.stop();
|
||||
emit stateChanged (getState(), this);
|
||||
}
|
||||
}
|
||||
|
||||
const CSMWorld::Data& CSMDoc::Document::getData() const
|
||||
{
|
||||
return mData;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../tools/tools.hpp"
|
||||
|
||||
#include "state.hpp"
|
||||
#include "saving.hpp"
|
||||
|
||||
class QAbstractItemModel;
|
||||
|
||||
@ -34,14 +35,12 @@ namespace CSMDoc
|
||||
boost::filesystem::path mSavePath;
|
||||
CSMWorld::Data mData;
|
||||
CSMTools::Tools mTools;
|
||||
Saving mSaving;
|
||||
|
||||
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
|
||||
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
|
||||
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&);
|
||||
@ -100,9 +99,6 @@ namespace CSMDoc
|
||||
|
||||
void operationDone (int type);
|
||||
|
||||
void saving();
|
||||
///< dummy implementation -> remove when proper save is implemented.
|
||||
|
||||
public slots:
|
||||
|
||||
void progress (int current, int max, int type);
|
||||
|
14
apps/opencs/model/doc/saving.cpp
Normal file
14
apps/opencs/model/doc/saving.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
#include "saving.hpp"
|
||||
|
||||
#include "state.hpp"
|
||||
|
||||
#include "savingstages.hpp"
|
||||
|
||||
CSMDoc::Saving::Saving (Document& document)
|
||||
: Operation (State_Saving, true, true), mDocument (document), mState (*this)
|
||||
{
|
||||
|
||||
|
||||
appendStage (new FinalSavingStage (mDocument, mState));
|
||||
}
|
25
apps/opencs/model/doc/saving.hpp
Normal file
25
apps/opencs/model/doc/saving.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef CSM_DOC_SAVING_H
|
||||
#define CSM_DOC_SAVING_H
|
||||
|
||||
#include "operation.hpp"
|
||||
#include "savingstate.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
|
||||
class Saving : public Operation
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Document& mDocument;
|
||||
SavingState mState;
|
||||
|
||||
public:
|
||||
|
||||
Saving (Document& document);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
30
apps/opencs/model/doc/savingstages.cpp
Normal file
30
apps/opencs/model/doc/savingstages.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
#include "savingstages.hpp"
|
||||
|
||||
#include <QUndoStack>
|
||||
|
||||
#include "document.hpp"
|
||||
#include "savingstate.hpp"
|
||||
|
||||
CSMDoc::FinalSavingStage::FinalSavingStage (Document& document, SavingState& state)
|
||||
: mDocument (document), mState (state)
|
||||
{}
|
||||
|
||||
int CSMDoc::FinalSavingStage::setup()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CSMDoc::FinalSavingStage::perform (int stage, std::vector<std::string>& messages)
|
||||
{
|
||||
if (mState.hasError())
|
||||
{
|
||||
/// \todo close stream
|
||||
/// \todo delete tmp file
|
||||
}
|
||||
else
|
||||
{
|
||||
/// \todo delete file, rename tmp file
|
||||
mDocument.getUndoStack().setClean();
|
||||
}
|
||||
}
|
28
apps/opencs/model/doc/savingstages.hpp
Normal file
28
apps/opencs/model/doc/savingstages.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef CSM_DOC_SAVINGSTAGES_H
|
||||
#define CSM_DOC_SAVINGSTAGES_H
|
||||
|
||||
#include "stage.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
class SavingState;
|
||||
|
||||
class FinalSavingStage : public Stage
|
||||
{
|
||||
Document& mDocument;
|
||||
SavingState& mState;
|
||||
|
||||
public:
|
||||
|
||||
FinalSavingStage (Document& document, SavingState& state);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
|
||||
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||
///< Messages resulting from this stage will be appended to \a messages.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
13
apps/opencs/model/doc/savingstate.cpp
Normal file
13
apps/opencs/model/doc/savingstate.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#include "savingstate.hpp"
|
||||
|
||||
#include "operation.hpp"
|
||||
|
||||
CSMDoc::SavingState::SavingState (Operation& operation)
|
||||
: mOperation (operation)
|
||||
{}
|
||||
|
||||
bool CSMDoc::SavingState::hasError() const
|
||||
{
|
||||
return mOperation.hasError();
|
||||
}
|
22
apps/opencs/model/doc/savingstate.hpp
Normal file
22
apps/opencs/model/doc/savingstate.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef CSM_DOC_SAVINGSTATE_H
|
||||
#define CSM_DOC_SAVINGSTATE_H
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Operation;
|
||||
|
||||
class SavingState
|
||||
{
|
||||
Operation& mOperation;
|
||||
|
||||
public:
|
||||
|
||||
SavingState (Operation& operation);
|
||||
|
||||
bool hasError() const;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user