added cancel button to loading window

deque
Marc Zinnschlag 11 years ago
parent 6bc5869222
commit 3fdd72f204

@ -33,6 +33,8 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con
this, SIGNAL (nextStage (CSMDoc::Document *, const std::string&, int)));
connect (&mLoader, SIGNAL (nextRecord (CSMDoc::Document *)),
this, SIGNAL (nextRecord (CSMDoc::Document *)));
connect (this, SIGNAL (cancelLoading (CSMDoc::Document *)),
&mLoader, SLOT (abortLoading (CSMDoc::Document *)));
}
CSMDoc::DocumentManager::~DocumentManager()

@ -75,6 +75,8 @@ namespace CSMDoc
void nextStage (CSMDoc::Document *document, const std::string& name, int steps);
void nextRecord (CSMDoc::Document *document);
void cancelLoading (CSMDoc::Document *document);
};
}

@ -102,7 +102,7 @@ void CSMDoc::Loader::loadDocument (CSMDoc::Document *document)
mDocuments.push_back (std::make_pair (document, Stage()));
}
void CSMDoc::Loader::abortLoading (Document *document)
void CSMDoc::Loader::abortLoading (CSMDoc::Document *document)
{
for (std::vector<std::pair<Document *, Stage> >::iterator iter = mDocuments.begin();
iter!=mDocuments.end(); ++iter)
@ -114,4 +114,4 @@ void CSMDoc::Loader::abortLoading (Document *document)
break;
}
}
}
}

@ -42,7 +42,7 @@ namespace CSMDoc
void loadDocument (CSMDoc::Document *document);
///< The ownership of \a document is not transferred.
void abortLoading (Document *document);
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.

@ -5,10 +5,12 @@
#include <QLabel>
#include <QProgressBar>
#include <QCursor>
#include <QDialogButtonBox>
#include "../../model/doc/document.hpp"
CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
: mDocument (document)
{
setWindowTitle (("Opening " + document->getSavePath().filename().string()).c_str());
@ -43,11 +45,18 @@ CSVDoc::LoadingDocument::LoadingDocument (CSMDoc::Document *document)
mRecordProgress->setTextVisible (true);
mRecordProgress->setValue (0);
QDialogButtonBox *buttonBox = new QDialogButtonBox (QDialogButtonBox::Cancel, Qt::Horizontal,
this);
layout->addWidget (buttonBox);
setLayout (layout);
move (QCursor::pos());
show();
connect (buttonBox, SIGNAL (rejected()), this, SLOT (cancel()));
}
void CSVDoc::LoadingDocument::nextStage (const std::string& name, int steps)
@ -69,6 +78,11 @@ void CSVDoc::LoadingDocument::nextRecord()
mRecordProgress->setValue (value);
}
void CSVDoc::LoadingDocument::cancel()
{
emit cancel (mDocument);
}
CSVDoc::Loader::Loader() {}
@ -81,7 +95,11 @@ CSVDoc::Loader::~Loader()
void CSVDoc::Loader::add (CSMDoc::Document *document)
{
mDocuments.insert (std::make_pair (document, new LoadingDocument (document)));
LoadingDocument *loading = new LoadingDocument (document);
mDocuments.insert (std::make_pair (document, loading));
connect (loading, SIGNAL (cancel (CSMDoc::Document *)),
this, SIGNAL (cancel (CSMDoc::Document *)));
}
void CSVDoc::Loader::loadingStopped (CSMDoc::Document *document, bool completed,

@ -5,6 +5,7 @@
#include <QObject>
#include <QWidget>
#include <QSignalMapper>
class QLabel;
class QProgressBar;
@ -20,6 +21,7 @@ namespace CSVDoc
{
Q_OBJECT
CSMDoc::Document *mDocument;
QLabel *mFile;
QProgressBar *mFileProgress;
QProgressBar *mRecordProgress;
@ -31,6 +33,14 @@ namespace CSVDoc
void nextStage (const std::string& name, int steps);
void nextRecord();
private slots:
void cancel();
signals:
void cancel (CSMDoc::Document *document);
};
class Loader : public QObject
@ -45,6 +55,10 @@ namespace CSVDoc
virtual ~Loader();
signals:
void cancel (CSMDoc::Document *document);
public slots:
void add (CSMDoc::Document *document);

@ -99,6 +99,10 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
connect (
&mDocumentManager, SIGNAL (nextRecord (CSMDoc::Document *)),
&mLoader, SLOT (nextRecord (CSMDoc::Document *)));
connect (
&mLoader, SIGNAL (cancel (CSMDoc::Document *)),
&mDocumentManager, SIGNAL (cancelLoading (CSMDoc::Document *)));
}
CSVDoc::ViewManager::~ViewManager()

Loading…
Cancel
Save