mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 08:09:39 +00:00
record loading progress bar
This commit is contained in:
parent
6692d2dc72
commit
6bc5869222
7 changed files with 77 additions and 22 deletions
|
@ -29,8 +29,10 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con
|
||||||
this, SLOT (documentNotLoaded (Document *, const std::string&)));
|
this, SLOT (documentNotLoaded (Document *, const std::string&)));
|
||||||
connect (this, SIGNAL (loadRequest (CSMDoc::Document *)),
|
connect (this, SIGNAL (loadRequest (CSMDoc::Document *)),
|
||||||
&mLoader, SLOT (loadDocument (CSMDoc::Document *)));
|
&mLoader, SLOT (loadDocument (CSMDoc::Document *)));
|
||||||
connect (&mLoader, SIGNAL (nextStage (CSMDoc::Document *, const std::string&)),
|
connect (&mLoader, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)),
|
||||||
this, SIGNAL (nextStage (CSMDoc::Document *, const std::string&)));
|
this, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)));
|
||||||
|
connect (&mLoader, SIGNAL (nextRecord (CSMDoc::Document *)),
|
||||||
|
this, SIGNAL (nextRecord (CSMDoc::Document *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMDoc::DocumentManager::~DocumentManager()
|
CSMDoc::DocumentManager::~DocumentManager()
|
||||||
|
|
|
@ -72,7 +72,9 @@ namespace CSMDoc
|
||||||
void loadingStopped (CSMDoc::Document *document, bool completed,
|
void loadingStopped (CSMDoc::Document *document, bool completed,
|
||||||
const std::string& error);
|
const std::string& error);
|
||||||
|
|
||||||
void nextStage (CSMDoc::Document *document, const std::string& name);
|
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||||
|
|
||||||
|
void nextRecord (CSMDoc::Document *document);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,20 @@ void CSMDoc::Loader::load()
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
|
const int batchingSize = 100;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (iter->second.mRecordsLeft)
|
if (iter->second.mRecordsLeft)
|
||||||
{
|
{
|
||||||
if (document->getData().continueLoading())
|
for (int i=0; i<batchingSize; ++i) // do not flood the system with update signals
|
||||||
iter->second.mRecordsLeft = false;
|
if (document->getData().continueLoading())
|
||||||
|
{
|
||||||
|
iter->second.mRecordsLeft = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit nextRecord (document);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -56,17 +64,17 @@ void CSMDoc::Loader::load()
|
||||||
{
|
{
|
||||||
boost::filesystem::path path = document->getContentFiles()[iter->second.mFile];
|
boost::filesystem::path path = document->getContentFiles()[iter->second.mFile];
|
||||||
|
|
||||||
emit nextStage (document, path.filename().string());
|
int steps = document->getData().startLoading (path, iter->second.mFile<size-1, false);
|
||||||
|
|
||||||
document->getData().startLoading (path, iter->second.mFile<size-1, false);
|
|
||||||
iter->second.mRecordsLeft = true;
|
iter->second.mRecordsLeft = true;
|
||||||
|
|
||||||
|
emit nextStage (document, path.filename().string(), steps/batchingSize);
|
||||||
}
|
}
|
||||||
else if (iter->second.mFile==size)
|
else if (iter->second.mFile==size)
|
||||||
{
|
{
|
||||||
emit nextStage (document, "Project File");
|
int steps = document->getData().startLoading (document->getProjectPath(), false, true);
|
||||||
|
|
||||||
document->getData().startLoading (document->getProjectPath(), false, true);
|
|
||||||
iter->second.mRecordsLeft = true;
|
iter->second.mRecordsLeft = true;
|
||||||
|
|
||||||
|
emit nextStage (document, "Project File", steps/batchingSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,7 +56,12 @@ namespace CSMDoc
|
||||||
///< Document load has been interrupted either because of a call to abortLoading
|
///< 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.
|
/// or a problem during loading). In the former case error will be an empty string.
|
||||||
|
|
||||||
void nextStage (CSMDoc::Document *document, const std::string& name);
|
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||||
|
|
||||||
|
void nextRecord (CSMDoc::Document *document);
|
||||||
|
///< \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.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,11 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout (this);
|
QVBoxLayout *layout = new QVBoxLayout (this);
|
||||||
|
|
||||||
|
// file progress
|
||||||
|
mFile = new QLabel (this);
|
||||||
|
|
||||||
|
layout->addWidget (mFile);
|
||||||
|
|
||||||
mFileProgress = new QProgressBar (this);
|
mFileProgress = new QProgressBar (this);
|
||||||
|
|
||||||
layout->addWidget (mFileProgress);
|
layout->addWidget (mFileProgress);
|
||||||
|
@ -27,9 +32,16 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
mFileProgress->setTextVisible (true);
|
mFileProgress->setTextVisible (true);
|
||||||
mFileProgress->setValue (0);
|
mFileProgress->setValue (0);
|
||||||
|
|
||||||
mFile = new QLabel (this);
|
// record progress
|
||||||
|
layout->addWidget (new QLabel ("Records", this));
|
||||||
|
|
||||||
layout->addWidget (mFile);
|
mRecordProgress = new QProgressBar (this);
|
||||||
|
|
||||||
|
layout->addWidget (mRecordProgress);
|
||||||
|
|
||||||
|
mRecordProgress->setMinimum (0);
|
||||||
|
mRecordProgress->setTextVisible (true);
|
||||||
|
mRecordProgress->setValue (0);
|
||||||
|
|
||||||
setLayout (layout);
|
setLayout (layout);
|
||||||
|
|
||||||
|
@ -38,19 +50,28 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::LoadingDocument::nextStage (const std::string& name)
|
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
|
||||||
{
|
{
|
||||||
mFile->setText (QString::fromUtf8 (("Loading: " + name).c_str()));
|
mFile->setText (QString::fromUtf8 (("Loading: " + name).c_str()));
|
||||||
|
|
||||||
mFileProgress->setValue (mFileProgress->value()+1);
|
mFileProgress->setValue (mFileProgress->value()+1);
|
||||||
|
|
||||||
|
mRecordProgress->setValue (0);
|
||||||
|
mRecordProgress->setMaximum (steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CSVDoc::Loader::Loader()
|
void CSVDoc::LoadingDocument::nextRecord()
|
||||||
{
|
{
|
||||||
|
int value = mRecordProgress->value()+1;
|
||||||
|
|
||||||
|
if (value<=mRecordProgress->maximum())
|
||||||
|
mRecordProgress->setValue (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSVDoc::Loader::Loader() {}
|
||||||
|
|
||||||
CSVDoc::Loader::~Loader()
|
CSVDoc::Loader::~Loader()
|
||||||
{
|
{
|
||||||
for (std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter (mDocuments.begin());
|
for (std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter (mDocuments.begin());
|
||||||
|
@ -79,10 +100,18 @@ void CSVDoc::Loader::loadingStopped (CSMDoc::Document *document, bool completed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVDoc::Loader::nextStage (CSMDoc::Document *document, const std::string& name)
|
void CSVDoc::Loader::nextStage (CSMDoc::Document *document, const std::string& name, int steps)
|
||||||
{
|
{
|
||||||
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||||
|
|
||||||
if (iter!=mDocuments.end())
|
if (iter!=mDocuments.end())
|
||||||
iter->second->nextStage (name);
|
iter->second->nextStage (name, steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVDoc::Loader::nextRecord (CSMDoc::Document *document)
|
||||||
|
{
|
||||||
|
std::map<CSMDoc::Document *, LoadingDocument *>::iterator iter = mDocuments.find (document);
|
||||||
|
|
||||||
|
if (iter!=mDocuments.end())
|
||||||
|
iter->second->nextRecord();
|
||||||
}
|
}
|
|
@ -22,12 +22,15 @@ namespace CSVDoc
|
||||||
|
|
||||||
QLabel *mFile;
|
QLabel *mFile;
|
||||||
QProgressBar *mFileProgress;
|
QProgressBar *mFileProgress;
|
||||||
|
QProgressBar *mRecordProgress;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
LoadingDocument (CSMDoc::Document *document);
|
LoadingDocument (CSMDoc::Document *document);
|
||||||
|
|
||||||
void nextStage (const std::string& name);
|
void nextStage (const std::string& name, int steps);
|
||||||
|
|
||||||
|
void nextRecord();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Loader : public QObject
|
class Loader : public QObject
|
||||||
|
@ -49,7 +52,9 @@ namespace CSVDoc
|
||||||
void loadingStopped (CSMDoc::Document *document, bool completed,
|
void loadingStopped (CSMDoc::Document *document, bool completed,
|
||||||
const std::string& error);
|
const std::string& error);
|
||||||
|
|
||||||
void nextStage (CSMDoc::Document *document, const std::string& name);
|
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
|
||||||
|
|
||||||
|
void nextRecord (CSMDoc::Document *document);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,12 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
|
||||||
&mLoader, SLOT (loadingStopped (CSMDoc::Document *, bool, const std::string&)));
|
&mLoader, SLOT (loadingStopped (CSMDoc::Document *, bool, const std::string&)));
|
||||||
|
|
||||||
connect (
|
connect (
|
||||||
&mDocumentManager, SIGNAL (nextStage (CSMDoc::Document *, const std::string&)),
|
&mDocumentManager, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)),
|
||||||
&mLoader, SLOT (nextStage (CSMDoc::Document *, const std::string&)));
|
&mLoader, SLOT (nextStage (CSMDoc::Document *, const std::string&, int)));
|
||||||
|
|
||||||
|
connect (
|
||||||
|
&mDocumentManager, SIGNAL (nextRecord (CSMDoc::Document *)),
|
||||||
|
&mLoader, SLOT (nextRecord (CSMDoc::Document *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVDoc::ViewManager::~ViewManager()
|
CSVDoc::ViewManager::~ViewManager()
|
||||||
|
|
Loading…
Reference in a new issue