15#ifndef QDESIGNER_UTILS_H
16#define QDESIGNER_UTILS_H
20#include <QtDesigner/abstractformwindow.h>
22#include <QtCore/qcompare.h>
23#include <QtCore/qmap.h>
24#include <QtCore/qhash.h>
25#include <QtCore/qvariant.h>
26#include <QtCore/qshareddata.h>
27#include <QtWidgets/qmainwindow.h>
28#include <QtGui/qicon.h>
29#include <QtGui/qpixmap.h>
38class QDesignerFormWindowCommand;
39class DesignerIconCache;
52
53
54
55
56
57
60
61
63template <
class IntType>
72 MetaEnum(
const QString &enumName,
const QString &scope,
const QString &separator);
74 void addKey(IntType value,
const QString &name);
76 QString
valueToKey(IntType value,
bool *ok =
nullptr)
const;
78 IntType
keyToValue(QStringView key,
bool *ok =
nullptr)
const;
80 const QString &
enumName()
const {
return m_enumName; }
81 const QString &
scope()
const {
return m_scope; }
82 const QString &
separator()
const {
return m_separator; }
94 KeyToValueMap m_keyToValueMap;
98template <
class IntType>
99MetaEnum<IntType>::
MetaEnum(
const QString &enumName,
const QString &scope,
const QString &separator) :
106template <
class IntType>
109 m_keyToValueMap.insert({name, value});
113template <
class IntType>
117 for (
auto it = m_keyToValueMap.begin(), end = m_keyToValueMap.end(); it != end; ++it) {
118 if (it->second == value) {
128template <
class IntType>
131 const auto lastSep = key.lastIndexOf(m_separator);
133 key = key.sliced(lastSep + m_separator.size());
134 const auto it = m_keyToValueMap.find(key);
135 const bool found = it != m_keyToValueMap.end();
138 return found ? it->second : IntType(0);
141template <
class IntType>
143 QString &target)
const
145 if (!m_scope.isEmpty()) {
147 target += m_separator;
149 if (sm == FullyQualified)
150 target += m_enumName + m_separator;
205 PropertySheetFlagValue(
int v,
const DesignerMetaFlags &mf);
216 PropertySheetPixmapValue(
const QString &path);
217 PropertySheetPixmapValue();
220 enum PixmapSource { LanguageResourcePixmap , ResourcePixmap, FilePixmap };
221 static PixmapSource getPixmapSource(QDesignerFormEditorInterface *core,
const QString & path);
223 PixmapSource pixmapSource(QDesignerFormEditorInterface *core)
const {
return getPixmapSource(core, m_path); }
225 QString path()
const;
226 void setPath(
const QString &path);
229 friend size_t qHash(
const PropertySheetPixmapValue &p, size_t seed = 0)
noexcept
231 return qHash(p.m_path, seed);
233 friend bool comparesEqual(
const PropertySheetPixmapValue &lhs,
234 const PropertySheetPixmapValue &rhs)
noexcept
236 return lhs.m_path == rhs.m_path;
238 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetPixmapValue)
245class PropertySheetIconValueData;
250 explicit PropertySheetIconValue(
const PropertySheetPixmapValue &pixmap);
251 PropertySheetIconValue();
252 ~PropertySheetIconValue();
253 PropertySheetIconValue(
const PropertySheetIconValue &)
noexcept;
254 PropertySheetIconValue &operator=(
const PropertySheetIconValue &);
255 PropertySheetIconValue(PropertySheetIconValue &&)
noexcept;
256 PropertySheetIconValue &operator=(PropertySheetIconValue &&)
noexcept;
258 bool isEmpty()
const;
260 QString theme()
const;
261 void setTheme(
const QString &);
263 int themeEnum()
const;
264 void setThemeEnum(
int e);
266 PropertySheetPixmapValue pixmap(QIcon::Mode mode, QIcon::State state)
const;
267 void setPixmap(QIcon::Mode mode, QIcon::State state,
const PropertySheetPixmapValue &path);
270 uint compare(
const PropertySheetIconValue &other)
const;
271 void assign(
const PropertySheetIconValue &other, uint mask);
274 PropertySheetIconValue themed()
const;
275 PropertySheetIconValue unthemed()
const;
277 using ModeStateKey = std::pair<QIcon::Mode, QIcon::State>;
278 using ModeStateToPixmapMap = QMap<ModeStateKey, PropertySheetPixmapValue>;
280 const ModeStateToPixmapMap &paths()
const;
284 size_t qHash(
const PropertySheetIconValue &p, size_t seed)
noexcept;
285 friend size_t qHash(
const PropertySheetIconValue &p)
noexcept
286 {
return qHash(p, 0); }
288 bool comparesEqual(
const PropertySheetIconValue &lhs,
289 const PropertySheetIconValue &rhs)
noexcept;
290 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetIconValue)
292 QSharedDataPointer<PropertySheetIconValueData> m_data;
301 DesignerPixmapCache(QObject *parent =
nullptr);
302 QPixmap pixmap(
const PropertySheetPixmapValue &value)
const;
307 mutable QHash<PropertySheetPixmapValue, QPixmap> m_cache;
308 friend class FormWindowBase;
315 explicit DesignerIconCache(DesignerPixmapCache *pixmapCache, QObject *parent =
nullptr);
316 QIcon icon(
const PropertySheetIconValue &value)
const;
321 mutable QHash<PropertySheetIconValue, QIcon> m_cache;
322 DesignerPixmapCache *m_pixmapCache;
323 friend class FormWindowBase;
330 PropertySheetTranslatableData(
bool translatable =
true,
331 const QString &disambiguation = QString(),
332 const QString &comment = QString());
335 bool translatable()
const {
return m_translatable; }
336 void setTranslatable(
bool translatable) { m_translatable = translatable; }
337 QString disambiguation()
const {
return m_disambiguation; }
338 void setDisambiguation(
const QString &d) { m_disambiguation = d; }
339 QString comment()
const {
return m_comment; }
340 void setComment(
const QString &comment) { m_comment = comment; }
341 QString id()
const {
return m_id; }
342 void setId(
const QString &id) { m_id = id; }
345 friend bool comparesEqual(
const PropertySheetTranslatableData &lhs,
346 const PropertySheetTranslatableData &rhs)
noexcept
348 return lhs.m_translatable == rhs.m_translatable
349 && lhs.m_disambiguation == rhs.m_disambiguation
350 && lhs.m_comment == rhs.m_comment
351 && lhs.m_id == rhs.m_id;
353 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetTranslatableData)
356 QString m_disambiguation;
365 PropertySheetStringValue(
const QString &value = QString(),
bool translatable =
true,
366 const QString &disambiguation = QString(),
const QString &comment = QString());
368 QString value()
const;
369 void setValue(
const QString &value);
372 friend bool comparesEqual(
const PropertySheetStringValue &lhs,
373 const PropertySheetStringValue &rhs)
noexcept
375 const PropertySheetTranslatableData &upLhs = lhs;
376 const PropertySheetTranslatableData &upRhs = rhs;
377 return lhs.m_value == rhs.m_value && upLhs == upRhs;
379 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringValue)
388 PropertySheetStringListValue(
const QStringList &value = QStringList(),
389 bool translatable =
true,
390 const QString &disambiguation = QString(),
391 const QString &comment = QString());
393 QStringList value()
const;
394 void setValue(
const QStringList &value);
397 friend bool comparesEqual(
const PropertySheetStringListValue &lhs,
398 const PropertySheetStringListValue &rhs)
noexcept
400 const PropertySheetTranslatableData &upLhs = lhs;
401 const PropertySheetTranslatableData &upRhs = rhs;
402 return lhs.m_value == rhs.m_value && upLhs == upRhs;
404 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringListValue)
413 PropertySheetKeySequenceValue(
const QKeySequence &value = QKeySequence(),
414 bool translatable =
true,
415 const QString &disambiguation = QString(),
416 const QString &comment = QString());
417 PropertySheetKeySequenceValue(
const QKeySequence::StandardKey &standardKey,
418 bool translatable =
true,
419 const QString &disambiguation = QString(),
420 const QString &comment = QString());
422 QKeySequence value()
const;
423 void setValue(
const QKeySequence &value);
424 QKeySequence::StandardKey standardKey()
const;
425 void setStandardKey(
const QKeySequence::StandardKey &standardKey);
426 bool isStandardKey()
const;
429 friend bool comparesEqual(
const PropertySheetKeySequenceValue &lhs,
430 const PropertySheetKeySequenceValue &rhs)
noexcept
432 const PropertySheetTranslatableData &upLhs = lhs;
433 const PropertySheetTranslatableData &upRhs = rhs;
434 return lhs.m_value == rhs.m_value && lhs.m_standardKey == rhs.m_standardKey
437 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetKeySequenceValue)
439 QKeySequence m_value;
440 QKeySequence::StandardKey m_standardKey;
450Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetFlagValue)
451Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetPixmapValue)
452Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetIconValue)
453Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringValue)
454Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringListValue)
455Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetKeySequenceValue)
477 QByteArray& ba, QString &errorMessage);
483
484
495 const bool m_enabled;
500 QPalette::ColorRole colorRole);
506inline int valueOf(
const QVariant &value,
bool *ok =
nullptr)
508 if (value.canConvert<PropertySheetEnumValue>()) {
511 return qvariant_cast<PropertySheetEnumValue>(value).value;
513 if (value.canConvert<PropertySheetFlagValue>()) {
518 return value.toInt(ok);
523 QObject *obj = child;
524 while (obj !=
nullptr) {
534 if (! fw || ! widget)
537 if (widget == fw->mainContainer())
541 if (
auto *mw = qobject_cast<QMainWindow*>(fw->mainContainer()))
542 return mw->centralWidget() == widget;
static bool canBeBuddy(QWidget *w, QDesignerFormWindowInterface *form)
static QString buddy(QLabel *label, QDesignerFormEditorInterface *core)
static constexpr auto buddyPropertyC
#define QT_BUDDYEDITOR_EXPORT
void init(QWidget *parentWidget, QAction *action, QAction *beforeAction=nullptr, bool update=true)
ActionInsertionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QStackedWidget *stackedWidget)
void init(QStackedWidget *stackedWidget, InsertionMode mode)
~AddStackedWidgetPageCommand() override
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
~AddTabPageCommand() override
void init(QTabWidget *tabWidget, InsertionMode mode)
void init(QTabWidget *tabWidget)
AddTabPageCommand(QDesignerFormWindowInterface *formWindow)
AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, InsertionMode mode)
~AddToolBoxPageCommand() override
void init(QToolBox *toolBox)
void undo() override
Reverts a change to the document.
void setBackground(QWidget *background) override
QDesignerFormWindowInterface * formWindow() const
void endConnection(QWidget *target, const QPoint &pos) override
void widgetRemoved(QWidget *w) override
QWidget * widgetAt(const QPoint &pos) const override
Connection * createConnection(QWidget *source, QWidget *destination) override
void createContextMenu(QMenu &menu) override
void deleteSelected() override
CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QMainWindow *mainWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void init(QMainWindow *mainWindow)
CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect=nullptr)
CreateSubmenuCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void restore(QDesignerFormWindowInterface *formWindow) const
void save(const QDesignerFormWindowInterface *formWindow)
void init(QMenuBar *menuBar)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void init(QStackedWidget *stackedWidget)
void redo() override
Applies a change to the document.
~DeleteStackedWidgetPageCommand() override
void undo() override
Reverts a change to the document.
void init(QTabWidget *tabWidget)
void redo() override
Applies a change to the document.
~DeleteTabPageCommand() override
void undo() override
Reverts a change to the document.
DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow)
void init(QToolBox *toolBox)
DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
~DeleteToolBoxPageCommand() override
void undo() override
Reverts a change to the document.
InsertActionIntoCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QAction *action, QAction *actionBefore, QWidget *associatedWidget, QWidget *objectToSelect)
MenuActionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
~MoveTabPageCommand() override
void undo() override
Reverts a change to the document.
MoveTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QTabWidget *tabWidget, QWidget *page, const QIcon &icon, const QString &label, int index, int newIndex)
MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, QWidget *page, int newIndex)
void undo() override
Reverts a change to the document.
~MoveToolBoxPageCommand() override
RemoveActionFromCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
RemoveMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
Combined button and popup list for selecting options.
int valueOf(const QVariant &value, bool *ok=nullptr)
bool isObjectAncestorOf(QObject *ancestor, QObject *child)
bool isCentralWidget(QDesignerFormWindowInterface *fw, QWidget *widget)
Auxiliary methods to store/retrieve settings.
QDESIGNER_SHARED_EXPORT void getFormLayoutItemPosition(const QFormLayout *formLayout, int index, int *rowPtr, int *columnPtr=nullptr, int *rowspanPtr=nullptr, int *colspanPtr=nullptr)
static QUndoCommand * createBuddyCommand(QDesignerFormWindowInterface *fw, QLabel *label, QWidget *buddy)
QDESIGNER_SHARED_EXPORT void formLayoutAddWidget(QFormLayout *formLayout, QWidget *w, const QRect &r, bool insert)
QDESIGNER_SHARED_EXPORT void designerWarning(const QString &message)
QDESIGNER_SHARED_EXPORT void reloadIconResources(DesignerIconCache *iconCache, QObject *object)
QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UicLanguage language, QByteArray &ba, QString &errorMessage)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
#define QDESIGNER_SHARED_EXPORT
DesignerMetaEnum metaEnum
DesignerMetaFlags metaFlags