diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /languages/lib/designer_integration | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'languages/lib/designer_integration')
7 files changed, 850 insertions, 0 deletions
diff --git a/languages/lib/designer_integration/Mainpage.dox b/languages/lib/designer_integration/Mainpage.dox new file mode 100644 index 00000000..1f2db949 --- /dev/null +++ b/languages/lib/designer_integration/Mainpage.dox @@ -0,0 +1,48 @@ +/** +@mainpage The KDevelop Designer Integration Support Library + +This library contains base classes to implement GUI designer integration in language support plugins. + +<b>Link with</b>: -ldesignerintegration + +<b>Include path</b>: -I\$(kde_includes)/languages/designer_integration + +\section usingintegration Using designer integration support library +Each language support which wants to use integrated designer, must reimplement +@code +virtual KDevDesignerIntegration *KDevLanguageSupport::designer(KInterfaceDesigner::DesignerType type) +@endcode +method and return designer integration object (@ref KDevLanguageSupport base class returns 0). + +Qt designer integration can be easily implemented by reusing @ref QtDesignerIntegration +base class. + +For example, designer method of a language support could look like: +@code +KDevDesignerIntegration * MyLanguageSupportPart::designer(KInterfaceDesigner::DesignerType type) +{ + KDevDesignerIntegration *des = 0; + switch (type) + { + case KInterfaceDesigner::QtDesigner: + des = m_designers[type]; + if (des == 0) + { + MyLanguageImplementationWidget *impl = new MyLanguageImplementationWidget(this); + des = new MyLanguageQtDesignerIntegration(this, impl); + m_designers[type] = des; + } + break; + } + return des; +} +return des; +@endcode +In the code above m_designers is a designer cache declared as: +@code +QMap<KInterfaceDesigner::DesignerType, KDevDesignerIntegration*> m_designers; +@endcode +MyLanguageImplementationWidget and MyLanguageQtDesignerIntegration classes are subclasses +of @ref QtDesignerIntegration and @ref ImplementationWidget base classes. +*/ + diff --git a/languages/lib/designer_integration/Makefile.am b/languages/lib/designer_integration/Makefile.am new file mode 100644 index 00000000..cab66420 --- /dev/null +++ b/languages/lib/designer_integration/Makefile.am @@ -0,0 +1,16 @@ +INCLUDES = -I$(top_srcdir)/lib/interfaces \ + -I$(top_srcdir)/lib/interfaces/extensions -I$(top_srcdir)/lib/interfaces/external -I$(top_srcdir)/lib/util \ + $(all_includes) +METASOURCES = AUTO +libdesignerintegration_la_LDFLAGS = $(all_libraries) +lib_LTLIBRARIES = libdesignerintegration.la +libdesignerintegration_la_LIBADD = $(top_builddir)/lib/interfaces/libkdevinterfaces.la $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) +libdesignerintegration_la_SOURCES = implementationwidgetbase.ui \ + implementationwidget.cpp qtdesignerintegration.cpp + +langincludedirdir = $(includedir)/kdevelop/languages/designer_integration +langincludedir_HEADERS = qtdesignerintegration.h implementationwidget.h implementationwidgetbase.h + +DOXYGEN_REFERENCES = dcop interfaces kdecore kdefx kdeui khtml kmdi kio kjs kparts kutils kdevinterfaces kdevutil +DOXYGEN_PROJECTNAME = KDevelop Designer Integration Support Library +include ../../../Doxyfile.am diff --git a/languages/lib/designer_integration/implementationwidget.cpp b/languages/lib/designer_integration/implementationwidget.cpp new file mode 100644 index 00000000..7c561e7c --- /dev/null +++ b/languages/lib/designer_integration/implementationwidget.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + * Copyright (C) 2004 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "implementationwidget.h" + +#include <qfileinfo.h> +#include <qtextstream.h> +#include <qfile.h> +#include <qdir.h> +#include <qregexp.h> +#include <qdom.h> +#include <qradiobutton.h> + +#include <klineedit.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <klistview.h> + +#include <kdevproject.h> +#include <domutil.h> +#include <filetemplate.h> +#include <kdevlanguagesupport.h> + +namespace ImplUtils{ +class ClassItem: public KListViewItem{ +public: + ClassItem(KListViewItem *parent, ClassDom dom) + :KListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); } + ClassItem(KListView *parent, ClassDom dom) + :KListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); } + ClassDom dom() const { return m_dom; } +private: + ClassDom m_dom; +}; + +class NamespaceItem: public KListViewItem{ +public: + NamespaceItem(KListViewItem *parent, NamespaceDom dom) + :KListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); } + NamespaceItem(KListView *parent, NamespaceDom dom) + :KListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); } + NamespaceDom dom() const { return m_dom; } +private: + NamespaceDom m_dom; +}; +} + +ImplementationWidget::ImplementationWidget(KDevLanguageSupport *part, QWidget* parent, const char* name, bool modal) + :CreateImplemenationWidgetBase(parent, name, modal), m_part(part) +{ +} + +void ImplementationWidget::init(const QString &formName) +{ + m_formName = formName; + + classView->clear(); + fileNameEdit->clear(); + classNameEdit->clear(); + + QDomDocument doc; + DomUtil::openDOMFile(doc, m_formName); + m_baseClassName = DomUtil::elementByPathExt(doc, "class").text(); + setCaption(i18n("Create or Select Implementation Class for: %1").arg(m_baseClassName)); + + KListViewItem *item = new KListViewItem(classView, i18n("Namespaces && Classes")); + item->setOpen(true); + processNamespaces(m_part->codeModel()->globalNamespace(), item); +} + +void ImplementationWidget::processNamespaces(NamespaceDom dom, KListViewItem *parent) +{ + const NamespaceList nslist = dom->namespaceList(); + for (NamespaceList::const_iterator it = nslist.begin(); it != nslist.end(); ++it) + processNamespaces(*it, new ImplUtils::NamespaceItem(parent, *it)); + const ClassList cllist = dom->classList(); + for (ClassList::ConstIterator it = cllist.begin(); it != cllist.end(); ++it) + processClasses(*it, new ImplUtils::ClassItem(parent, *it)); +} + +void ImplementationWidget::processClasses(ClassDom dom, KListViewItem *parent) +{ + const ClassList cllist = dom->classList(); + for (ClassList::ConstIterator it = cllist.begin(); it != cllist.end(); ++it) + processClasses(*it, new ImplUtils::ClassItem(parent, *it)); +} + +ImplementationWidget::~ImplementationWidget() +{ +} + +/*$SPECIALIZATION$*/ +void ImplementationWidget::classNameChanged(const QString &text) +{ + fileNameEdit->setText(text.lower()); +} + +void ImplementationWidget::accept() +{ + if (createButton->isOn()) + { + if (classNameEdit->text().isEmpty()) + return; + if (!createClass()) + return; + ClassList cllist = m_part->codeModel()->globalNamespace()->classByName(classNameEdit->text()); + if (cllist.count() > 0) + m_selectedClass = cllist.first(); + else + KMessageBox::error(0, i18n("Class was created but not found in class store.")); + } + else if (useButton->isOn()) + { + if (!classView->currentItem()) + return; + ImplUtils::ClassItem *item = dynamic_cast<ImplUtils::ClassItem*>(classView->currentItem()); + if (!item) + return; + m_selectedClass = item->dom(); + } + QDialog::accept(); +} + +ClassDom ImplementationWidget::selectedClass() +{ + return m_selectedClass; +} + +bool ImplementationWidget::createClass() +{ + m_part->project()->addFiles(createClassFiles()); + return true; +} + +int ImplementationWidget::exec(const QString &formName) +{ + init(formName); + return QDialog::exec(); +} + +#include "implementationwidget.moc" + diff --git a/languages/lib/designer_integration/implementationwidget.h b/languages/lib/designer_integration/implementationwidget.h new file mode 100644 index 00000000..3200c877 --- /dev/null +++ b/languages/lib/designer_integration/implementationwidget.h @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (C) 2004 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef IMPLEMENTATIONWIDGET_H +#define IMPLEMENTATIONWIDGET_H + +#include "implementationwidgetbase.h" + +#include <codemodel.h> + +class KListViewItem; +class KDevLanguageSupport; + +/** +Base class for implementation creation widgets. +Contains language-independent implementation widget that can be used +to create or select an implementation of a form in designer. + +Implementations could be subclasses or simple files with callbacks, etc. + +Subclasses of this class should reimplement only pure virtual functions in the common case. +*/ +class ImplementationWidget : public CreateImplemenationWidgetBase +{ +Q_OBJECT +public: + ImplementationWidget(KDevLanguageSupport *part, QWidget* parent = 0, const char* name = 0, bool modal = false); + virtual ~ImplementationWidget(); + /*$PUBLIC_FUNCTIONS$*/ + + /**@returns The %DOM of selected (or created) class.*/ + ClassDom selectedClass(); + + /**Executes implementation widget for a form @p formName.*/ + int exec(const QString &formName); + +public slots: + /*$PUBLIC_SLOTS$*/ + +protected: + /*$PROTECTED_FUNCTIONS$*/ + /**Sets up the dialog. No need to reimplement unless you want to restrict + the number of classes being displayed as possible implementation classes.*/ + void init(const QString &formName); + + void processNamespaces(NamespaceDom dom, KListViewItem *parent); + void processClasses(ClassDom dom, KListViewItem *parent); + + /**Creates a class and adds it to a project. No need to reimplement.*/ + bool createClass(); + + /**Reimplement to create actual files with the form implementation. + @return The list of absolute paths to a files created.*/ + virtual QStringList createClassFiles() = 0; + +protected slots: + /*$PROTECTED_SLOTS$*/ + virtual void classNameChanged(const QString &text); + virtual void accept(); + +protected: + KDevLanguageSupport *m_part; + ClassDom m_selectedClass; + QString m_formName; + QString m_baseClassName; +}; + +#endif + diff --git a/languages/lib/designer_integration/implementationwidgetbase.ui b/languages/lib/designer_integration/implementationwidgetbase.ui new file mode 100644 index 00000000..1a39d39e --- /dev/null +++ b/languages/lib/designer_integration/implementationwidgetbase.ui @@ -0,0 +1,267 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>CreateImplemenationWidgetBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>CreateImplemenationWidgetBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>518</width> + <height>353</height> + </rect> + </property> + <property name="caption"> + <string>Create or Select Implementation Class</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>okButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>cancelButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QButtonGroup" row="0" column="0"> + <property name="name"> + <cstring>buttonGroup1</cstring> + </property> + <property name="title"> + <string></string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton" row="0" column="0"> + <property name="name"> + <cstring>createButton</cstring> + </property> + <property name="text"> + <string>Create &new class</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="KListView" row="4" column="0"> + <column> + <property name="text"> + <string>Class Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>File</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>classView</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>classNameLabel</cstring> + </property> + <property name="text"> + <string>C&lass name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>classNameEdit</cstring> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>classNameEdit</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="QRadioButton" row="3" column="0"> + <property name="name"> + <cstring>useButton</cstring> + </property> + <property name="text"> + <string>Use &existing class</string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>layout2_2</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>fileNameLabel</cstring> + </property> + <property name="text"> + <string>&File name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>fileNameEdit</cstring> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>fileNameEdit</cstring> + </property> + </widget> + </vbox> + </widget> + </grid> + </widget> + </grid> +</widget> +<customwidgets> +</customwidgets> +<connections> + <connection> + <sender>cancelButton</sender> + <signal>clicked()</signal> + <receiver>CreateImplemenationWidgetBase</receiver> + <slot>reject()</slot> + </connection> + <connection> + <sender>okButton</sender> + <signal>clicked()</signal> + <receiver>CreateImplemenationWidgetBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>createButton</sender> + <signal>toggled(bool)</signal> + <receiver>classNameLabel</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>createButton</sender> + <signal>toggled(bool)</signal> + <receiver>classNameEdit</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>useButton</sender> + <signal>toggled(bool)</signal> + <receiver>classView</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>createButton</sender> + <signal>toggled(bool)</signal> + <receiver>fileNameLabel</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>createButton</sender> + <signal>toggled(bool)</signal> + <receiver>fileNameEdit</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>classNameEdit</sender> + <signal>textChanged(const QString&)</signal> + <receiver>CreateImplemenationWidgetBase</receiver> + <slot>classNameChanged(const QString&)</slot> + </connection> +</connections> +<tabstops> + <tabstop>createButton</tabstop> + <tabstop>classNameEdit</tabstop> + <tabstop>fileNameEdit</tabstop> + <tabstop>classView</tabstop> + <tabstop>okButton</tabstop> + <tabstop>cancelButton</tabstop> +</tabstops> +<slots> + <slot access="protected">classNameChanged(const QString &)</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>klistview.h</includehint> +</includehints> +</UI> diff --git a/languages/lib/designer_integration/qtdesignerintegration.cpp b/languages/lib/designer_integration/qtdesignerintegration.cpp new file mode 100644 index 00000000..32dc16ca --- /dev/null +++ b/languages/lib/designer_integration/qtdesignerintegration.cpp @@ -0,0 +1,195 @@ +/*************************************************************************** + * Copyright (C) 2004 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "qtdesignerintegration.h" + +#include <qpair.h> +#include <qregexp.h> +#include <qfileinfo.h> + +#include <klocale.h> +#include <kdebug.h> +#include <kmessagebox.h> +#include <kurl.h> + +#include <rurl.h> +#include <domutil.h> +#include <kdevpartcontroller.h> +#include <kdevcreatefile.h> +#include <kdevlanguagesupport.h> +#include <kdevproject.h> + +#include "codemodel_utils.h" +#include "implementationwidget.h" + +QtDesignerIntegration::QtDesignerIntegration(KDevLanguageSupport *part, ImplementationWidget *impl, bool classHasDefinitions, const char* name) + :KDevDesignerIntegration(part, name), m_part(part), m_impl(impl), + m_classHasDefinitions(classHasDefinitions) +{ +} + +QtDesignerIntegration::~QtDesignerIntegration() +{ + delete m_impl; +} + +void QtDesignerIntegration::addFunction(const QString& formName, KInterfaceDesigner::Function function) +{ + kdDebug() << "QtDesignerIntegration::addFunction: form: " << formName << ", function: " << function.function << endl; + + if (!m_implementations.contains(formName)) + if (!selectImplementation(formName)) + return; + + ClassDom klass = m_implementations[formName]; + if (!klass) + { + KMessageBox::error(0, i18n("Cannot find implementation class for form: %1").arg(formName)); + return; + } + + addFunctionToClass(function, klass); +} + +void QtDesignerIntegration::editFunction(const QString& formName, KInterfaceDesigner::Function oldFunction, KInterfaceDesigner::Function function) +{ + kdDebug() << "QtDesignerIntegration::editFunction: form: " << formName + << ", old function: " << oldFunction.function + << ", function: " << function.function << endl; +} + +void QtDesignerIntegration::removeFunction(const QString& formName, KInterfaceDesigner::Function function) +{ + kdDebug() << "QtDesignerIntegration::removeFunction: form: " << formName << ", function: " << function.function << endl; +} + +bool QtDesignerIntegration::selectImplementation(const QString &formName) +{ + QFileInfo fi(formName); + if (!fi.exists()) + return false; + + if (m_impl->exec(formName)) + { + m_implementations[formName] = m_impl->selectedClass(); + return true; + } + return false; +} + +void QtDesignerIntegration::loadSettings(QDomDocument dom, QString path) +{ + QDomElement el = DomUtil::elementByPath(dom, path + "/qtdesigner"); + if (el.isNull()) + return; + QDomNodeList impls = el.elementsByTagName("implementation"); + for (uint i = 0; i < impls.count(); ++i) + { + QDomElement el = impls.item(i).toElement(); + if (el.isNull()) + continue; + QString implementationPath = Relative::File(m_part->project()->projectDirectory(), + el.attribute("implementationpath"), true).urlPath(); + FileDom file = m_part->codeModel()->fileByName(implementationPath); + if (!file) + continue; + ClassList cllist = file->classByName(el.attribute("class")); + QString uiPath = Relative::File(m_part->project()->projectDirectory(), + el.attribute("path"), true).urlPath(); + if (cllist.count() > 0) + m_implementations[uiPath] = cllist.first(); + } +} + +void QtDesignerIntegration::saveSettings(QDomDocument dom, QString path) +{ + kdDebug() << "QtDesignerIntegration::saveSettings" << endl; + QDomElement el = DomUtil::createElementByPath(dom, path + "/qtdesigner"); + for (QMap<QString, ClassDom>::const_iterator it = m_implementations.begin(); + it != m_implementations.end(); ++it) + { + QDomElement il = dom.createElement("implementation"); + el.appendChild(il); + il.setAttribute("path", + Relative::File(m_part->project()->projectDirectory(), it.key()).rurl()); + il.setAttribute("implementationpath", + Relative::File(m_part->project()->projectDirectory(), it.data()->fileName()).rurl()); + il.setAttribute("class", it.data()->name()); + } +} + +void QtDesignerIntegration::openFunction(const QString &formName, const QString &functionName) +{ + kdDebug() << "QtDesignerIntegration::openFunction, formName = " << formName + << ", functionName = " << functionName << endl; + QString fn = functionName; + if (fn.find("(") > 0) + fn.remove(fn.find("("), fn.length()); + + if (!m_implementations[formName]) + return; + + int line = -1, col = -1; + + QString impl = m_implementations[formName]->fileName(); + processImplementationName(impl); + + if (m_part->codeModel()->hasFile(impl)) + { + if (m_classHasDefinitions) + { + FunctionDefinitionList list = + m_part->codeModel()->fileByName(impl)->functionDefinitionList(); + for (FunctionDefinitionList::const_iterator it = list.begin(); it != list.end(); ++it) + { + if ((*it)->name() == fn) + (*it)->getStartPosition(&line, &col); + } + } + else + { + FunctionList list = + m_part->codeModel()->fileByName(impl)->functionList(); + for (FunctionList::const_iterator it = list.begin(); it != list.end(); ++it) + { + if ((*it)->name() == fn) + (*it)->getStartPosition(&line, &col); + } + } + } + + m_part->partController()->editDocument(KURL(impl), line, col); +} + +void QtDesignerIntegration::processImplementationName(QString &// name + ) +{ +} + +void QtDesignerIntegration::openSource(const QString &formName) +{ + if (!m_implementations.contains(formName)) + if (!selectImplementation(formName)) + return; + QString impl = m_implementations[formName]->fileName(); + processImplementationName(impl); + m_part->partController()->editDocument(KURL(impl), -1, -1); +} + +#include "qtdesignerintegration.moc" diff --git a/languages/lib/designer_integration/qtdesignerintegration.h b/languages/lib/designer_integration/qtdesignerintegration.h new file mode 100644 index 00000000..fd8b512f --- /dev/null +++ b/languages/lib/designer_integration/qtdesignerintegration.h @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (C) 2004 by Alexander Dymo * + * adymo@kdevelop.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef QTDESIGNERINTEGRATION_H +#define QTDESIGNERINTEGRATION_H + +#include <qmap.h> + +#include <codemodel.h> +#include "kdevdesignerintegration.h" + +class KDevLanguageSupport; +class ImplementationWidget; + +/** +Qt Designer integration base class. +Contains language-independent implementation part of a @ref KDevDesignerIntegration interface. +Ready to use in KDevelop language support plugins. + +Subclasses of this class should reimplement only pure virtual functions in the common case. +*/ +class QtDesignerIntegration : public KDevDesignerIntegration +{ +Q_OBJECT +public: + QtDesignerIntegration(KDevLanguageSupport *part, ImplementationWidget *impl, + bool classHasDefinitions, const char* name = 0); + virtual ~QtDesignerIntegration(); + +public slots: + virtual void addFunction(const QString& formName, KInterfaceDesigner::Function function); + virtual void editFunction(const QString& formName, KInterfaceDesigner::Function oldFunction, KInterfaceDesigner::Function function); + virtual void removeFunction(const QString& formName, KInterfaceDesigner::Function function); + + virtual void openFunction(const QString &formName, const QString &functionName); + + virtual void openSource(const QString &formName); + + virtual void saveSettings(QDomDocument dom, QString path); + virtual void loadSettings(QDomDocument dom, QString path); + + bool selectImplementation(const QString &formName); + +protected: + /**Reimplement this to add a function to a class. This means you need to modify + the source file and add actual code of a function.*/ + virtual void addFunctionToClass(KInterfaceDesigner::Function function, ClassDom klass) = 0; + /**Modifies name to be a name of a implementation file for languages that have + separate files for interface and implementation parts of a class. For example, + C++ language support plugin will do: + @code + name.replace(".h", ".cpp"); + @endcode*/ + virtual void processImplementationName(QString &name); + + //Form file - derived class name + QMap<QString, ClassDom> m_implementations; + + KDevLanguageSupport *m_part; + ImplementationWidget *m_impl; + bool m_classHasDefinitions; +}; + +#endif |