1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-23 20:23:54 +00:00
openmw/apps/opencs/model/doc/loader.hpp

79 lines
2 KiB
C++
Raw Normal View History

2014-04-24 13:09:25 +00:00
#ifndef CSM_DOC_LOADER_H
#define CSM_DOC_LOADER_H
#include <vector>
#include <QMutex>
2022-09-22 18:26:05 +00:00
#include <QObject>
2014-04-24 13:09:25 +00:00
#include <QWaitCondition>
2022-10-09 10:39:43 +00:00
class QTimer;
2014-04-24 13:09:25 +00:00
namespace CSMDoc
{
class Document;
class Loader : public QObject
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2022-09-22 18:26:05 +00:00
struct Stage
{
int mFile;
int mRecordsLoaded;
bool mRecordsLeft;
2022-09-22 18:26:05 +00:00
Stage();
};
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
QMutex mMutex;
QWaitCondition mThingsToDo;
std::vector<std::pair<Document*, Stage>> mDocuments;
2022-09-22 18:26:05 +00:00
QTimer* mTimer;
bool mShouldStop;
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
public:
Loader();
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
QWaitCondition& hasThingsToDo();
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
void stop();
2022-09-22 18:26:05 +00:00
private slots:
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
void load();
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
public slots:
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
void loadDocument(CSMDoc::Document* document);
///< The ownership of \a document is not transferred.
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
void abortLoading(CSMDoc::Document* document);
///< Abort loading \a docuemnt (ignored if \a document has already finished being
/// loaded). Will result in a documentNotLoaded signal, once the Loader has finished
/// cleaning up.
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
signals:
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
void documentLoaded(Document* document);
///< The ownership of \a document is not transferred.
2014-04-24 13:09:25 +00:00
2022-09-22 18:26:05 +00:00
void documentNotLoaded(Document* document, const std::string& error);
///< Document load has been interrupted either because of a call to abortLoading
/// or a problem during loading). In the former case error will be an empty string.
2014-05-03 11:01:29 +00:00
2022-09-22 18:26:05 +00:00
void nextStage(CSMDoc::Document* document, const std::string& name, int totalRecords);
2014-05-03 13:33:35 +00:00
2022-09-22 18:26:05 +00:00
void nextRecord(CSMDoc::Document* document, int records);
///< \note This signal is only given once per group of records. The group size is
/// approximately the total number of records divided by the steps value of the
/// previous nextStage signal.
2022-09-22 18:26:05 +00:00
void loadMessage(CSMDoc::Document* document, const std::string& message);
///< Non-critical load error or warning
2014-04-24 13:09:25 +00:00
};
}
#endif