Skip to content

Commit

Permalink
Added a fix step in CLI to fix functions signatures that includes OUT
Browse files Browse the repository at this point in the history
parameters.

Reverted the previous way to create thread in ModelExportForm.
  • Loading branch information
rkhaotix committed Apr 5, 2015
1 parent 04e904e commit 56aa0e4
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 142 deletions.
2 changes: 1 addition & 1 deletion libpgmodeler/src/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Parameter::Parameter(void)
{
obj_type=OBJ_PARAMETER;
is_in=is_out=is_variadic=false;
is_in=is_out=is_variadic=false;
}

void Parameter::setType(PgSQLType type)
Expand Down
244 changes: 108 additions & 136 deletions libpgmodeler_ui/src/modelexportform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

ModelExportForm::ModelExportForm(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{
model=nullptr;
export_thread=nullptr;
export_hlp=nullptr;

model=nullptr;
setupUi(this);

export_thread=new QThread(this);
export_hlp.moveToThread(export_thread);

pgsqlvers_ht=new HintTextWidget(pgsqlvers_hint, this);
pgsqlvers_ht->setText(pgsqlvers_chk->statusTip());

Expand All @@ -44,23 +44,31 @@ ModelExportForm::ModelExportForm(QWidget *parent, Qt::WindowFlags f) : QDialog(p
connect(export_to_file_rb, SIGNAL(clicked()), this, SLOT(selectExportMode(void)));
connect(export_to_dbms_rb, SIGNAL(clicked()), this, SLOT(selectExportMode(void)));
connect(export_to_img_rb, SIGNAL(clicked()), this, SLOT(selectExportMode(void)));
connect(pgsqlvers_chk, SIGNAL(toggled(bool)), pgsqlvers1_cmb, SLOT(setEnabled(bool)));
connect(close_btn, SIGNAL(clicked(bool)), this, SLOT(close(void)));
connect(select_file_tb, SIGNAL(clicked(void)), this, SLOT(selectOutputFile(void)));
connect(select_img_tb, SIGNAL(clicked(void)), this, SLOT(selectOutputFile(void)));
connect(export_btn, SIGNAL(clicked(void)), this, SLOT(exportModel(void)));
connect(pgsqlvers_chk, SIGNAL(toggled(bool)), pgsqlvers1_cmb, SLOT(setEnabled(bool)));
connect(close_btn, SIGNAL(clicked(bool)), this, SLOT(close(void)));
connect(select_file_tb, SIGNAL(clicked(void)), this, SLOT(selectOutputFile(void)));
connect(select_img_tb, SIGNAL(clicked(void)), this, SLOT(selectOutputFile(void)));
connect(export_btn, SIGNAL(clicked(void)), this, SLOT(exportModel(void)));
connect(drop_chk, SIGNAL(toggled(bool)), drop_db_rb, SLOT(setEnabled(bool)));
connect(drop_chk, SIGNAL(toggled(bool)), drop_objs_rb, SLOT(setEnabled(bool)));

connect(&export_hlp, SIGNAL(s_progressUpdated(int,QString,ObjectType,QString)), this, SLOT(updateProgress(int,QString,ObjectType,QString)));
connect(export_thread, SIGNAL(started(void)), &export_hlp, SLOT(exportToDBMS(void)));
connect(&export_hlp, SIGNAL(s_exportFinished(void)), this, SLOT(handleExportFinished(void)));
connect(&export_hlp, SIGNAL(s_exportCanceled(void)), this, SLOT(handleExportCanceled(void)));
connect(&export_hlp, SIGNAL(s_errorIgnored(QString,QString,QString)), this, SLOT(handleErrorIgnored(QString,QString,QString)));
connect(&export_hlp, SIGNAL(s_exportAborted(Exception)), this, SLOT(captureThreadError(Exception)));
connect(cancel_btn, SIGNAL(clicked(bool)), this, SLOT(cancelExport(void)));

pgsqlvers_cmb->addItems(PgSQLVersions::ALL_VERSIONS);
pgsqlvers1_cmb->addItems(PgSQLVersions::ALL_VERSIONS);

double values[]={ ModelWidget::MINIMUM_ZOOM, 0.5f, 0.75f, 1, 1.25f, 1.50f, 1.75f, 2,
2.25, 2.50, 2.75, 3, 3.25, 3.50, 3.75, ModelWidget::MAXIMUM_ZOOM };
unsigned cnt=sizeof(values)/sizeof(double);
double values[]={ ModelWidget::MINIMUM_ZOOM, 0.5f, 0.75f, 1, 1.25f, 1.50f, 1.75f, 2,
2.25, 2.50, 2.75, 3, 3.25, 3.50, 3.75, ModelWidget::MAXIMUM_ZOOM };
unsigned cnt=sizeof(values)/sizeof(double);

for(unsigned i=0; i < cnt; i++)
zoom_cmb->addItem(QString("%1%").arg(values[i] * 100), QVariant(values[i]));
for(unsigned i=0; i < cnt; i++)
zoom_cmb->addItem(QString("%1%").arg(values[i] * 100), QVariant(values[i]));

zoom_cmb->setCurrentText(QString("100%"));

Expand All @@ -69,13 +77,13 @@ ModelExportForm::ModelExportForm(QWidget *parent, Qt::WindowFlags f) : QDialog(p

void ModelExportForm::exec(ModelWidget *model)
{
if(model)
{
this->model=model;
if(model)
{
this->model=model;
ConnectionsConfigWidget::fillConnectionsComboBox(connections_cmb);
selectExportMode();
QDialog::exec();
}
QDialog::exec();
}
}

void ModelExportForm::handleErrorIgnored(QString err_code, QString err_msg, QString cmd)
Expand All @@ -102,18 +110,16 @@ void ModelExportForm::updateProgress(int progress, QString msg, ObjectType obj_t
QPixmap ico;

progress_lbl->setText(text);
progress_pb->setValue(progress);
progress_pb->setValue(progress);


if(obj_type!=BASE_OBJECT)
if(obj_type!=BASE_OBJECT)
ico=QPixmap(QString(":/icones/icones/") + BaseObject::getSchemaName(obj_type) + QString(".png"));
else if(!cmd.isEmpty())
ico=QPixmap(QString(":/icones/icones/codigosql.png"));
else
else
ico=QPixmap(QString(":/icones/icones/msgbox_info.png"));

ico_lbl->setPixmap(ico);

item=PgModelerUiNS::createOutputTreeItem(output_trw, text, ico, nullptr, false, false);

if(!cmd.isEmpty())
Expand All @@ -127,61 +133,56 @@ void ModelExportForm::updateProgress(int progress, QString msg, ObjectType obj_t
fnt.setPointSizeF(8.0);
cmd_label->setFont(fnt);
}

}

void ModelExportForm::exportModel(void)
{
try
{
createThread();

try
{
output_trw->clear();
settings_tbw->setTabEnabled(1, true);
settings_tbw->setCurrentIndex(1);

//Export to png
if(export_to_img_rb->isChecked())
export_hlp->exportToPNG(model->scene, image_edt->text(), zoom_cmb->itemData(zoom_cmb->currentIndex()).toDouble(),
//Export to png
if(export_to_img_rb->isChecked())
export_hlp.exportToPNG(model->scene, image_edt->text(), zoom_cmb->itemData(zoom_cmb->currentIndex()).toDouble(),
show_grid_chk->isChecked(), show_delim_chk->isChecked(), page_by_page_chk->isChecked());
else
{
progress_lbl->setText(trUtf8("Initializing model export..."));

//Exporting to sql file
if(export_to_file_rb->isChecked())
{
progress_lbl->setText(trUtf8("Saving file '%1'").arg(file_edt->text()));
export_hlp->exportToSQL(model->db_model, file_edt->text(), pgsqlvers_cmb->currentText());
}
//Exporting directly to DBMS
else
{
QString version;
else
{
progress_lbl->setText(trUtf8("Initializing model export..."));

//Exporting to sql file
if(export_to_file_rb->isChecked())
{
progress_lbl->setText(trUtf8("Saving file '%1'").arg(file_edt->text()));
export_hlp.exportToSQL(model->db_model, file_edt->text(), pgsqlvers_cmb->currentText());
}
//Exporting directly to DBMS
else
{
QString version;
Connection *conn=reinterpret_cast<Connection *>(connections_cmb->itemData(connections_cmb->currentIndex()).value<void *>());

//If the user chose a specific version
if(pgsqlvers1_cmb->isEnabled())
version=pgsqlvers1_cmb->currentText();
//If the user chose a specific version
if(pgsqlvers1_cmb->isEnabled())
version=pgsqlvers1_cmb->currentText();

export_hlp->setExportToDBMSParams(model->db_model, conn, version, ignore_dup_chk->isChecked(),
export_hlp.setExportToDBMSParams(model->db_model, conn, version, ignore_dup_chk->isChecked(),
drop_chk->isChecked() && drop_db_rb->isChecked(),
drop_chk->isChecked() && drop_objs_rb->isChecked());

export_hlp->moveToThread(export_thread);
export_thread->start();
enableExportModes(false);
cancel_btn->setEnabled(true);
}
}
}
catch(Exception &e)
{
Messagebox msg_box;

finishExport(trUtf8("Exporting process aborted!"));
msg_box.show(e);
}
enableExportModes(false);
cancel_btn->setEnabled(true);
}
}
}
catch(Exception &e)
{
Messagebox msg_box;

finishExport(trUtf8("Exporting process aborted!"));
msg_box.show(e);
}
}

void ModelExportForm::selectExportMode(void)
Expand All @@ -206,40 +207,40 @@ void ModelExportForm::selectExportMode(void)

void ModelExportForm::selectOutputFile(void)
{
QFileDialog file_dlg;
QFileDialog file_dlg;

file_dlg.setWindowTitle(trUtf8("Export model as..."));
file_dlg.setWindowTitle(trUtf8("Export model as..."));

file_dlg.setFileMode(QFileDialog::AnyFile);
file_dlg.setAcceptMode(QFileDialog::AcceptSave);
file_dlg.setModal(true);
file_dlg.setFileMode(QFileDialog::AnyFile);
file_dlg.setAcceptMode(QFileDialog::AcceptSave);
file_dlg.setModal(true);

if(export_to_file_rb->isChecked())
{
file_dlg.setNameFilter(trUtf8("SQL code (*.sql);;All files (*.*)"));
if(export_to_file_rb->isChecked())
{
file_dlg.setNameFilter(trUtf8("SQL code (*.sql);;All files (*.*)"));
file_dlg.selectFile(model->getDatabaseModel()->getName() + QString(".sql"));
}
else
{
file_dlg.setNameFilter(trUtf8("PNG image (*.png);;All files (*.*)"));
}
else
{
file_dlg.setNameFilter(trUtf8("PNG image (*.png);;All files (*.*)"));
file_dlg.selectFile(model->getDatabaseModel()->getName() + QString(".png"));
}
}


if(file_dlg.exec()==QFileDialog::Accepted)
{
QString file;
if(file_dlg.exec()==QFileDialog::Accepted)
{
QString file;

if(!file_dlg.selectedFiles().isEmpty())
file = file_dlg.selectedFiles().at(0);
if(!file_dlg.selectedFiles().isEmpty())
file = file_dlg.selectedFiles().at(0);

if(export_to_file_rb->isChecked())
file_edt->setText(file);
else
image_edt->setText(file);
}
if(export_to_file_rb->isChecked())
file_edt->setText(file);
else
image_edt->setText(file);
}

export_btn->setEnabled(!file_edt->text().isEmpty() || !image_edt->text().isEmpty());
export_btn->setEnabled(!file_edt->text().isEmpty() || !image_edt->text().isEmpty());
}

void ModelExportForm::captureThreadError(Exception e)
Expand All @@ -251,15 +252,15 @@ void ModelExportForm::captureThreadError(Exception e)
PgModelerUiNS::createOutputTreeItem(output_trw, PgModelerUiNS::formatMessage(e.getExtraInfo()), QPixmap(), item, true);

finishExport(trUtf8("Exporting process aborted!"));
ico_lbl->setPixmap(QPixmap(QString(":/icones/icones/msgbox_erro.png")));
ico_lbl->setPixmap(QPixmap(QString(":/icones/icones/msgbox_erro.png")));

throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
}

void ModelExportForm::cancelExport(void)
{
export_hlp->cancelExport();
cancel_btn->setEnabled(false);
export_hlp.cancelExport();
cancel_btn->setEnabled(false);
}

void ModelExportForm::handleExportCanceled(void)
Expand All @@ -282,61 +283,32 @@ void ModelExportForm::handleExportFinished(void)
PgModelerUiNS::createOutputTreeItem(output_trw, msg, ico);
}

void ModelExportForm::createThread(void)
{
export_thread=new QThread(this);
export_hlp=new ModelExportHelper;

connect(export_hlp, SIGNAL(s_progressUpdated(int,QString,ObjectType,QString)), this, SLOT(updateProgress(int,QString,ObjectType,QString)));
connect(export_thread, SIGNAL(started(void)), export_hlp, SLOT(exportToDBMS(void)));
connect(export_hlp, SIGNAL(s_exportFinished(void)), this, SLOT(handleExportFinished(void)));
connect(export_hlp, SIGNAL(s_exportCanceled(void)), this, SLOT(handleExportCanceled(void)));
connect(export_hlp, SIGNAL(s_errorIgnored(QString,QString,QString)), this, SLOT(handleErrorIgnored(QString,QString,QString)));
connect(export_hlp, SIGNAL(s_exportAborted(Exception)), this, SLOT(captureThreadError(Exception)));
connect(cancel_btn, SIGNAL(clicked(bool)), this, SLOT(cancelExport(void)));
}

void ModelExportForm::destroyThread(void)
void ModelExportForm::finishExport(const QString &msg)
{
if(export_hlp)
{
if(export_thread->isRunning())
export_thread->quit();
export_thread->wait();

delete(export_thread);
delete(export_hlp);

export_thread=nullptr;
export_hlp=nullptr;
}
}
enableExportModes(true);

void ModelExportForm::finishExport(const QString &msg)
{
//if(export_thread->isRunning())
// export_thread->quit();
destroyThread();
enableExportModes(true);

cancel_btn->setEnabled(false);
progress_pb->setValue(100);
progress_lbl->setText(msg);
progress_lbl->repaint();
cancel_btn->setEnabled(false);
progress_pb->setValue(100);
progress_lbl->setText(msg);
progress_lbl->repaint();
}

void ModelExportForm::enableExportModes(bool value)
{
export_to_dbms_rb->setEnabled(value);
export_to_file_rb->setEnabled(value);
export_to_img_rb->setEnabled(value);
export_btn->setEnabled(value);
close_btn->setEnabled(value);
export_to_dbms_rb->setEnabled(value);
export_to_file_rb->setEnabled(value);
export_to_img_rb->setEnabled(value);
export_btn->setEnabled(value);
close_btn->setEnabled(value);
}

void ModelExportForm::closeEvent(QCloseEvent *event)
{
/* Ignore the close event when the thread is running this avoid
close the form and make thread execute in background */
if(export_thread && export_thread->isRunning())
event->ignore();
/* Ignore the close event when the thread is running this avoid
close the form and make thread execute in background */
if(export_thread->isRunning())
event->ignore();
}
4 changes: 1 addition & 3 deletions libpgmodeler_ui/src/modelexportform.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ class ModelExportForm: public QDialog, public Ui::ModelExportForm {
ModelWidget *model;

//! \brief Export helper
ModelExportHelper *export_hlp;
ModelExportHelper export_hlp;

//! \brief Thread used to manage the export helper when dealing with dbms export
QThread *export_thread;

HintTextWidget *pgsqlvers_ht, *drop_ht, *ignore_dup_ht, *page_by_page_ht;

void createThread(void);
void destroyThread(void);
void finishExport(const QString &msg);
void enableExportModes(bool value);
void closeEvent(QCloseEvent *event);
Expand Down
Loading

0 comments on commit 56aa0e4

Please sign in to comment.