1
/* This file is part of the KDE project
2
Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
3
Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library 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 GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
21
#ifndef KFORMDESIGNEROBJECTTREE_H
22
#define KFORMDESIGNEROBJECTTREE_H
29
#include <qguardedptr.h>
34
namespace KFormDesigner {
39
typedef QPtrList<ObjectTreeItem> ObjectTreeList;
40
typedef QPtrListIterator<ObjectTreeItem> ObjectTreeListIterator;
41
typedef QDict<ObjectTreeItem> ObjectTreeDict;
42
typedef QDictIterator<ObjectTreeItem> ObjectTreeDictIterator;
43
typedef QMap<QString, QVariant> QVariantMap;
45
/*! This class holds the properties of a widget (classname, name, parent, children ..).
46
\author Lucijan Busch <lucijan@kde.org>
48
//! An item representing a widget
49
class KFORMEDITOR_EXPORT ObjectTreeItem
53
ObjectTreeItem(const QString &className, const QString &name, QWidget *widget, Container *parentContainer, Container *container=0);
54
virtual ~ObjectTreeItem();
56
QString name() const { return m_name; }
57
QString className() const { return m_className; }
58
QWidget* widget() const { return m_widget; }
59
EventEater* eventEater() const { return m_eater; }
60
ObjectTreeItem* parent() const { return m_parent; }
61
ObjectTreeList* children() { return &m_children; }
62
/*! \return a QMap<QString, QVariant> of all modified properties for this widget.
63
The QVariant is the old value (ie first value) of the property whose name is the QString. */
64
const QVariantMap* modifiedProperties() { return &m_props;}
65
//! \return the widget's Container, or 0if the widget is not a Container.
66
Container* container() const { return m_container;}
68
void setWidget(QWidget *w) { m_widget = w; }
69
void setParent(ObjectTreeItem *parent) { m_parent = parent;}
71
void debug(int ident);
72
void rename(const QString &name);
74
void addChild(ObjectTreeItem *it);
75
void removeChild(ObjectTreeItem *it);
77
/*! Adds \a property in the list of the modified properties for this object.
78
These modified properties are written in the .ui files when saving the form.
80
void addModifiedProperty(const QCString &property, const QVariant &value);
81
void storeUnknownProperty(QDomElement &el);
83
void addPixmapName(const QCString &property, const QString &name);
84
QString pixmapName(const QCString &property);
86
void setEnabled(bool enabled) { m_enabled = enabled; }
87
bool isEnabled() const { return m_enabled; }
89
int gridRow() const { return m_row; }
90
int gridCol() const { return m_col; }
91
int gridRowSpan() const { return m_rowspan; }
92
int gridColSpan() const { return m_colspan; }
93
bool spanMultipleCells() const { return m_span; }
94
void setGridPos(int row, int col, int rowspan, int colspan);
99
ObjectTreeList m_children;
100
QGuardedPtr<Container> m_container;
101
QMap<QString, QVariant> m_props;
102
QString m_unknownProps;
103
QMap<QCString, QString> m_pixmapNames;
104
ObjectTreeItem* m_parent;
105
QGuardedPtr<QWidget> m_widget;
106
QGuardedPtr<EventEater> m_eater;
110
int m_row, m_col, m_rowspan, m_colspan;
113
friend class ObjectTree;
117
//! A class representing all the objects in a Form
118
/*! This class holds ObjectTreeItem for each widget in a Form.
120
class KFORMEDITOR_EXPORT ObjectTree : public ObjectTreeItem
123
ObjectTree(const QString &className=QString::null, const QString &name=QString::null,
124
QWidget *widget=0, Container *container=0);
125
virtual ~ObjectTree();
127
/*! Renames the item named \a oldname to \a newname. \return false if widget named \a newname
128
already exists and renaming failed. */
129
bool rename(const QString &oldname, const QString &newname );
130
/*! Sets \a newparent as new parent for the item whose name is \a name. */
131
bool reparent(const QString &name, const QString &newparent);
133
/*! \return the ObjectTreeItem named \a name, or 0 if doesn't exist. */
134
ObjectTreeItem* lookup(const QString &name);
135
/*! \return a dict containing all ObjectTreeItem in this ObjectTree. If you want to iterate on
136
this dict, iterate on a copy. */
137
ObjectTreeDict* dict() { return &m_treeDict; }
139
void addItem(ObjectTreeItem *parent, ObjectTreeItem *c);
140
void removeItem(const QString &name);
141
void removeItem(ObjectTreeItem *c);
143
/*! Generates a new name with \a base as beginning (eg if base is "QLineEdit", it returns "QLineEdit1"). */
144
QString genName(const QString &base);
147
ObjectTreeDict m_treeDict;