16#ifndef QDESIGNER_UTILS_H
17#define QDESIGNER_UTILS_H
21#include <QtDesigner/abstractformwindow.h>
23#include <QtCore/qcompare.h>
24#include <QtCore/qmap.h>
25#include <QtCore/qhash.h>
26#include <QtCore/qvariant.h>
27#include <QtCore/qshareddata.h>
28#include <QtWidgets/qmainwindow.h>
29#include <QtGui/qicon.h>
30#include <QtGui/qpixmap.h>
39class QDesignerFormWindowCommand;
40class DesignerIconCache;
53
54
55
56
57
58
61
62
64template <
class IntType>
73 MetaEnum(
const QString &enumName,
const QString &scope,
const QString &separator);
75 void addKey(IntType value,
const QString &name);
77 QString
valueToKey(IntType value,
bool *ok =
nullptr)
const;
79 IntType
keyToValue(QStringView key,
bool *ok =
nullptr)
const;
81 const QString &
enumName()
const {
return m_enumName; }
82 const QString &
scope()
const {
return m_scope; }
83 const QString &
separator()
const {
return m_separator; }
95 KeyToValueMap m_keyToValueMap;
99template <
class IntType>
100MetaEnum<IntType>::
MetaEnum(
const QString &enumName,
const QString &scope,
const QString &separator) :
107template <
class IntType>
110 m_keyToValueMap.insert({name, value});
114template <
class IntType>
118 for (
auto it = m_keyToValueMap.begin(), end = m_keyToValueMap.end(); it != end; ++it) {
119 if (it->second == value) {
129template <
class IntType>
132 const auto lastSep = key.lastIndexOf(m_separator);
134 key = key.sliced(lastSep + m_separator.size());
135 const auto it = m_keyToValueMap.find(key);
136 const bool found = it != m_keyToValueMap.end();
139 return found ? it->second : IntType(0);
142template <
class IntType>
144 QString &target)
const
146 if (!m_scope.isEmpty()) {
148 target += m_separator;
150 if (sm == FullyQualified)
151 target += m_enumName + m_separator;
206 PropertySheetFlagValue(
int v,
const DesignerMetaFlags &mf);
217 PropertySheetPixmapValue(
const QString &path);
218 PropertySheetPixmapValue();
221 enum PixmapSource { LanguageResourcePixmap , ResourcePixmap, FilePixmap };
222 static PixmapSource getPixmapSource(QDesignerFormEditorInterface *core,
const QString & path);
224 PixmapSource pixmapSource(QDesignerFormEditorInterface *core)
const {
return getPixmapSource(core, m_path); }
226 QString path()
const;
227 void setPath(
const QString &path);
230 friend size_t qHash(
const PropertySheetPixmapValue &p, size_t seed = 0)
noexcept
232 return qHash(p.m_path, seed);
234 friend bool comparesEqual(
const PropertySheetPixmapValue &lhs,
235 const PropertySheetPixmapValue &rhs)
noexcept
237 return lhs.m_path == rhs.m_path;
239 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetPixmapValue)
246class PropertySheetIconValueData;
251 explicit PropertySheetIconValue(
const PropertySheetPixmapValue &pixmap);
252 PropertySheetIconValue();
253 ~PropertySheetIconValue();
254 PropertySheetIconValue(
const PropertySheetIconValue &)
noexcept;
255 PropertySheetIconValue &operator=(
const PropertySheetIconValue &);
256 PropertySheetIconValue(PropertySheetIconValue &&)
noexcept;
257 PropertySheetIconValue &operator=(PropertySheetIconValue &&)
noexcept;
259 bool isEmpty()
const;
261 QString theme()
const;
262 void setTheme(
const QString &);
264 int themeEnum()
const;
265 void setThemeEnum(
int e);
267 PropertySheetPixmapValue pixmap(QIcon::Mode mode, QIcon::State state)
const;
268 void setPixmap(QIcon::Mode mode, QIcon::State state,
const PropertySheetPixmapValue &path);
271 uint compare(
const PropertySheetIconValue &other)
const;
272 void assign(
const PropertySheetIconValue &other, uint mask);
275 PropertySheetIconValue themed()
const;
276 PropertySheetIconValue unthemed()
const;
278 using ModeStateKey = std::pair<QIcon::Mode, QIcon::State>;
279 using ModeStateToPixmapMap = QMap<ModeStateKey, PropertySheetPixmapValue>;
281 const ModeStateToPixmapMap &paths()
const;
285 size_t qHash(
const PropertySheetIconValue &p, size_t seed)
noexcept;
286 friend size_t qHash(
const PropertySheetIconValue &p)
noexcept
287 {
return qHash(p, 0); }
289 bool comparesEqual(
const PropertySheetIconValue &lhs,
290 const PropertySheetIconValue &rhs)
noexcept;
291 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetIconValue)
293 QSharedDataPointer<PropertySheetIconValueData> m_data;
302 DesignerPixmapCache(QObject *parent =
nullptr);
303 QPixmap pixmap(
const PropertySheetPixmapValue &value)
const;
308 mutable QHash<PropertySheetPixmapValue, QPixmap> m_cache;
309 friend class FormWindowBase;
316 explicit DesignerIconCache(DesignerPixmapCache *pixmapCache, QObject *parent =
nullptr);
317 QIcon icon(
const PropertySheetIconValue &value)
const;
322 mutable QHash<PropertySheetIconValue, QIcon> m_cache;
323 DesignerPixmapCache *m_pixmapCache;
324 friend class FormWindowBase;
331 PropertySheetTranslatableData(
bool translatable =
true,
332 const QString &disambiguation = QString(),
333 const QString &comment = QString());
336 bool translatable()
const {
return m_translatable; }
337 void setTranslatable(
bool translatable) { m_translatable = translatable; }
338 QString disambiguation()
const {
return m_disambiguation; }
339 void setDisambiguation(
const QString &d) { m_disambiguation = d; }
340 QString comment()
const {
return m_comment; }
341 void setComment(
const QString &comment) { m_comment = comment; }
342 QString id()
const {
return m_id; }
343 void setId(
const QString &id) { m_id = id; }
346 friend bool comparesEqual(
const PropertySheetTranslatableData &lhs,
347 const PropertySheetTranslatableData &rhs)
noexcept
349 return lhs.m_translatable == rhs.m_translatable
350 && lhs.m_disambiguation == rhs.m_disambiguation
351 && lhs.m_comment == rhs.m_comment
352 && lhs.m_id == rhs.m_id;
354 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetTranslatableData)
357 QString m_disambiguation;
366 PropertySheetStringValue(
const QString &value = QString(),
bool translatable =
true,
367 const QString &disambiguation = QString(),
const QString &comment = QString());
369 QString value()
const;
370 void setValue(
const QString &value);
373 friend bool comparesEqual(
const PropertySheetStringValue &lhs,
374 const PropertySheetStringValue &rhs)
noexcept
376 const PropertySheetTranslatableData &upLhs = lhs;
377 const PropertySheetTranslatableData &upRhs = rhs;
378 return lhs.m_value == rhs.m_value && upLhs == upRhs;
380 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringValue)
389 PropertySheetStringListValue(
const QStringList &value = QStringList(),
390 bool translatable =
true,
391 const QString &disambiguation = QString(),
392 const QString &comment = QString());
394 QStringList value()
const;
395 void setValue(
const QStringList &value);
398 friend bool comparesEqual(
const PropertySheetStringListValue &lhs,
399 const PropertySheetStringListValue &rhs)
noexcept
401 const PropertySheetTranslatableData &upLhs = lhs;
402 const PropertySheetTranslatableData &upRhs = rhs;
403 return lhs.m_value == rhs.m_value && upLhs == upRhs;
405 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringListValue)
414 PropertySheetKeySequenceValue(
const QKeySequence &value = QKeySequence(),
415 bool translatable =
true,
416 const QString &disambiguation = QString(),
417 const QString &comment = QString());
418 PropertySheetKeySequenceValue(
const QKeySequence::StandardKey &standardKey,
419 bool translatable =
true,
420 const QString &disambiguation = QString(),
421 const QString &comment = QString());
423 QKeySequence value()
const;
424 void setValue(
const QKeySequence &value);
425 QKeySequence::StandardKey standardKey()
const;
426 void setStandardKey(
const QKeySequence::StandardKey &standardKey);
427 bool isStandardKey()
const;
430 friend bool comparesEqual(
const PropertySheetKeySequenceValue &lhs,
431 const PropertySheetKeySequenceValue &rhs)
noexcept
433 const PropertySheetTranslatableData &upLhs = lhs;
434 const PropertySheetTranslatableData &upRhs = rhs;
435 return lhs.m_value == rhs.m_value && lhs.m_standardKey == rhs.m_standardKey
438 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetKeySequenceValue)
440 QKeySequence m_value;
441 QKeySequence::StandardKey m_standardKey;
451Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetFlagValue)
452Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetPixmapValue)
453Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetIconValue)
454Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringValue)
455Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringListValue)
456Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetKeySequenceValue)
478 QByteArray& ba, QString &errorMessage);
484
485
496 const bool m_enabled;
501 QPalette::ColorRole colorRole);
507inline int valueOf(
const QVariant &value,
bool *ok =
nullptr)
509 if (value.canConvert<PropertySheetEnumValue>()) {
512 return qvariant_cast<PropertySheetEnumValue>(value).value;
514 if (value.canConvert<PropertySheetFlagValue>()) {
519 return value.toInt(ok);
524 QObject *obj = child;
525 while (obj !=
nullptr) {
535 if (! fw || ! widget)
538 if (widget == fw->mainContainer())
542 if (
auto *mw = qobject_cast<QMainWindow*>(fw->mainContainer()))
543 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)
QT_END_NAMESPACE Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QtOhos::enums::kit::ShareKit::systemShare::SelectionMode))
#define QDESIGNER_SHARED_EXPORT
DesignerMetaEnum metaEnum
DesignerMetaFlags metaFlags