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>
41class QDesignerFormWindowCommand;
42class DesignerIconCache;
55
56
57
58
59
60
63
64
66template <
class IntType>
75 MetaEnum(
const QString &enumName,
const QString &scope,
const QString &separator);
77 void addKey(IntType value,
const QString &name);
83 const QString &
enumName()
const {
return m_enumName; }
84 const QString &
scope()
const {
return m_scope; }
85 const QString &
separator()
const {
return m_separator; }
105 KeyToValueMap m_keyToValueMap;
106 KeyToValueMap m_canonicalKeyToValueMap;
110template <
class IntType>
111MetaEnum<IntType>::
MetaEnum(
const QString &enumName,
const QString &scope,
const QString &separator) :
118template <
class IntType>
121 m_keyToValueMap.insert({name, value});
122 const bool singleBit = value != 0 && (value & (value - IntType(1))) == 0;
123 const auto &m = m_canonicalKeyToValueMap;
125 ||
std::none_of(m.cbegin(), m.cend(),
126 [value](
const auto &e) {
return e.second == value; })) {
127 m_canonicalKeyToValueMap.insert({name, value});
132template <
class IntType>
135 for (
auto it = m_keyToValueMap.begin(), end = m_keyToValueMap.end(); it != end; ++it) {
136 if (it->second == value)
142template <
class IntType>
146 const auto lastSep = key.lastIndexOf(m_separator);
148 key = key.sliced(lastSep + m_separator.size());
149 const auto it = m_keyToValueMap.find(key);
150 if (it == m_keyToValueMap.end())
155template <
class IntType>
156bool MetaEnum<IntType>::trimValue(QStringView *value)
158 *value = value->trimmed();
159 return std::none_of(value->cbegin(), value->cend(),
160 [](QChar c) {
return c.isSpace() && c != u' '; });
163template <
class IntType>
165 QString &target)
const
167 if (!m_scope.isEmpty()) {
169 target += m_separator;
171 if (sm == FullyQualified)
172 target += m_enumName + m_separator;
227 PropertySheetFlagValue(
int v,
const DesignerMetaFlags &mf);
238 PropertySheetPixmapValue(
const QString &path);
239 PropertySheetPixmapValue();
242 enum PixmapSource { LanguageResourcePixmap , ResourcePixmap, FilePixmap };
243 static PixmapSource getPixmapSource(QDesignerFormEditorInterface *core,
const QString & path);
245 PixmapSource pixmapSource(QDesignerFormEditorInterface *core)
const {
return getPixmapSource(core, m_path); }
247 QString path()
const;
248 void setPath(
const QString &path);
251 friend size_t qHash(
const PropertySheetPixmapValue &p, size_t seed = 0)
noexcept
253 return qHash(p.m_path, seed);
255 friend bool comparesEqual(
const PropertySheetPixmapValue &lhs,
256 const PropertySheetPixmapValue &rhs)
noexcept
258 return lhs.m_path == rhs.m_path;
260 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetPixmapValue)
267class PropertySheetIconValueData;
272 explicit PropertySheetIconValue(
const PropertySheetPixmapValue &pixmap);
273 PropertySheetIconValue();
274 ~PropertySheetIconValue();
275 PropertySheetIconValue(
const PropertySheetIconValue &)
noexcept;
276 PropertySheetIconValue &operator=(
const PropertySheetIconValue &);
277 PropertySheetIconValue(PropertySheetIconValue &&)
noexcept;
278 PropertySheetIconValue &operator=(PropertySheetIconValue &&)
noexcept;
280 bool isEmpty()
const;
282 QString theme()
const;
283 void setTheme(
const QString &);
285 int themeEnum()
const;
286 void setThemeEnum(
int e);
288 PropertySheetPixmapValue pixmap(QIcon::Mode mode, QIcon::State state)
const;
289 void setPixmap(QIcon::Mode mode, QIcon::State state,
const PropertySheetPixmapValue &path);
292 uint compare(
const PropertySheetIconValue &other)
const;
293 void assign(
const PropertySheetIconValue &other, uint mask);
296 PropertySheetIconValue themed()
const;
297 PropertySheetIconValue unthemed()
const;
299 using ModeStateKey = std::pair<QIcon::Mode, QIcon::State>;
300 using ModeStateToPixmapMap = QMap<ModeStateKey, PropertySheetPixmapValue>;
302 const ModeStateToPixmapMap &paths()
const;
306 size_t qHash(
const PropertySheetIconValue &p, size_t seed)
noexcept;
307 friend size_t qHash(
const PropertySheetIconValue &p)
noexcept
308 {
return qHash(p, 0); }
310 bool comparesEqual(
const PropertySheetIconValue &lhs,
311 const PropertySheetIconValue &rhs)
noexcept;
312 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetIconValue)
314 QSharedDataPointer<PropertySheetIconValueData> m_data;
323 DesignerPixmapCache(QObject *parent =
nullptr);
324 QPixmap pixmap(
const PropertySheetPixmapValue &value)
const;
329 mutable QHash<PropertySheetPixmapValue, QPixmap> m_cache;
330 friend class FormWindowBase;
337 explicit DesignerIconCache(DesignerPixmapCache *pixmapCache, QObject *parent =
nullptr);
338 QIcon icon(
const PropertySheetIconValue &value)
const;
343 mutable QHash<PropertySheetIconValue, QIcon> m_cache;
344 DesignerPixmapCache *m_pixmapCache;
345 friend class FormWindowBase;
352 PropertySheetTranslatableData(
bool translatable =
true,
353 const QString &disambiguation = QString(),
354 const QString &comment = QString());
357 bool translatable()
const {
return m_translatable; }
358 void setTranslatable(
bool translatable) { m_translatable = translatable; }
359 QString disambiguation()
const {
return m_disambiguation; }
360 void setDisambiguation(
const QString &d) { m_disambiguation = d; }
361 QString comment()
const {
return m_comment; }
362 void setComment(
const QString &comment) { m_comment = comment; }
363 QString id()
const {
return m_id; }
364 void setId(
const QString &id) { m_id = id; }
367 friend bool comparesEqual(
const PropertySheetTranslatableData &lhs,
368 const PropertySheetTranslatableData &rhs)
noexcept
370 return lhs.m_translatable == rhs.m_translatable
371 && lhs.m_disambiguation == rhs.m_disambiguation
372 && lhs.m_comment == rhs.m_comment
373 && lhs.m_id == rhs.m_id;
375 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetTranslatableData)
378 QString m_disambiguation;
387 PropertySheetStringValue(
const QString &value = QString(),
bool translatable =
true,
388 const QString &disambiguation = QString(),
const QString &comment = QString());
390 QString value()
const;
391 void setValue(
const QString &value);
394 friend bool comparesEqual(
const PropertySheetStringValue &lhs,
395 const PropertySheetStringValue &rhs)
noexcept
397 const PropertySheetTranslatableData &upLhs = lhs;
398 const PropertySheetTranslatableData &upRhs = rhs;
399 return lhs.m_value == rhs.m_value && upLhs == upRhs;
401 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringValue)
410 PropertySheetStringListValue(
const QStringList &value = QStringList(),
411 bool translatable =
true,
412 const QString &disambiguation = QString(),
413 const QString &comment = QString());
415 QStringList value()
const;
416 void setValue(
const QStringList &value);
419 friend bool comparesEqual(
const PropertySheetStringListValue &lhs,
420 const PropertySheetStringListValue &rhs)
noexcept
422 const PropertySheetTranslatableData &upLhs = lhs;
423 const PropertySheetTranslatableData &upRhs = rhs;
424 return lhs.m_value == rhs.m_value && upLhs == upRhs;
426 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringListValue)
435 PropertySheetKeySequenceValue(
const QKeySequence &value = QKeySequence(),
436 bool translatable =
true,
437 const QString &disambiguation = QString(),
438 const QString &comment = QString());
439 PropertySheetKeySequenceValue(
const QKeySequence::StandardKey &standardKey,
440 bool translatable =
true,
441 const QString &disambiguation = QString(),
442 const QString &comment = QString());
444 QKeySequence value()
const;
445 void setValue(
const QKeySequence &value);
446 QKeySequence::StandardKey standardKey()
const;
447 void setStandardKey(
const QKeySequence::StandardKey &standardKey);
448 bool isStandardKey()
const;
451 friend bool comparesEqual(
const PropertySheetKeySequenceValue &lhs,
452 const PropertySheetKeySequenceValue &rhs)
noexcept
454 const PropertySheetTranslatableData &upLhs = lhs;
455 const PropertySheetTranslatableData &upRhs = rhs;
456 return lhs.m_value == rhs.m_value && lhs.m_standardKey == rhs.m_standardKey
459 Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetKeySequenceValue)
461 QKeySequence m_value;
462 QKeySequence::StandardKey m_standardKey;
472Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetFlagValue)
473Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetPixmapValue)
474Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetIconValue)
475Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringValue)
476Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetStringListValue)
477Q_DECLARE_METATYPE(qdesigner_internal::PropertySheetKeySequenceValue)
499 QByteArray& ba, QString &errorMessage);
505
506
517 const bool m_enabled;
522 QPalette::ColorRole colorRole);
528inline int valueOf(
const QVariant &value,
bool *ok =
nullptr)
530 if (value.canConvert<PropertySheetEnumValue>()) {
533 return qvariant_cast<PropertySheetEnumValue>(value).value;
535 if (value.canConvert<PropertySheetFlagValue>()) {
540 return value.toInt(ok);
545 QObject *obj = child;
546 while (obj !=
nullptr) {
556 if (! fw || ! widget)
559 if (widget == fw->mainContainer())
563 if (
auto *mw = qobject_cast<QMainWindow*>(fw->mainContainer()))
564 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(QtOhosQpa::enums::kit::ShareKit::systemShare::SelectionMode))
#define QDESIGNER_SHARED_EXPORT
DesignerMetaEnum metaEnum
DesignerMetaFlags metaFlags