• 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
implementationwidget.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 "implementationwidget.h"
21
22#include <tqfileinfo.h>
23#include <tqtextstream.h>
24#include <tqfile.h>
25#include <tqdir.h>
26#include <tqregexp.h>
27#include <tqdom.h>
28#include <tqradiobutton.h>
29
30#include <klineedit.h>
31#include <tdelocale.h>
32#include <tdemessagebox.h>
33#include <tdelistview.h>
34
35#include <kdevproject.h>
36#include <domutil.h>
37#include <filetemplate.h>
38#include <kdevlanguagesupport.h>
39
40namespace ImplUtils{
41class ClassItem: public TDEListViewItem{
42public:
43 ClassItem(TDEListViewItem *parent, ClassDom dom)
44 :TDEListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); }
45 ClassItem(TDEListView *parent, ClassDom dom)
46 :TDEListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); }
47 ClassDom dom() const { return m_dom; }
48private:
49 ClassDom m_dom;
50};
51
52class NamespaceItem: public TDEListViewItem{
53public:
54 NamespaceItem(TDEListViewItem *parent, NamespaceDom dom)
55 :TDEListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); }
56 NamespaceItem(TDEListView *parent, NamespaceDom dom)
57 :TDEListViewItem(parent, dom->name(), dom->fileName()), m_dom(dom) { setOpen(true); }
58 NamespaceDom dom() const { return m_dom; }
59private:
60 NamespaceDom m_dom;
61};
62}
63
64ImplementationWidget::ImplementationWidget(KDevLanguageSupport *part, TQWidget* parent, const char* name, bool modal)
65 :CreateImplemenationWidgetBase(parent, name, modal), m_part(part)
66{
67}
68
69void ImplementationWidget::init(const TQString &formName)
70{
71 m_formName = formName;
72
73 classView->clear();
74 fileNameEdit->clear();
75 classNameEdit->clear();
76
77 TQDomDocument doc;
78 DomUtil::openDOMFile(doc, m_formName);
79 m_baseClassName = DomUtil::elementByPathExt(doc, "class").text();
80 setCaption(i18n("Create or Select Implementation Class for: %1").arg(m_baseClassName));
81
82 TDEListViewItem *item = new TDEListViewItem(classView, i18n("Namespaces &amp;&amp; Classes"));
83 item->setOpen(true);
84 processNamespaces(m_part->codeModel()->globalNamespace(), item);
85}
86
87void ImplementationWidget::processNamespaces(NamespaceDom dom, TDEListViewItem *parent)
88{
89 const NamespaceList nslist = dom->namespaceList();
90 for (NamespaceList::const_iterator it = nslist.begin(); it != nslist.end(); ++it)
91 processNamespaces(*it, new ImplUtils::NamespaceItem(parent, *it));
92 const ClassList cllist = dom->classList();
93 for (ClassList::ConstIterator it = cllist.begin(); it != cllist.end(); ++it)
94 processClasses(*it, new ImplUtils::ClassItem(parent, *it));
95}
96
97void ImplementationWidget::processClasses(ClassDom dom, TDEListViewItem *parent)
98{
99 const ClassList cllist = dom->classList();
100 for (ClassList::ConstIterator it = cllist.begin(); it != cllist.end(); ++it)
101 processClasses(*it, new ImplUtils::ClassItem(parent, *it));
102}
103
104ImplementationWidget::~ImplementationWidget()
105{
106}
107
108/*$SPECIALIZATION$*/
109void ImplementationWidget::classNameChanged(const TQString &text)
110{
111 fileNameEdit->setText(text.lower());
112}
113
114void ImplementationWidget::accept()
115{
116 if (createButton->isOn())
117 {
118 if (classNameEdit->text().isEmpty())
119 return;
120 if (!createClass())
121 return;
122 ClassList cllist = m_part->codeModel()->globalNamespace()->classByName(classNameEdit->text());
123 if (cllist.count() > 0)
124 m_selectedClass = cllist.first();
125 else
126 KMessageBox::error(0, i18n("Class was created but not found in class store."));
127 }
128 else if (useButton->isOn())
129 {
130 if (!classView->currentItem())
131 return;
132 ImplUtils::ClassItem *item = dynamic_cast<ImplUtils::ClassItem*>(classView->currentItem());
133 if (!item)
134 return;
135 m_selectedClass = item->dom();
136 }
137 TQDialog::accept();
138}
139
140ClassDom ImplementationWidget::selectedClass()
141{
142 return m_selectedClass;
143}
144
145bool ImplementationWidget::createClass()
146{
147 m_part->project()->addFiles(createClassFiles());
148 return true;
149}
150
151int ImplementationWidget::exec(const TQString &formName)
152{
153 init(formName);
154 return TQDialog::exec();
155}
156
157#include "implementationwidget.moc"
158
ImplementationWidget::exec
int exec(const TQString &formName)
Executes implementation widget for a form formName.
Definition implementationwidget.cpp:151
ImplementationWidget::createClassFiles
virtual TQStringList createClassFiles()=0
Reimplement to create actual files with the form implementation.
ImplementationWidget::selectedClass
ClassDom selectedClass()
Definition implementationwidget.cpp:140
ImplementationWidget::init
void init(const TQString &formName)
Sets up the dialog.
Definition implementationwidget.cpp:69
ImplementationWidget::createClass
bool createClass()
Creates a class and adds it to a project.
Definition implementationwidget.cpp:145

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.9.8
This website is maintained by Timothy Pearson.