2014-04-24 13:09:25 +00:00
|
|
|
#ifndef CSM_DOC_LOADER_H
|
|
|
|
#define CSM_DOC_LOADER_H
|
|
|
|
|
2023-02-15 19:56:32 +00:00
|
|
|
#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
|
2014-05-03 10:07:05 +00:00
|
|
|
|
|
|
|
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;
|
2016-06-10 16:10:14 +00:00
|
|
|
QWaitCondition mThingsToDo;
|
|
|
|
std::vector<std::pair<Document*, Stage>> mDocuments;
|
|
|
|
|
|
|
|
QTimer* mTimer;
|
|
|
|
bool mShouldStop;
|
2014-04-24 13:09:25 +00:00
|
|
|
|
2023-02-15 19:56:32 +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();
|
|
|
|
|
2016-06-10 16:10:14 +00:00
|
|
|
void stop();
|
|
|
|
|
2014-04-24 13:09:25 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
void load();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2014-04-29 12:27:44 +00:00
|
|
|
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.
|
2014-05-10 11:18:40 +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
|