| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Designer of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #include "abstractwidgetbox.h" | 
| 30 |  | 
| 31 | QT_BEGIN_NAMESPACE | 
| 32 |  | 
| 33 | /*! | 
| 34 |     \class QDesignerWidgetBoxInterface | 
| 35 |  | 
| 36 |     \brief The QDesignerWidgetBoxInterface class allows you to control | 
| 37 |     the contents of Qt Designer's widget box. | 
| 38 |  | 
| 39 |     \inmodule QtDesigner | 
| 40 |  | 
| 41 |     QDesignerWidgetBoxInterface contains a collection of functions | 
| 42 |     that is typically used to manipulate the contents of \QD's widget | 
| 43 |     box. | 
| 44 |  | 
| 45 |     \QD uses an XML file to populate its widget box. The name of that | 
| 46 |     file is one of the widget box's properties, and you can retrieve | 
| 47 |     it using the fileName() function. | 
| 48 |  | 
| 49 |     QDesignerWidgetBoxInterface also provides the save() function that | 
| 50 |     saves the contents of the widget box in the file specified by the | 
| 51 |     widget box's file name property. If you have made changes to the | 
| 52 |     widget box, for example by dropping a widget into the widget box, | 
| 53 |     without calling the save() function, the original content can be | 
| 54 |     restored by a simple invocation of the load() function: | 
| 55 |  | 
| 56 |     \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 0 | 
| 57 |  | 
| 58 |     The QDesignerWidgetBoxInterface class is not intended to be | 
| 59 |     instantiated directly. You can retrieve an interface to Qt | 
| 60 |     Designer's widget box using the | 
| 61 |     QDesignerFormEditorInterface::widgetBox() function. A pointer to | 
| 62 |     \QD's current QDesignerFormEditorInterface object (\c formEditor | 
| 63 |     in the example above) is provided by the | 
| 64 |     QDesignerCustomWidgetInterface::initialize() function's | 
| 65 |     parameter. When implementing a custom widget plugin, you must | 
| 66 |     subclass the QDesignerCustomWidgetInterface to expose your plugin | 
| 67 |     to \QD. | 
| 68 |  | 
| 69 |     If you want to save your changes, and at the same time preserve | 
| 70 |     the original contents, you can use the save() function combined | 
| 71 |     with the setFileName() function to save your changes into another | 
| 72 |     file. Remember to store the name of the original file first: | 
| 73 |  | 
| 74 |     \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 1 | 
| 75 |  | 
| 76 |     Then you can restore the original contents of the widget box by | 
| 77 |     resetting the file name to the original file and calling load(): | 
| 78 |  | 
| 79 |     \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 2 | 
| 80 |  | 
| 81 |     In a similar way, you can later use your customized XML file: | 
| 82 |  | 
| 83 |     \snippet lib/tools_designer_src_lib_sdk_abstractwidgetbox.cpp 3 | 
| 84 |  | 
| 85 |  | 
| 86 |     \sa QDesignerFormEditorInterface | 
| 87 | */ | 
| 88 |  | 
| 89 | /*! | 
| 90 |     Constructs a widget box interface with the given \a parent and | 
| 91 |     the specified window \a flags. | 
| 92 | */ | 
| 93 | QDesignerWidgetBoxInterface::QDesignerWidgetBoxInterface(QWidget *parent, Qt::WindowFlags flags) | 
| 94 |     : QWidget(parent, flags) | 
| 95 | { | 
| 96 | } | 
| 97 |  | 
| 98 | /*! | 
| 99 |     Destroys the widget box interface. | 
| 100 | */ | 
| 101 | QDesignerWidgetBoxInterface::~QDesignerWidgetBoxInterface() | 
| 102 | { | 
| 103 | } | 
| 104 |  | 
| 105 | /*! | 
| 106 |     \internal | 
| 107 | */ | 
| 108 | int QDesignerWidgetBoxInterface::findOrInsertCategory(const QString &categoryName) | 
| 109 | { | 
| 110 |     int count = categoryCount(); | 
| 111 |     for (int index=0; index<count; ++index) { | 
| 112 |         Category c = category(cat_idx: index); | 
| 113 |         if (c.name() == categoryName) | 
| 114 |             return index; | 
| 115 |     } | 
| 116 |  | 
| 117 |     addCategory(cat: Category(categoryName)); | 
| 118 |     return count; | 
| 119 | } | 
| 120 |  | 
| 121 | /*! | 
| 122 |     \internal | 
| 123 |     \fn int QDesignerWidgetBoxInterface::categoryCount() const | 
| 124 | */ | 
| 125 |  | 
| 126 | /*! | 
| 127 |     \internal | 
| 128 |     \fn Category QDesignerWidgetBoxInterface::category(int cat_idx) const | 
| 129 | */ | 
| 130 |  | 
| 131 | /*! | 
| 132 |     \internal | 
| 133 |     \fn void QDesignerWidgetBoxInterface::addCategory(const Category &cat) | 
| 134 | */ | 
| 135 |  | 
| 136 | /*! | 
| 137 |     \internal | 
| 138 |     \fn void QDesignerWidgetBoxInterface::removeCategory(int cat_idx) | 
| 139 | */ | 
| 140 |  | 
| 141 | /*! | 
| 142 |     \internal | 
| 143 |     \fn int QDesignerWidgetBoxInterface::widgetCount(int cat_idx) const | 
| 144 | */ | 
| 145 |  | 
| 146 | /*! | 
| 147 |     \internal | 
| 148 |     \fn Widget QDesignerWidgetBoxInterface::widget(int cat_idx, int wgt_idx) const | 
| 149 | */ | 
| 150 |  | 
| 151 | /*! | 
| 152 |     \internal | 
| 153 |     \fn void QDesignerWidgetBoxInterface::addWidget(int cat_idx, const Widget &wgt) | 
| 154 | */ | 
| 155 |  | 
| 156 | /*! | 
| 157 |     \internal | 
| 158 |     \fn void QDesignerWidgetBoxInterface::removeWidget(int cat_idx, int wgt_idx) | 
| 159 | */ | 
| 160 |  | 
| 161 | /*! | 
| 162 |     \internal | 
| 163 |     \fn void QDesignerWidgetBoxInterface::dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, const QPoint &global_mouse_pos) | 
| 164 |  | 
| 165 | */ | 
| 166 |  | 
| 167 | /*! | 
| 168 |     \fn void QDesignerWidgetBoxInterface::setFileName(const QString &fileName) | 
| 169 |  | 
| 170 |     Sets the XML file that \QD will use to populate its widget box, to | 
| 171 |     \a fileName. You must call load() to update the widget box with | 
| 172 |     the new XML file. | 
| 173 |  | 
| 174 |     \sa fileName(), load() | 
| 175 | */ | 
| 176 |  | 
| 177 | /*! | 
| 178 |     \fn QString QDesignerWidgetBoxInterface::fileName() const | 
| 179 |  | 
| 180 |     Returns the name of the XML file \QD is currently using to | 
| 181 |     populate its widget box. | 
| 182 |  | 
| 183 |     \sa setFileName() | 
| 184 | */ | 
| 185 |  | 
| 186 | /*! | 
| 187 |     \fn bool QDesignerWidgetBoxInterface::load() | 
| 188 |  | 
| 189 |     Populates \QD's widget box by loading (or reloading) the currently | 
| 190 |     specified XML file. Returns true if the file is successfully | 
| 191 |     loaded; otherwise false. | 
| 192 |  | 
| 193 |     \sa setFileName() | 
| 194 | */ | 
| 195 |  | 
| 196 | /*! | 
| 197 |     \fn bool QDesignerWidgetBoxInterface::save() | 
| 198 |  | 
| 199 |     Saves the contents of \QD's widget box in the file specified by | 
| 200 |     the fileName() function. Returns true if the content is | 
| 201 |     successfully saved; otherwise false. | 
| 202 |  | 
| 203 |     \sa fileName(), setFileName() | 
| 204 | */ | 
| 205 |  | 
| 206 |  | 
| 207 | /*! | 
| 208 |     \internal | 
| 209 |  | 
| 210 |     \class QDesignerWidgetBoxInterface::Widget | 
| 211 |  | 
| 212 |     \brief The Widget class specified a widget in Qt Designer's widget | 
| 213 |     box component. | 
| 214 | */ | 
| 215 |  | 
| 216 | /*! | 
| 217 |     \enum QDesignerWidgetBoxInterface::Widget::Type | 
| 218 |  | 
| 219 |     \value Default | 
| 220 |     \value Custom | 
| 221 | */ | 
| 222 |  | 
| 223 | /*! | 
| 224 |     \fn QDesignerWidgetBoxInterface::Widget::Widget(const QString &aname, const QString &xml, const QString &icon_name, Type atype) | 
| 225 | */ | 
| 226 |  | 
| 227 | /*! | 
| 228 |     \fn QString QDesignerWidgetBoxInterface::Widget::name() const | 
| 229 | */ | 
| 230 |  | 
| 231 | /*! | 
| 232 |     \fn void QDesignerWidgetBoxInterface::Widget::setName(const QString &aname) | 
| 233 | */ | 
| 234 |  | 
| 235 | /*! | 
| 236 |     \fn QString QDesignerWidgetBoxInterface::Widget::domXml() const | 
| 237 | */ | 
| 238 |  | 
| 239 | /*! | 
| 240 |     \fn void QDesignerWidgetBoxInterface::Widget::setDomXml(const QString &xml) | 
| 241 | */ | 
| 242 |  | 
| 243 | /*! | 
| 244 |     \fn QString QDesignerWidgetBoxInterface::Widget::iconName() const | 
| 245 | */ | 
| 246 |  | 
| 247 | /*! | 
| 248 |     \fn void QDesignerWidgetBoxInterface::Widget::setIconName(const QString &icon_name) | 
| 249 | */ | 
| 250 |  | 
| 251 | /*! | 
| 252 |     \fn Type QDesignerWidgetBoxInterface::Widget::type() const | 
| 253 | */ | 
| 254 |  | 
| 255 | /*! | 
| 256 |     \fn void QDesignerWidgetBoxInterface::Widget::setType(Type atype) | 
| 257 | */ | 
| 258 |  | 
| 259 | /*! | 
| 260 |     \fn bool QDesignerWidgetBoxInterface::Widget::isNull() const | 
| 261 | */ | 
| 262 |  | 
| 263 |  | 
| 264 | /*! | 
| 265 |     \class QDesignerWidgetBoxInterface::Category | 
| 266 |     \brief The Category class specifies a category in Qt Designer's widget box component. | 
| 267 |     \internal | 
| 268 | */ | 
| 269 |  | 
| 270 | /*! | 
| 271 |     \enum QDesignerWidgetBoxInterface::Category::Type | 
| 272 |  | 
| 273 |     \value Default | 
| 274 |     \value Scratchpad | 
| 275 | */ | 
| 276 |  | 
| 277 | /*! | 
| 278 |     \fn QDesignerWidgetBoxInterface::Category::Category(const QString &aname, Type atype) | 
| 279 | */ | 
| 280 |  | 
| 281 | /*! | 
| 282 |     \fn QString QDesignerWidgetBoxInterface::Category::name() const | 
| 283 | */ | 
| 284 |  | 
| 285 | /*! | 
| 286 |     \fn void QDesignerWidgetBoxInterface::Category::setName(const QString &aname) | 
| 287 | */ | 
| 288 |  | 
| 289 | /*! | 
| 290 |     \fn int QDesignerWidgetBoxInterface::Category::widgetCount() const | 
| 291 | */ | 
| 292 |  | 
| 293 | /*! | 
| 294 |     \fn Widget QDesignerWidgetBoxInterface::Category::widget(int idx) const | 
| 295 | */ | 
| 296 |  | 
| 297 | /*! | 
| 298 |     \fn void QDesignerWidgetBoxInterface::Category::removeWidget(int idx) | 
| 299 | */ | 
| 300 |  | 
| 301 | /*! | 
| 302 |     \fn void QDesignerWidgetBoxInterface::Category::addWidget(const Widget &awidget) | 
| 303 | */ | 
| 304 |  | 
| 305 | /*! | 
| 306 |     \fn Type QDesignerWidgetBoxInterface::Category::type() const | 
| 307 | */ | 
| 308 |  | 
| 309 | /*! | 
| 310 |     \fn void QDesignerWidgetBoxInterface::Category::setType(Type atype) | 
| 311 | */ | 
| 312 |  | 
| 313 | /*! | 
| 314 |     \fn bool QDesignerWidgetBoxInterface::Category::isNull() const | 
| 315 | */ | 
| 316 |  | 
| 317 | /*! | 
| 318 |     \typedef QDesignerWidgetBoxInterface::CategoryList | 
| 319 |     \internal | 
| 320 | */ | 
| 321 |  | 
| 322 | /*! | 
| 323 |     \typedef QDesignerWidgetBoxInterface::WidgetList | 
| 324 |     \internal | 
| 325 | */ | 
| 326 |  | 
| 327 | QT_END_NAMESPACE | 
| 328 |  |