diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 5a9e1e99cc..ca235042a6 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -7,6 +7,8 @@ set (OPENCS_SRC model/world/universalid.cpp model/world/idcollection.cpp model/world/data.cpp model/world/idtable.cpp model/world/commands.cpp model/world/idtableproxymodel.cpp model/world/record.cpp + model/tools/tools.cpp model/tools/verifier.cpp + view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp view/world/subview.cpp view/world/table.cpp view/world/tablesubview.cpp @@ -21,6 +23,8 @@ set (OPENCS_HDR model/world/idtable.hpp model/world/columns.hpp model/world/idtableproxymodel.hpp model/world/commands.hpp + model/tools/tools.hpp model/tools/verifier.hpp + view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp view/world/subview.hpp view/world/table.hpp view/world/tablesubview.hpp diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index e8091b3e00..f85fde0382 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -7,13 +7,16 @@ CSMDoc::Document::Document (const std::string& name) connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool))); + 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())); // dummy implementation -> remove when proper verify is implemented. mVerifyCount = 0; - connect (&mVerifyTimer, SIGNAL(timeout()), this, SLOT (verifying())); + } QUndoStack& CSMDoc::Document::getUndoStack() @@ -53,23 +56,19 @@ void CSMDoc::Document::save() void CSMDoc::Document::verify() { mVerifyCount = 1; - mVerifyTimer.start (500); emit stateChanged (getState(), this); - emit progress (1, 20, State_Verifying, 1, this); + mTools.runVerifier(); } void CSMDoc::Document::abortOperation (int type) { + mTools.abortOperation (type); + if (type==State_Saving) { mSaveTimer.stop(); emit stateChanged (getState(), this); } - else if (type==State_Verifying) - { - mVerifyTimer.stop(); - emit stateChanged (getState(), this); - } } void CSMDoc::Document::modificationStateChanged (bool clean) @@ -77,6 +76,14 @@ void CSMDoc::Document::modificationStateChanged (bool clean) emit stateChanged (getState(), this); } +void CSMDoc::Document::operationDone (int type) +{ + if (type==State_Verifying) + mVerifyCount = 0; + + emit stateChanged (getState(), this); +} + void CSMDoc::Document::saving() { ++mSaveCount; @@ -92,20 +99,6 @@ void CSMDoc::Document::saving() } } -void CSMDoc::Document::verifying() -{ - ++mVerifyCount; - - emit progress (mVerifyCount, 20, State_Verifying, 1, this); - - if (mVerifyCount>19) - { - mVerifyCount = 0; - mVerifyTimer.stop(); - emit stateChanged (getState(), this); - } -} - const CSMWorld::Data& CSMDoc::Document::getData() const { return mData; @@ -114,4 +107,9 @@ const CSMWorld::Data& CSMDoc::Document::getData() const CSMWorld::Data& CSMDoc::Document::getData() { return mData; +} + +void CSMDoc::Document::progress (int current, int max, int type) +{ + emit progress (current, max, type, 1, this); } \ No newline at end of file diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index b414bf04d4..3fe20bc80e 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -9,6 +9,8 @@ #include "../world/data.hpp" +#include "../tools/tools.hpp" + namespace CSMDoc { class Document : public QObject @@ -32,12 +34,12 @@ namespace CSMDoc std::string mName; ///< \todo replace name with ESX list QUndoStack mUndoStack; CSMWorld::Data mData; + CSMTools::Tools mTools; int mSaveCount; ///< dummy implementation -> remove when proper save is implemented. QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented. int mVerifyCount; ///< dummy implementation -> remove when proper verify is implemented. - QTimer mVerifyTimer; ///< dummy implementation -> remove when proper verify is implemented. // not implemented Document (const Document&); @@ -75,11 +77,14 @@ namespace CSMDoc void modificationStateChanged (bool clean); + void operationDone (int type); + void saving(); ///< dummy implementation -> remove when proper save is implemented. - void verifying(); - ///< dummy implementation -> remove when proper verify is implemented. + public slots: + + void progress (int current, int max, int type); }; } diff --git a/apps/opencs/model/tools/tools.cpp b/apps/opencs/model/tools/tools.cpp new file mode 100644 index 0000000000..941a22cfff --- /dev/null +++ b/apps/opencs/model/tools/tools.cpp @@ -0,0 +1,46 @@ + +#include "tools.hpp" + +#include + +#include "verifier.hpp" + +#include "../doc/document.hpp" + +CSMTools::Verifier *CSMTools::Tools::getVerifier() +{ + if (!mVerifier) + { + mVerifier = new Verifier; + + connect (mVerifier, SIGNAL (progress (int, int, int)), this, SIGNAL (progress (int, int, int))); + connect (mVerifier, SIGNAL (finished()), this, SLOT (verifierDone())); + } + + return mVerifier; +} + +CSMTools::Tools::Tools() : mVerifier (0) +{ + +} + +CSMTools::Tools::~Tools() +{ + delete mVerifier; +} + +void CSMTools::Tools::runVerifier() +{ + getVerifier()->start(); +} + +void CSMTools::Tools::abortOperation (int type) +{ + +} + +void CSMTools::Tools::verifierDone() +{ + emit done (CSMDoc::Document::State_Verifying); +} \ No newline at end of file diff --git a/apps/opencs/model/tools/tools.hpp b/apps/opencs/model/tools/tools.hpp new file mode 100644 index 0000000000..65b1d16840 --- /dev/null +++ b/apps/opencs/model/tools/tools.hpp @@ -0,0 +1,45 @@ +#ifndef CSM_TOOLS_TOOLS_H +#define CSM_TOOLS_TOOLS_H + +#include + +namespace CSMTools +{ + class Verifier; + + class Tools : public QObject + { + Q_OBJECT + + Verifier *mVerifier; + + // not implemented + Tools (const Tools&); + Tools& operator= (const Tools&); + + Verifier *getVerifier(); + + public: + + Tools(); + + virtual ~Tools(); + + void runVerifier(); + + void abortOperation (int type); + ///< \attention The operation is not aborted immediately. + + private slots: + + void verifierDone(); + + signals: + + void progress (int current, int max, int type); + + void done (int type); + }; +} + +#endif diff --git a/apps/opencs/model/tools/verifier.cpp b/apps/opencs/model/tools/verifier.cpp new file mode 100644 index 0000000000..43a864289f --- /dev/null +++ b/apps/opencs/model/tools/verifier.cpp @@ -0,0 +1,33 @@ + +#include "verifier.hpp" + +#include + +#include "../doc/document.hpp" + +void CSMTools::Verifier::run() +{ + mStep = 0; + + QTimer timer; + + timer.connect (&timer, SIGNAL (timeout()), this, SLOT (verify())); + + timer.start (0); + + exec(); +} + +void CSMTools::Verifier::abort() +{ + exit(); +} + +void CSMTools::Verifier::verify() +{ + ++mStep; + emit progress (mStep, 1000, CSMDoc::Document::State_Verifying); + + if (mStep>=1000) + exit(); +} \ No newline at end of file diff --git a/apps/opencs/model/tools/verifier.hpp b/apps/opencs/model/tools/verifier.hpp new file mode 100644 index 0000000000..0e7fae19c4 --- /dev/null +++ b/apps/opencs/model/tools/verifier.hpp @@ -0,0 +1,33 @@ +#ifndef CSM_TOOLS_VERIFIER_H +#define CSM_TOOLS_VERIFIER_H + +#include + +namespace CSMTools +{ + class Verifier : public QThread + { + Q_OBJECT + + int mStep; + + public: + + virtual void run(); + + signals: + + void progress (int current, int max, int type); + + public slots: + + void abort(); + + private slots: + + void verify(); + }; + +} + +#endif