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
00047
00048 KexiCustomPropertyFactory::init();
00049 }
00050
00051 KexiFormManager::~KexiFormManager()
00052 {
00053 }
00054
00055 KAction* KexiFormManager::action( const char* name )
00056 {
00057 KActionCollection *col = m_part->actionCollectionForMode(Kexi::DesignViewMode);
00058 if (!col)
00059 return 0;
00060 QCString n( translateName( name ).latin1() );
00061 KAction *a = col->action(n);
00062 if (a)
00063 return a;
00064 KexiDBForm *dbform;
00065 if (!activeForm() || !activeForm()->designMode()
00066 || !(dbform = dynamic_cast<KexiDBForm*>(activeForm()->formWidget())))
00067 return 0;
00068 KexiFormScrollView *scrollViewWidget = dynamic_cast<KexiFormScrollView*>(dbform->dataAwareObject());
00069 if (!scrollViewWidget)
00070 return 0;
00071 KexiFormView* formViewWidget = dynamic_cast<KexiFormView*>(scrollViewWidget->parent());
00072 if (!formViewWidget)
00073 return 0;
00074 return formViewWidget->parentDialog()->mainWin()->actionCollection()->action(n);
00075 }
00076
00077 KexiFormView* KexiFormManager::activeFormViewWidget() const
00078 {
00079 KexiDBForm *dbform;
00080 if (!activeForm() || !activeForm()->designMode()
00081 || !(dbform = dynamic_cast<KexiDBForm*>(activeForm()->formWidget())))
00082 return 0;
00083 KexiFormScrollView *scrollViewWidget = dynamic_cast<KexiFormScrollView*>(dbform->dataAwareObject());
00084 if (!scrollViewWidget)
00085 return 0;
00086 return dynamic_cast<KexiFormView*>(scrollViewWidget->parent());
00087 }
00088
00089 void KexiFormManager::enableAction( const char* name, bool enable )
00090 {
00091 KexiFormView* formViewWidget = activeFormViewWidget();
00092 if (!formViewWidget)
00093 return;
00094
00095
00096 formViewWidget->setAvailable(translateName( name ).latin1(), enable);
00097 }
00098
00099 void KexiFormManager::setFormDataSource(const QCString& mime, const QCString& name)
00100 {
00101 if (!activeForm())
00102 return;
00103 KexiDBForm* formWidget = dynamic_cast<KexiDBForm*>(activeForm()->widget());
00104 if (!formWidget)
00105 return;
00106
00107
00108
00109 QCString oldDataSourceMimeType( formWidget->dataSourceMimeType() );
00110 QCString oldDataSource( formWidget->dataSource().latin1() );
00111 if (mime!=oldDataSourceMimeType || name!=oldDataSource) {
00112 QMap<QCString, QVariant> propValues;
00113 propValues.insert("dataSource", name);
00114 propValues.insert("dataSourceMimeType", mime);
00115 KFormDesigner::CommandGroup *group
00116 = new KFormDesigner::CommandGroup(i18n("Set Form's Data Source to \"%1\"").arg(name), propertySet());
00117 propertySet()->createPropertyCommandsInDesignMode(formWidget, propValues, group, true );
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
00153 void KexiFormManager::setDataSourceFieldOrExpression(const QString& string, const QString& caption,
00154 KexiDB::Field::Type type)
00155 {
00156 if (!activeForm())
00157 return;
00158
00159
00160
00161
00162 KFormDesigner::WidgetPropertySet *set = propertySet();
00163 if (!set || !set->contains("dataSource"))
00164 return;
00165
00166 (*set)["dataSource"].setValue(string);
00167
00168 if (set->contains("autoCaption") && (*set)["autoCaption"].value().toBool()) {
00169 if (set->contains("fieldCaptionInternal"))
00170 (*set)["fieldCaptionInternal"].setValue(caption);
00171 }
00172 if (type!=KexiDB::Field::InvalidType
00173 && set->contains("widgetType") && (*set)["widgetType"].value().toString()=="Auto")
00174 {
00175 if (set->contains("fieldTypeInternal"))
00176 (*set)["fieldTypeInternal"].setValue(type);
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186 }
00187
00188 void KexiFormManager::insertAutoFields(const QString& sourceMimeType, const QString& sourceName,
00189 const QStringList& fields)
00190 {
00191 KexiFormView* formViewWidget = activeFormViewWidget();
00192 if (!formViewWidget)
00193 return;
00194 formViewWidget->insertAutoFields(sourceMimeType, sourceName, fields);
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"
|