1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/apps/opencs/model/doc/loader.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.1 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 <chrono>
#include <optional>
2022-10-19 17:02:00 +00:00
#include <string>
#include <utility>
2014-04-24 13:09:25 +00:00
#include <vector>
#include <QMutex>
#include <QObject>
#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
{
Q_OBJECT
struct Stage
2022-09-22 18:26:05 +00:00
{
2024-05-19 16:55:37 +00:00
int mFile = 0;
int mRecordsLoaded = 0;
bool mRecordsLeft = false;
2022-09-22 18:26:05 +00:00
};
2014-04-24 13:09:25 +00:00
QMutex mMutex;
QWaitCondition mThingsToDo;
std::vector<std::pair<Document*, Stage>> mDocuments;
QTimer* mTimer;
bool mShouldStop;
2014-04-24 13:09:25 +00:00
std::optional<std::chrono::steady_clock::time_point> mStart;
2022-09-22 18:26:05 +00:00
public:
2014-04-24 13:09:25 +00:00
Loader();
QWaitCondition& hasThingsToDo();
void stop();
2014-04-24 13:09:25 +00:00
private slots:
void load();
public slots:
void loadDocument(CSMDoc::Document* document);
2014-04-24 13:09:25 +00:00
///< The ownership of \a document is not transferred.
2014-05-03 14:44:50 +00:00
void abortLoading(CSMDoc::Document* document);
2014-04-24 13:09:25 +00:00
///< 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.
signals:
void documentLoaded(Document* document);
///< The ownership of \a document is not transferred.
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
2014-06-26 09:41:21 +00:00
void nextStage(CSMDoc::Document* document, const std::string& name, int totalRecords);
2014-05-03 13:33:35 +00:00
2014-06-26 09:41:21 +00:00
void nextRecord(CSMDoc::Document* document, int records);
2014-05-03 13:33:35 +00:00
///< \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.
void loadMessage(CSMDoc::Document* document, const std::string& message);
///< Non-critical load error or warning
2014-04-24 13:09:25 +00:00
};
}
#endif