#include <QApplication>
#include <QProgressDialog>
#include <QVBoxLayout>
namespace gdcm {
class MyQtWatcher : public SimpleSubjectWatcher
{
size_t nfiles;
double progress;
size_t index;
double refprogress;
QWidget* win;
QProgressDialog* qtprogress;
public:
MyQtWatcher(Subject * s, const char *comment = "", QWidget *w = NULL, QProgressDialog* p = NULL, size_t n = 1):
SimpleSubjectWatcher(s,comment),nfiles(n),progress(0),index(0),refprogress(0),win(w),qtprogress(p){}
void ShowIteration()
{
index++;
assert( index <= nfiles );
refprogress = progress;
}
void ShowProgress(Subject *, const Event &evt)
{
const ProgressEvent &pe = dynamic_cast<const ProgressEvent&>(evt);
progress = refprogress + (1. / (double)nfiles ) * pe.GetProgress();
std::cout << "Global Progress: " << progress << " per file progress " << pe.GetProgress() << std::endl;
int i = (int)(progress * 100 + 0.5);
qtprogress->setValue(i);
win->show();
}
virtual void ShowDataSet(Subject *caller, const Event &evt)
{
(void)caller;
(void)evt;
}
};
}
int main(int argc, char *argv[])
{
if( argc < 4 )
{
std::cerr << argv[0] << " remote_server port filename" << std::endl;
return 1;
}
QApplication a(argc, argv);
std::ostringstream error_log;
const char *remote = argv[1];
int portno = atoi(argv[2]);
const char *filename = argv[3];
QVBoxLayout* layout = new QVBoxLayout;
QWidget* win = new QWidget;
QProgressDialog* progress = new QProgressDialog("Sending data...", "Cancel", 0, 100);
progress->setWindowModality(Qt::WindowModal);
layout->addWidget(progress,Qt::AlignCenter);
win->setLayout(layout);
gdcm::MyQtWatcher w( &scu, "QtWatcher", win, progress );
{
std::cerr << "Could not InitializeConnection" << std::endl;
return 1;
}
filenames.push_back( filename );
{
std::cerr << "Could not GenerateFromFilenames" << std::endl;
return 1;
}
{
std::cerr << "Could not Start" << std::endl;
return 1;
}
{
std::cerr << "Could not Store" << std::endl;
std::cerr << "Error log is:" << std::endl;
std::cerr << error_log.str() << std::endl;
return 1;
}
{
std::cerr << "Could not Stop" << std::endl;
return 1;
}
win->show();
return a.exec();
}