• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Designer Integration Support Library
 

KDevelop Designer Integration Support Library

  • languages
  • lib
  • designer_integration
qtdesignerintegration.cpp
1 /***************************************************************************
2  * Copyright (C) 2004 by Alexander Dymo *
3  * adymo@kdevelop.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Library General Public License as *
7  * published by the Free Software Foundation; either version 2 of the *
8  * License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Library General Public *
16  * License along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #include "qtdesignerintegration.h"
21 
22 #include <tqpair.h>
23 #include <tqregexp.h>
24 #include <tqfileinfo.h>
25 
26 #include <tdelocale.h>
27 #include <kdebug.h>
28 #include <tdemessagebox.h>
29 #include <kurl.h>
30 
31 #include <rurl.h>
32 #include <domutil.h>
33 #include <kdevpartcontroller.h>
34 #include <kdevcreatefile.h>
35 #include <kdevlanguagesupport.h>
36 #include <kdevproject.h>
37 
38 #include "codemodel_utils.h"
39 #include "implementationwidget.h"
40 
41 QtDesignerIntegration::QtDesignerIntegration(KDevLanguageSupport *part, ImplementationWidget *impl, bool classHasDefinitions, const char* name)
42  :KDevDesignerIntegration(part, name), m_part(part), m_impl(impl),
43  m_classHasDefinitions(classHasDefinitions)
44 {
45 }
46 
47 QtDesignerIntegration::~QtDesignerIntegration()
48 {
49  delete m_impl;
50 }
51 
52 void QtDesignerIntegration::addFunction(const TQString& formName, KInterfaceDesigner::Function function)
53 {
54  kdDebug() << "QtDesignerIntegration::addFunction: form: " << formName << ", function: " << function.function << endl;
55 
56  if (!m_implementations.contains(formName))
57  if (!selectImplementation(formName))
58  return;
59 
60  ClassDom klass = m_implementations[formName];
61  if (!klass)
62  {
63  KMessageBox::error(0, i18n("Cannot find implementation class for form: %1").arg(formName));
64  return;
65  }
66 
67  addFunctionToClass(function, klass);
68 }
69 
70 void QtDesignerIntegration::editFunction(const TQString& formName, KInterfaceDesigner::Function oldFunction, KInterfaceDesigner::Function function)
71 {
72  kdDebug() << "QtDesignerIntegration::editFunction: form: " << formName
73  << ", old function: " << oldFunction.function
74  << ", function: " << function.function << endl;
75 }
76 
77 void QtDesignerIntegration::removeFunction(const TQString& formName, KInterfaceDesigner::Function function)
78 {
79  kdDebug() << "QtDesignerIntegration::removeFunction: form: " << formName << ", function: " << function.function << endl;
80 }
81 
82 bool QtDesignerIntegration::selectImplementation(const TQString &formName)
83 {
84  TQFileInfo fi(formName);
85  if (!fi.exists())
86  return false;
87 
88  if (m_impl->exec(formName))
89  {
90  m_implementations[formName] = m_impl->selectedClass();
91  return true;
92  }
93  return false;
94 }
95 
96 void QtDesignerIntegration::loadSettings(TQDomDocument dom, TQString path)
97 {
98  TQDomElement el = DomUtil::elementByPath(dom, path + "/qtdesigner");
99  if (el.isNull())
100  return;
101  TQDomNodeList impls = el.elementsByTagName("implementation");
102  for (uint i = 0; i < impls.count(); ++i)
103  {
104  TQDomElement el = impls.item(i).toElement();
105  if (el.isNull())
106  continue;
107  TQString implementationPath = Relative::File(m_part->project()->projectDirectory(),
108  el.attribute("implementationpath"), true).urlPath();
109  FileDom file = m_part->codeModel()->fileByName(implementationPath);
110  if (!file)
111  continue;
112  ClassList cllist = file->classByName(el.attribute("class"));
113  TQString uiPath = Relative::File(m_part->project()->projectDirectory(),
114  el.attribute("path"), true).urlPath();
115  if (cllist.count() > 0)
116  m_implementations[uiPath] = cllist.first();
117  }
118 }
119 
120 void QtDesignerIntegration::saveSettings(TQDomDocument dom, TQString path)
121 {
122  kdDebug() << "QtDesignerIntegration::saveSettings" << endl;
123  TQDomElement el = DomUtil::createElementByPath(dom, path + "/qtdesigner");
124  for (TQMap<TQString, ClassDom>::const_iterator it = m_implementations.begin();
125  it != m_implementations.end(); ++it)
126  {
127  TQDomElement il = dom.createElement("implementation");
128  el.appendChild(il);
129  il.setAttribute("path",
130  Relative::File(m_part->project()->projectDirectory(), it.key()).rurl());
131  il.setAttribute("implementationpath",
132  Relative::File(m_part->project()->projectDirectory(), it.data()->fileName()).rurl());
133  il.setAttribute("class", it.data()->name());
134  }
135 }
136 
137 void QtDesignerIntegration::openFunction(const TQString &formName, const TQString &functionName)
138 {
139  kdDebug() << "QtDesignerIntegration::openFunction, formName = " << formName
140  << ", functionName = " << functionName << endl;
141  TQString fn = functionName;
142  if (fn.find("(") > 0)
143  fn.remove(fn.find("("), fn.length());
144 
145  if (!m_implementations[formName])
146  return;
147 
148  int line = -1, col = -1;
149 
150  TQString impl = m_implementations[formName]->fileName();
151  processImplementationName(impl);
152 
153  if (m_part->codeModel()->hasFile(impl))
154  {
155  if (m_classHasDefinitions)
156  {
157  FunctionDefinitionList list =
158  m_part->codeModel()->fileByName(impl)->functionDefinitionList();
159  for (FunctionDefinitionList::const_iterator it = list.begin(); it != list.end(); ++it)
160  {
161  if ((*it)->name() == fn)
162  (*it)->getStartPosition(&line, &col);
163  }
164  }
165  else
166  {
167  FunctionList list =
168  m_part->codeModel()->fileByName(impl)->functionList();
169  for (FunctionList::const_iterator it = list.begin(); it != list.end(); ++it)
170  {
171  if ((*it)->name() == fn)
172  (*it)->getStartPosition(&line, &col);
173  }
174  }
175  }
176 
177  m_part->partController()->editDocument(KURL(impl), line, col);
178 }
179 
180 void QtDesignerIntegration::processImplementationName(TQString &// name
181  )
182 {
183 }
184 
185 void QtDesignerIntegration::openSource(const TQString &formName)
186 {
187  if (!m_implementations.contains(formName))
188  if (!selectImplementation(formName))
189  return;
190  TQString impl = m_implementations[formName]->fileName();
191  processImplementationName(impl);
192  m_part->partController()->editDocument(KURL(impl), -1, -1);
193 }
194 
195 #include "qtdesignerintegration.moc"
ImplementationWidget
Base class for implementation creation widgets.
Definition: implementationwidget.h:40
QtDesignerIntegration::processImplementationName
virtual void processImplementationName(TQString &name)
Modifies name to be a name of a implementation file for languages that have separate files for interf...
Definition: qtdesignerintegration.cpp:180

KDevelop Designer Integration Support Library

Skip menu "KDevelop Designer Integration Support Library"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDevelop Designer Integration Support Library

Skip menu "KDevelop Designer Integration Support Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Designer Integration Support Library by doxygen 1.8.13
This website is maintained by Timothy Pearson.