kexi
kexiformmanager.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexiformmanager.h"
00021 #include "widgets/kexidbform.h"
00022 #include "widgets/kexidbautofield.h"
00023 #include "kexiformscrollview.h"
00024 #include "kexiformview.h"
00025 #include "kexidatasourcepage.h"
00026
00027 #include <formeditor/formmanager.h>
00028 #include <formeditor/widgetpropertyset.h>
00029 #include <formeditor/form.h>
00030 #include <formeditor/widgetlibrary.h>
00031 #include <formeditor/commands.h>
00032 #include <formeditor/objecttree.h>
00033
00034 #include <koproperty/set.h>
00035 #include <koproperty/property.h>
00036 #include <widget/kexicustompropertyfactory.h>
00037
00038 KexiFormManager::KexiFormManager(KexiPart::Part *parent, const char* name)
00039 : KFormDesigner::FormManager(parent,
00040 KFormDesigner::FormManager::HideEventsInPopupMenu |
00041 KFormDesigner::FormManager::SkipFileActions |
00042 KFormDesigner::FormManager::HideSignalSlotConnections
00043 , name)
00044 , m_part(parent)
00045 {
00046 m_emitSelectionSignalsUpdatesPropertySet = true;
00047 KexiCustomPropertyFactory::init();
00048 }
00049
00050 KexiFormManager::~KexiFormManager()
00051 {
00052 }
00053
00054 KAction* KexiFormManager::action( const char* name )
00055 {
00056 KActionCollection *col = m_part->actionCollectionForMode(Kexi::DesignViewMode);
00057 if (!col)
00058 return 0;
00059 QCString n( translateName( name ).latin1() );
00060 KAction *a = col->action(n);
00061 if (a)
00062 return a;
00063 KexiDBForm *dbform;
00064 if (!activeForm() || !activeForm()->designMode()
00065 || !(dbform = dynamic_cast<KexiDBForm*>(activeForm()->formWidget())))
00066 return 0;
00067 KexiFormScrollView *scrollViewWidget = dynamic_cast<KexiFormScrollView*>(dbform->dataAwareObject());
00068 if (!scrollViewWidget)
00069 return 0;
00070 KexiFormView* formViewWidget = dynamic_cast<KexiFormView*>(scrollViewWidget->parent());
00071 if (!formViewWidget)
00072 return 0;
00073 return formViewWidget->parentDialog()->mainWin()->actionCollection()->action(n);
00074 }
00075
00076 KexiFormView* KexiFormManager::activeFormViewWidget() const
00077 {
00078 KexiDBForm *dbform;
00079 if (!activeForm() || !activeForm()->designMode()
00080 || !(dbform = dynamic_cast<KexiDBForm*>(activeForm()->formWidget())))
00081 return 0;
00082 KexiFormScrollView *scrollViewWidget = dynamic_cast<KexiFormScrollView*>(dbform->dataAwareObject());
00083 if (!scrollViewWidget)
00084 return 0;
00085 return dynamic_cast<KexiFormView*>(scrollViewWidget->parent());
00086 }
00087
00088 void KexiFormManager::enableAction( const char* name, bool enable )
00089 {
00090 KexiFormView* formViewWidget = activeFormViewWidget();
00091 if (!formViewWidget)
00092 return;
00093
00094
00095 formViewWidget->setAvailable(translateName( name ).latin1(), enable);
00096 }
00097
00098 void KexiFormManager::setFormDataSource(const QCString& mime, const QCString& name)
00099 {
00100 if (!activeForm())
00101 return;
00102 KexiDBForm* formWidget = dynamic_cast<KexiDBForm*>(activeForm()->widget());
00103 if (!formWidget)
00104 return;
00105
00106
00107
00108 QCString oldDataSourceMimeType( formWidget->dataSourceMimeType() );
00109 QCString oldDataSource( formWidget->dataSource().latin1() );
00110 if (mime!=oldDataSourceMimeType || name!=oldDataSource) {
00111 QMap<QCString, QVariant> propValues;
00112 propValues.insert("dataSource", name);
00113 propValues.insert("dataSourceMimeType", mime);
00114 KFormDesigner::CommandGroup *group
00115 = new KFormDesigner::CommandGroup(i18n("Set Form's Data Source to \"%1\"").arg(name), propertySet());
00116 propertySet()->createPropertyCommandsInDesignMode(formWidget, propValues, group, true );
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 }
00151
00152 void KexiFormManager::setDataSourceFieldOrExpression(const QString& string, const QString& caption,
00153 KexiDB::Field::Type type)
00154 {
00155 if (!activeForm())
00156 return;
00157
00158
00159
00160
00161 KFormDesigner::WidgetPropertySet *set = propertySet();
00162 if (!set || !set->contains("dataSource"))
00163 return;
00164
00165 (*set)["dataSource"].setValue(string);
00166
00167 if (set->contains("autoCaption") && (*set)["autoCaption"].value().toBool()) {
00168 if (set->contains("fieldCaptionInternal"))
00169 (*set)["fieldCaptionInternal"].setValue(caption);
00170 }
00171 if (
00172 set->contains("widgetType") && (*set)["widgetType"].value().toString()=="Auto")
00173 {
00174 if (set->contains("fieldTypeInternal"))
00175 (*set)["fieldTypeInternal"].setValue(type);
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185 }
00186
00187 void KexiFormManager::insertAutoFields(const QString& sourceMimeType, const QString& sourceName,
00188 const QStringList& fields)
00189 {
00190 KexiFormView* formViewWidget = activeFormViewWidget();
00191 if (!formViewWidget || !formViewWidget->form() || !formViewWidget->form()->activeContainer())
00192 return;
00193 formViewWidget->insertAutoFields(sourceMimeType, sourceName, fields,
00194 formViewWidget->form()->activeContainer());
00195 }
00196
00197 void KexiFormManager::slotHistoryCommandExecuted()
00198 {
00199 const KFormDesigner::CommandGroup *group = dynamic_cast<const KFormDesigner::CommandGroup*>(sender());
00200 if (group) {
00201 if (group->commands().count()==2) {
00202 KexiDBForm* formWidget = dynamic_cast<KexiDBForm*>(activeForm()->widget());
00203 if (!formWidget)
00204 return;
00205 QPtrListIterator<KCommand> it(group->commands());
00206 const KFormDesigner::PropertyCommand* pc1 = dynamic_cast<const KFormDesigner::PropertyCommand*>(it.current());
00207 ++it;
00208 const KFormDesigner::PropertyCommand* pc2 = dynamic_cast<const KFormDesigner::PropertyCommand*>(it.current());
00209 if (pc1 && pc2 && pc1->property()=="dataSource" && pc2->property()=="dataSourceMimeType") {
00210 const QMap<QCString, QVariant>::const_iterator it1( pc1->oldValues().constBegin() );
00211 const QMap<QCString, QVariant>::const_iterator it2( pc2->oldValues().constBegin() );
00212 if (it1.key()==formWidget->name() && it2.key()==formWidget->name())
00213 static_cast<KexiFormPart*>(m_part)->dataSourcePage()->setDataSource(
00214 formWidget->dataSourceMimeType(), formWidget->dataSource().latin1());
00215 }
00216 }
00217 }
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 #include "kexiformmanager.moc"
|