Import dialog and import progress moved to core library.
							parent
							
								
									25c481f5f1
								
							
						
					
					
						commit
						0e803c23cb
					
				| 
		 Before Width: | Height: | Size: 820 B After Width: | Height: | Size: 820 B  | 
@ -0,0 +1,36 @@
 | 
			
		||||
#include "importdialog.h"
 | 
			
		||||
#include "ui_importdialog.h"
 | 
			
		||||
#include "importprogress.h"
 | 
			
		||||
#include "csvimporter.h"
 | 
			
		||||
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
#include <QDesktopWidget>
 | 
			
		||||
 | 
			
		||||
ImportDialog::ImportDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::ImportDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImportDialog::~ImportDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ImportDialog::fileName()
 | 
			
		||||
{
 | 
			
		||||
    return ui->editFile->text();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ImportDialog::separator()
 | 
			
		||||
{
 | 
			
		||||
    return ui->editSeparator->text();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportDialog::on_btnFile_clicked()
 | 
			
		||||
{
 | 
			
		||||
    QString file = QFileDialog::getOpenFileName(this, tr("Import file"), "", tr("All Files (*.*)"));
 | 
			
		||||
    ui->editFile->setText(file);
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,34 @@
 | 
			
		||||
#include "importprogress.h"
 | 
			
		||||
#include "ui_importprogress.h"
 | 
			
		||||
 | 
			
		||||
ImportProgress::ImportProgress(QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::ImportProgress)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    ui->progressBar->setRange(0, 100);
 | 
			
		||||
    ui->progressBar->setValue(0);
 | 
			
		||||
 | 
			
		||||
    m_terminate = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImportProgress::~ImportProgress()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportProgress::on_btnCancel_clicked()
 | 
			
		||||
{
 | 
			
		||||
    m_terminate = true;
 | 
			
		||||
    this->close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportProgress::updateProgress(int currentPos)
 | 
			
		||||
{
 | 
			
		||||
    ui->progressBar->setValue(currentPos);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImportProgress::terminate()
 | 
			
		||||
{
 | 
			
		||||
    return m_terminate;
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
#ifndef IMPORTPROGRESS_H
 | 
			
		||||
#define IMPORTPROGRESS_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include "iimportprogress.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ImportProgress;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ImportProgress : public QWidget, public IImportProgress
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ImportProgress(QWidget *parent = 0);
 | 
			
		||||
    ~ImportProgress();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void on_btnCancel_clicked();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ImportProgress *ui;
 | 
			
		||||
    bool m_terminate;
 | 
			
		||||
 | 
			
		||||
    // IImportProgress interface
 | 
			
		||||
public:
 | 
			
		||||
    void updateProgress(int currentPos);
 | 
			
		||||
    bool terminate();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // IMPORTPROGRESS_H
 | 
			
		||||
@ -1,46 +0,0 @@
 | 
			
		||||
#include "importdialog.h"
 | 
			
		||||
#include "ui_importdialog.h"
 | 
			
		||||
 | 
			
		||||
#include <service.h>
 | 
			
		||||
#include <csvimporter.h>
 | 
			
		||||
#include <QDesktopWidget>
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
 | 
			
		||||
#include "data/postdata.h"
 | 
			
		||||
#include "postregister-odb.hxx"
 | 
			
		||||
#include "importprogressform.h"
 | 
			
		||||
 | 
			
		||||
ImportDialog::ImportDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::ImportDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImportDialog::~ImportDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportDialog::on_buttonBox_accepted()
 | 
			
		||||
{
 | 
			
		||||
    QString fileName = ui->editFile->text();
 | 
			
		||||
    Service<PostData> service;
 | 
			
		||||
    PostData pd;
 | 
			
		||||
    CsvImporter importer(pd.metaObject());
 | 
			
		||||
 | 
			
		||||
    importer.setImportFile(fileName);
 | 
			
		||||
    importer.setSeparator(ui->editSparator->text());
 | 
			
		||||
 | 
			
		||||
    ImportProgressForm *progress = new ImportProgressForm();
 | 
			
		||||
    progress->move(QApplication::desktop()->screen()->rect().center() - progress->rect().center());
 | 
			
		||||
    progress->setWindowModality(Qt::ApplicationModal);
 | 
			
		||||
    progress->show();
 | 
			
		||||
    service.importData(&importer, progress);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportDialog::on_btnFile_clicked()
 | 
			
		||||
{
 | 
			
		||||
    QString file = QFileDialog::getOpenFileName(this, tr("Import file"), "", tr("All Files (*.*)"));
 | 
			
		||||
    ui->editFile->setText(file);
 | 
			
		||||
}
 | 
			
		||||
@ -1,34 +0,0 @@
 | 
			
		||||
#include "importprogressform.h"
 | 
			
		||||
#include "ui_importprogressform.h"
 | 
			
		||||
 | 
			
		||||
ImportProgressForm::ImportProgressForm(QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::ImportProgressForm)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    ui->progressBar->setRange(0, 100);
 | 
			
		||||
    ui->progressBar->setValue(0);
 | 
			
		||||
 | 
			
		||||
    m_terminate = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImportProgressForm::~ImportProgressForm()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportProgressForm::on_btnCancel_clicked()
 | 
			
		||||
{
 | 
			
		||||
    m_terminate = true;
 | 
			
		||||
    this->close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImportProgressForm::updateProgress(int currentPos)
 | 
			
		||||
{
 | 
			
		||||
    ui->progressBar->setValue(currentPos);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImportProgressForm::terminate()
 | 
			
		||||
{
 | 
			
		||||
    return m_terminate;
 | 
			
		||||
}
 | 
			
		||||
@ -1,32 +0,0 @@
 | 
			
		||||
#ifndef IMPORTPROGRESSFORM_H
 | 
			
		||||
#define IMPORTPROGRESSFORM_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <iimportprogress.h>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ImportProgressForm;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ImportProgressForm : public QWidget, public IImportProgress
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ImportProgressForm(QWidget *parent = 0);
 | 
			
		||||
    ~ImportProgressForm();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void on_btnCancel_clicked();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ImportProgressForm *ui;
 | 
			
		||||
    bool m_terminate;
 | 
			
		||||
 | 
			
		||||
    // IImportProgress interface
 | 
			
		||||
public:
 | 
			
		||||
    void updateProgress(int currentPos);
 | 
			
		||||
    bool terminate();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // IMPORTPROGRESSFORM_H
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
<RCC>
 | 
			
		||||
    <qresource prefix="/">
 | 
			
		||||
        <file>icons/import.svg</file>
 | 
			
		||||
    </qresource>
 | 
			
		||||
</RCC>
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue