kexi
kexidbsubform.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kexidbsubform.h"
00022
00023 #include "kexidbform.h"
00024 #include "../kexiformview.h"
00025 #include <kexidb/utils.h>
00026 #include <formeditor/formIO.h>
00027 #include <formeditor/objecttree.h>
00028 #include <formeditor/utils.h>
00029 #include <formeditor/container.h>
00030 #include <formeditor/formmanager.h>
00031
00032 KexiDBSubForm::KexiDBSubForm(KFormDesigner::Form *parentForm, QWidget *parent, const char *name)
00033 : QScrollView(parent, name), m_parentForm(parentForm), m_form(0), m_widget(0)
00034 {
00035 setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
00036 viewport()->setPaletteBackgroundColor(colorGroup().mid());
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 void
00063 KexiDBSubForm::setFormName(const QString &name)
00064 {
00065 if(m_formName==name)
00066 return;
00067
00068 m_formName = name;
00069
00070 if(name.isEmpty()) {
00071 delete m_widget;
00072 m_widget = 0;
00073 updateScrollBars();
00074 return;
00075 }
00076
00077 QWidget *pw = parentWidget();
00078 KexiFormView *view = 0;
00079 QStringList list;
00080 while(pw) {
00081 if(pw->isA("KexiDBSubForm")) {
00082 if(list.contains(pw->name())) {
00084 return;
00085 }
00086 list.append(pw->name());
00087 }
00088 else if(! view && pw->isA("KexiFormView"))
00089 view = static_cast<KexiFormView*>(pw);
00090 pw = pw->parentWidget();
00091 }
00092
00093 if (!view || !view->parentDialog() || !view->parentDialog()->mainWin()
00094 || !view->parentDialog()->mainWin()->project()->dbConnection())
00095 return;
00096
00097 KexiDB::Connection *conn = view->parentDialog()->mainWin()->project()->dbConnection();
00098
00099
00100 int id = KexiDB::idForObjectName(*conn, name, KexiPart::FormObjectType);
00101 if((id == 0) || (id == view->parentDialog()->id()))
00102 return;
00103
00104
00105 delete m_widget;
00106 m_widget = new KexiDBFormBase(viewport(), "KexiDBSubForm_widget");
00107 m_widget->show();
00108 addChild(m_widget);
00109 m_form = new KFormDesigner::Form(KexiFormPart::library(), this->name());
00110 m_form->createToplevel(m_widget);
00111
00112
00113 QString data;
00114 bool ok = conn->loadDataBlock(id, data, QString::null);
00115 if (ok)
00116 ok = KFormDesigner::FormIO::loadFormFromString(m_form, m_widget, data);
00117 if(!ok) {
00118 delete m_widget;
00119 m_widget = 0;
00120 updateScrollBars();
00121 m_formName = QString::null;
00122 return;
00123 }
00124 m_form->setDesignMode(false);
00125
00126
00127 KFormDesigner::ObjectTreeItem *tree = m_parentForm->objectTree()->lookup(QObject::name());
00128 KFormDesigner::installRecursiveEventFilter(this, tree->eventEater());
00129 }
00130
00131 #include "kexidbsubform.moc"
|