kexi

kexiformmanager.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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 //moved to KexiFormPart lib()->setAdvancedPropertiesVisible(false);
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 //  if (QString(name)=="layout_menu")
00095 //      kdDebug() << "!!!!!!!!!!! " << enable << endl;
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 //  setPropertyValueInDesignMode(formWidget, "dataSource", name);
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 /*addToActiveForm*/);
00118     }
00119 
00120 /*
00121     if (activeForm()->selectedWidget() == formWidget) {
00122         //active form is selected: just use properties system
00123         KFormDesigner::WidgetPropertySet *set = propertySet();
00124         if (!set || !set->contains("dataSource"))
00125             return;
00126         (*set)["dataSource"].setValue(name);
00127         if (set->contains("dataSourceMimeType"))
00128             (*set)["dataSourceMimeType"].setValue(mime);
00129         return;
00130     }
00131 
00132     //active form isn't selected: change it's data source and mime type by hand
00133     QCString oldDataSourceMimeType( formWidget->dataSourceMimeType() );
00134     QCString oldDataSource( formWidget->dataSource().latin1() );
00135 
00136     if (mime!=oldDataSourceMimeType || name!=oldDataSource) {
00137         formWidget->setDataSourceMimeType(mime);
00138         formWidget->setDataSource(name);
00139         emit dirty(activeForm(), true);
00140 
00141         activeForm()->addCommand( 
00142             new KFormDesigner::PropertyCommand(propertySet(), QString(formWidget->name()),
00143                 oldDataSource, name, "dataSource"), 
00144             false );
00145 
00146         // If the property is changed, we add it in ObjectTreeItem modifProp
00147         KFormDesigner::ObjectTreeItem *fromTreeItem = activeForm()->objectTree()->lookup(formWidget->name());
00148         fromTreeItem->addModifiedProperty("dataSourceMimeType", mime);
00149         fromTreeItem->addModifiedProperty("dataSource", name);
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 //  KexiFormDataItemInterface* dataWidget = dynamic_cast<KexiFormDataItemInterface*>(activeForm()->selectedWidget());
00159 //  if (!dataWidget)
00160 //      return;
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 /*  QString oldDataSource( dataWidget->dataSource() );
00180     if (string!=oldDataSource) {
00181         dataWidget->setDataSource(string);
00182         emit dirty(activeForm(), true);
00183 
00184         buffer
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 bool KexiFormManager::loadFormFromDomInternal(Form *form, QWidget *container, QDomDocument &inBuf)
00222 {
00223     QMap<QCString,QString> customProperties;
00224     FormIO::loadFormFromDom(myform, container, domDoc, &customProperties);
00225 }
00226 
00227 bool KexiFormManager::saveFormToStringInternal(Form *form, QString &dest, int indent)
00228 {
00229     QMap<QCString,QString> customProperties;
00230     return KFormDesigner::FormIO::saveFormToString(form, dest, indent, &customProperties);
00231 }
00232 
00233 */
00234 
00235 #include "kexiformmanager.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys