| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "abstractwidgetdatabase.h"
|
|---|
| 43 | #include <QtCore/qdebug.h>
|
|---|
| 44 | #include <qalgorithms.h>
|
|---|
| 45 |
|
|---|
| 46 | QT_BEGIN_NAMESPACE
|
|---|
| 47 |
|
|---|
| 48 | namespace {
|
|---|
| 49 | enum { debugWidgetDataBase = 0 };
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | /*!
|
|---|
| 53 | \class QDesignerWidgetDataBaseInterface
|
|---|
| 54 | \brief The QDesignerWidgetDataBaseInterface class provides an interface that is used to
|
|---|
| 55 | access and modify Qt Designer's widget database.
|
|---|
| 56 | \inmodule QtDesigner
|
|---|
| 57 | \internal
|
|---|
| 58 | */
|
|---|
| 59 |
|
|---|
| 60 | /*!
|
|---|
| 61 | Constructs an interface to the widget database with the given \a parent.
|
|---|
| 62 | */
|
|---|
| 63 | QDesignerWidgetDataBaseInterface::QDesignerWidgetDataBaseInterface(QObject *parent)
|
|---|
| 64 | : QObject(parent)
|
|---|
| 65 | {
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | /*!
|
|---|
| 69 | Destroys the interface to the widget database.
|
|---|
| 70 | */
|
|---|
| 71 | QDesignerWidgetDataBaseInterface::~QDesignerWidgetDataBaseInterface()
|
|---|
| 72 | {
|
|---|
| 73 | qDeleteAll(m_items);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /*!
|
|---|
| 77 |
|
|---|
| 78 | */
|
|---|
| 79 | int QDesignerWidgetDataBaseInterface::count() const
|
|---|
| 80 | {
|
|---|
| 81 | return m_items.count();
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /*!
|
|---|
| 85 | */
|
|---|
| 86 | QDesignerWidgetDataBaseItemInterface *QDesignerWidgetDataBaseInterface::item(int index) const
|
|---|
| 87 | {
|
|---|
| 88 | return index != -1 ? m_items.at(index) : 0;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | /*!
|
|---|
| 92 | */
|
|---|
| 93 | int QDesignerWidgetDataBaseInterface::indexOf(QDesignerWidgetDataBaseItemInterface *item) const
|
|---|
| 94 | {
|
|---|
| 95 | return m_items.indexOf(item);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /*!
|
|---|
| 99 | */
|
|---|
| 100 | void QDesignerWidgetDataBaseInterface::insert(int index, QDesignerWidgetDataBaseItemInterface *item)
|
|---|
| 101 | {
|
|---|
| 102 | if (debugWidgetDataBase)
|
|---|
| 103 | qDebug() << "insert at " << index << ' ' << item->name() << " derived from " << item->extends();
|
|---|
| 104 |
|
|---|
| 105 | m_items.insert(index, item);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | /*!
|
|---|
| 109 | */
|
|---|
| 110 | void QDesignerWidgetDataBaseInterface::append(QDesignerWidgetDataBaseItemInterface *item)
|
|---|
| 111 | {
|
|---|
| 112 | if (debugWidgetDataBase)
|
|---|
| 113 | qDebug() << "append " << item->name() << " derived from " << item->extends();
|
|---|
| 114 | m_items.append(item);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /*!
|
|---|
| 118 | */
|
|---|
| 119 | QDesignerFormEditorInterface *QDesignerWidgetDataBaseInterface::core() const
|
|---|
| 120 | {
|
|---|
| 121 | return 0;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | /*!
|
|---|
| 125 | */
|
|---|
| 126 | int QDesignerWidgetDataBaseInterface::indexOfClassName(const QString &name, bool) const
|
|---|
| 127 | {
|
|---|
| 128 | const int itemCount = count();
|
|---|
| 129 | for (int i=0; i<itemCount; ++i) {
|
|---|
| 130 | const QDesignerWidgetDataBaseItemInterface *entry = item(i);
|
|---|
| 131 | if (entry->name() == name)
|
|---|
| 132 | return i;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | return -1;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /*!
|
|---|
| 139 | */
|
|---|
| 140 | int QDesignerWidgetDataBaseInterface::indexOfObject(QObject *object, bool) const
|
|---|
| 141 | {
|
|---|
| 142 | if (!object)
|
|---|
| 143 | return -1;
|
|---|
| 144 |
|
|---|
| 145 | const QString className = QString::fromUtf8(object->metaObject()->className());
|
|---|
| 146 | return indexOfClassName(className);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | /*!
|
|---|
| 150 | */
|
|---|
| 151 | bool QDesignerWidgetDataBaseInterface::isContainer(QObject *object, bool resolveName) const
|
|---|
| 152 | {
|
|---|
| 153 | if (const QDesignerWidgetDataBaseItemInterface *i = item(indexOfObject(object, resolveName)))
|
|---|
| 154 | return i->isContainer();
|
|---|
| 155 | return false;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /*!
|
|---|
| 159 | */
|
|---|
| 160 | bool QDesignerWidgetDataBaseInterface::isCustom(QObject *object, bool resolveName) const
|
|---|
| 161 | {
|
|---|
| 162 | if (const QDesignerWidgetDataBaseItemInterface *i = item(indexOfObject(object, resolveName)))
|
|---|
| 163 | return i->isCustom();
|
|---|
| 164 | return false;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /*!
|
|---|
| 168 | \fn void QDesignerWidgetDataBaseInterface::changed()
|
|---|
| 169 |
|
|---|
| 170 | This signal is emitted ...
|
|---|
| 171 | */
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | // Doc: No implementation - an abstract class
|
|---|
| 175 |
|
|---|
| 176 | /*!
|
|---|
| 177 | \class QDesignerWidgetDataBaseItemInterface
|
|---|
| 178 | \brief The QDesignerWidgetDataBaseItemInterface class provides an interface that is used to
|
|---|
| 179 | access individual items in Qt Designer's widget database.
|
|---|
| 180 | \inmodule QtDesigner
|
|---|
| 181 | \internal
|
|---|
| 182 |
|
|---|
| 183 | This class enables individual items in the widget database to be accessed and modified.
|
|---|
| 184 | Changes to the widget database itself are made through the QDesignerWidgetDataBaseInterface
|
|---|
| 185 | class.
|
|---|
| 186 | */
|
|---|
| 187 |
|
|---|
| 188 | /*!
|
|---|
| 189 | \fn virtual QDesignerWidgetDataBaseItemInterface::~QDesignerWidgetDataBaseItemInterface()
|
|---|
| 190 |
|
|---|
| 191 | Destroys the interface.
|
|---|
| 192 | */
|
|---|
| 193 |
|
|---|
| 194 | /*!
|
|---|
| 195 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::name() const = 0
|
|---|
| 196 |
|
|---|
| 197 | Returns the name of the widget.
|
|---|
| 198 | */
|
|---|
| 199 |
|
|---|
| 200 | /*!
|
|---|
| 201 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setName(const QString &name) = 0
|
|---|
| 202 | */
|
|---|
| 203 |
|
|---|
| 204 | /*!
|
|---|
| 205 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::group() const = 0
|
|---|
| 206 |
|
|---|
| 207 | Returns the name of the group that the widget belongs to.
|
|---|
| 208 | */
|
|---|
| 209 |
|
|---|
| 210 | /*!
|
|---|
| 211 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setGroup(const QString &group) = 0
|
|---|
| 212 | */
|
|---|
| 213 |
|
|---|
| 214 | /*!
|
|---|
| 215 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::toolTip() const = 0
|
|---|
| 216 |
|
|---|
| 217 | Returns the tool tip to be used by the widget.
|
|---|
| 218 | */
|
|---|
| 219 |
|
|---|
| 220 | /*!
|
|---|
| 221 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setToolTip(const QString &toolTip) = 0
|
|---|
| 222 | */
|
|---|
| 223 |
|
|---|
| 224 | /*!
|
|---|
| 225 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::whatsThis() const = 0
|
|---|
| 226 |
|
|---|
| 227 | Returns the "What's This?" help for the widget.
|
|---|
| 228 | */
|
|---|
| 229 |
|
|---|
| 230 | /*!
|
|---|
| 231 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setWhatsThis(const QString &whatsThis) = 0
|
|---|
| 232 | */
|
|---|
| 233 |
|
|---|
| 234 | /*!
|
|---|
| 235 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::includeFile() const = 0
|
|---|
| 236 |
|
|---|
| 237 | Returns the name of the include file that the widget needs when being built from source.
|
|---|
| 238 | */
|
|---|
| 239 |
|
|---|
| 240 | /*!
|
|---|
| 241 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setIncludeFile(const QString &includeFile) = 0
|
|---|
| 242 | */
|
|---|
| 243 |
|
|---|
| 244 | /*!
|
|---|
| 245 | \fn virtual QIcon QDesignerWidgetDataBaseItemInterface::icon() const = 0
|
|---|
| 246 |
|
|---|
| 247 | Returns the icon used to represent the item.
|
|---|
| 248 | */
|
|---|
| 249 |
|
|---|
| 250 | /*!
|
|---|
| 251 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setIcon(const QIcon &icon) = 0
|
|---|
| 252 | */
|
|---|
| 253 |
|
|---|
| 254 | /*!
|
|---|
| 255 | \fn virtual bool QDesignerWidgetDataBaseItemInterface::isCompat() const = 0
|
|---|
| 256 |
|
|---|
| 257 | Returns true if this type of widget is provided for compatibility purposes (e.g. Qt3Support
|
|---|
| 258 | widgets); otherwise returns false.
|
|---|
| 259 |
|
|---|
| 260 | \sa setCompat()
|
|---|
| 261 | */
|
|---|
| 262 |
|
|---|
| 263 | /*!
|
|---|
| 264 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setCompat(bool compat) = 0
|
|---|
| 265 |
|
|---|
| 266 | If \a compat is true, the widget is handled as a compatibility widget; otherwise it is
|
|---|
| 267 | handled normally by \QD.
|
|---|
| 268 |
|
|---|
| 269 | \sa isCompat()
|
|---|
| 270 | */
|
|---|
| 271 |
|
|---|
| 272 | /*!
|
|---|
| 273 | \fn virtual bool QDesignerWidgetDataBaseItemInterface::isContainer() const = 0
|
|---|
| 274 |
|
|---|
| 275 | Returns true if this widget is intended to be used to hold other widgets; otherwise returns
|
|---|
| 276 | false.
|
|---|
| 277 |
|
|---|
| 278 | \sa setContainer()
|
|---|
| 279 | */
|
|---|
| 280 |
|
|---|
| 281 | /*!
|
|---|
| 282 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setContainer(bool container) = 0
|
|---|
| 283 |
|
|---|
| 284 | If \a container is true, the widget can be used to hold other widgets in \QD; otherwise
|
|---|
| 285 | \QD will refuse to let the user place other widgets inside it.
|
|---|
| 286 |
|
|---|
| 287 | \sa isContainer()
|
|---|
| 288 | */
|
|---|
| 289 |
|
|---|
| 290 | /*!
|
|---|
| 291 | \fn virtual bool QDesignerWidgetDataBaseItemInterface::isCustom() const = 0
|
|---|
| 292 |
|
|---|
| 293 | Returns true if the widget is a custom widget; otherwise return false if it is a standard
|
|---|
| 294 | Qt widget.
|
|---|
| 295 |
|
|---|
| 296 | \sa setCustom()
|
|---|
| 297 | */
|
|---|
| 298 |
|
|---|
| 299 | /*!
|
|---|
| 300 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setCustom(bool custom) = 0
|
|---|
| 301 |
|
|---|
| 302 | If \a custom is true, the widget is handled specially by \QD; otherwise it is handled as
|
|---|
| 303 | a standard Qt widget.
|
|---|
| 304 |
|
|---|
| 305 | \sa isCustom()
|
|---|
| 306 | */
|
|---|
| 307 |
|
|---|
| 308 | /*!
|
|---|
| 309 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::pluginPath() const = 0
|
|---|
| 310 |
|
|---|
| 311 | Returns the path to use for the widget plugin.
|
|---|
| 312 | */
|
|---|
| 313 |
|
|---|
| 314 | /*!
|
|---|
| 315 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setPluginPath(const QString &path) = 0
|
|---|
| 316 | */
|
|---|
| 317 |
|
|---|
| 318 | /*!
|
|---|
| 319 | \fn virtual bool QDesignerWidgetDataBaseItemInterface::isPromoted() const = 0
|
|---|
| 320 |
|
|---|
| 321 | Returns true if the widget is promoted; otherwise returns false.
|
|---|
| 322 |
|
|---|
| 323 | Promoted widgets are those that represent custom widgets, but which are represented in
|
|---|
| 324 | \QD by either standard Qt widgets or readily-available custom widgets.
|
|---|
| 325 |
|
|---|
| 326 | \sa setPromoted()
|
|---|
| 327 | */
|
|---|
| 328 |
|
|---|
| 329 | /*!
|
|---|
| 330 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setPromoted(bool promoted) = 0
|
|---|
| 331 |
|
|---|
| 332 | If \a promoted is true, the widget is handled as a promoted widget by \QD and will use
|
|---|
| 333 | a placeholder widget to represent it; otherwise it is handled as a standard widget.
|
|---|
| 334 |
|
|---|
| 335 | \sa isPromoted()
|
|---|
| 336 | */
|
|---|
| 337 |
|
|---|
| 338 | /*!
|
|---|
| 339 | \fn virtual QString QDesignerWidgetDataBaseItemInterface::extends() const = 0
|
|---|
| 340 |
|
|---|
| 341 | Returns the name of the widget that the item extends.
|
|---|
| 342 | */
|
|---|
| 343 |
|
|---|
| 344 | /*!
|
|---|
| 345 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setExtends(const QString &s) = 0
|
|---|
| 346 | */
|
|---|
| 347 |
|
|---|
| 348 | /*!
|
|---|
| 349 | \fn virtual void QDesignerWidgetDataBaseItemInterface::setDefaultPropertyValues(const QList<QVariant> &list) = 0
|
|---|
| 350 |
|
|---|
| 351 | Sets the default property values for the widget to the given \a list.
|
|---|
| 352 | */
|
|---|
| 353 |
|
|---|
| 354 | /*!
|
|---|
| 355 | \fn virtual QList<QVariant> QDesignerWidgetDataBaseItemInterface::defaultPropertyValues() const = 0
|
|---|
| 356 |
|
|---|
| 357 | Returns a list of default values to be used as properties for the item.
|
|---|
| 358 | */
|
|---|
| 359 |
|
|---|
| 360 | QT_END_NAMESPACE
|
|---|