QWidget * ScriptToolbox::loadUi(const QString & screenName, QWidget * parent) { if(screenName.isEmpty()) return 0; q.prepare("SELECT *" " FROM uiform" " WHERE((uiform_name=:uiform_name)" " AND (uiform_enabled))" " ORDER BY uiform_order" " LIMIT 1;"); q.bindValue(":uiform_name", screenName); q.exec(); if(!q.first()) { QMessageBox::critical(0, tr("Could Not Create Form"), tr("Could not create the required form. Either an error occurred or the specified form does not exist.") ); return 0; } XUiLoader loader; QByteArray ba = q.value("uiform_source").toByteArray(); QBuffer uiFile(&ba); if(!uiFile.open(QIODevice::ReadOnly)) { QMessageBox::critical(0, tr("Could not load file"), tr("There was an error loading the UI Form from the database.")); return 0; } QWidget *ui = loader.load(&uiFile, parent); uiFile.close(); return ui; }
void uiforms::sTest() { q.prepare("SELECT *" " FROM uiform " " WHERE(uiform_id=:uiform_id);"); q.bindValue(":uiform_id", _uiform->id()); q.exec(); if (q.first()) ; // everything's OK else if (q.lastError().type() != QSqlError::NoError) { systemError(this, q.lastError().databaseText(), __FILE__, __LINE__); return; } else return; XMainWindow * wnd = new XMainWindow(); wnd->setObjectName(q.value("uiform_name").toString()); XUiLoader loader; QByteArray ba = q.value("uiform_source").toString().toUtf8(); qDebug("about to load a uiFile with %s", ba.constData()); QBuffer uiFile(&ba); if(!uiFile.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Could not load file"), tr("There was an error loading the UI Form from the database.")); return; } QWidget *ui = loader.load(&uiFile); if (ui) { wnd->setWindowTitle(ui->windowTitle()); wnd->setCentralWidget(ui); omfgThis->handleNewWindow(wnd); } else QMessageBox::critical(this, tr("Could not load file"), tr("<p>Could not interpret the UI Form data " "as a UI definition.")); uiFile.close(); }
QWidget * ScriptToolbox::createWidget(const QString & className, QWidget * parent, const QString & name) { XUiLoader ui; return ui.createWidget(className, parent, name); }
QWidget *ScriptToolbox::openWindow(QString name, QWidget *parent, Qt::WindowModality modality, Qt::WindowFlags flags) { QWidget *returnVal = 0; XSqlQuery screenq; screenq.prepare("SELECT * " "FROM uiform " "WHERE (uiform_name=:uiform_name);"); screenq.bindValue(":uiform_name", name); screenq.exec(); if (screenq.first()) { XUiLoader loader; QByteArray ba = screenq.value("uiform_source").toByteArray(); QBuffer uiFile(&ba); if (!uiFile.open(QIODevice::ReadOnly)) { QMessageBox::critical(0, tr("Could not load UI"), tr("<p>There was an error loading the UI Form " "from the database.")); return 0; } QWidget *ui = loader.load(&uiFile); uiFile.close(); if (ui->inherits("QDialog")) { flags |= Qt::Dialog; if (modality == Qt::NonModal) modality = Qt::WindowModal; } XMainWindow *window = new XMainWindow(parent, screenq.value("uiform_name").toString(), flags); window->setCentralWidget(ui); window->setWindowTitle(ui->windowTitle()); window->setWindowModality(modality); if (ui->inherits("QDialog")) { QDialog *innerdlg = qobject_cast<QDialog*>(ui); connect(innerdlg, SIGNAL(finished(int)), window, SLOT(close())); connect(innerdlg, SIGNAL(accepted()), window, SLOT(close())); connect(innerdlg, SIGNAL(rejected()), window, SLOT(close())); // alternative to creating mydialog object: // for each property of mydialog (including functions) // add a property to _engine's mywindow property if (engine(window)) { QScriptValue mydialog = engine(window)->newQObject(innerdlg); engine(window)->globalObject().setProperty("mydialog", mydialog); } else qWarning("Could not find the script engine to embed a dialog inside " "a placeholder window"); omfgThis->handleNewWindow(window); returnVal = ui; } else { omfgThis->handleNewWindow(window); returnVal = window; } _lastWindow = window; } else if (screenq.lastError().type() != QSqlError::None) { systemError(0, screenq.lastError().databaseText(), __FILE__, __LINE__); return 0; } return returnVal; }