2#include <QAbstractProxyModel>
4#include <QDialogButtonBox>
20inline std::ostream&
operator<<(std::ostream& os,
const QString& qs)
23 return os << qs.toUtf8().constData();
29inline QPoint
operator-(
const QPoint& pt,
const QSize& sz)
31 return {pt.x() - sz.width(), pt.y() - sz.height()};
37inline QPoint
operator+(
const QPoint& pt,
const QSize& sz)
39 return {pt.x() + sz.width(), pt.y() + sz.height()};
45inline QRect
operator+(
const QRect& rc,
const QSize& sz)
47 return {rc.topLeft(), rc.size() + sz};
53inline QRect
operator-(
const QRect& rc,
const QSize& sz)
55 return {rc.topLeft(), rc.size() - sz};
61inline QRect
operator+(
const QRect& rc,
const QPoint& pt)
63 return {rc.topLeft() + pt, rc.size()};
71 rc = {rc.topLeft() + pt, rc.size()};
78inline QRect
operator-(
const QRect& rc,
const QPoint& pt)
80 return {rc.topLeft() - pt, rc.size()};
88 rc = {rc.topLeft() - pt, rc.size()};
97 r.adjust(-sz, -sz, sz, sz);
106 return r.adjusted(-sz, -sz, sz, sz);
116 return {pt.x(), pt.y()};
126 return {pt.x(), pt.y()};
166 typedef QPair<QPalette::ColorRole, QColor> Pair;
182template<
typename T,
typename F>
185 static_assert(std::is_base_of_v<QObject, T>,
"Type T must be a QObject-derived class!");
186 return T::staticMetaObject.enumerator(T::staticMetaObject.indexOfEnumerator(QMetaEnum::fromType<F>().name()));
205template<
typename QObjectType,
typename FlagsType>
214 Iterator(
const QMetaEnum& metaEnum,
const FlagsType& flags,
int index)
224 return static_cast<EnumType>(metaEnum.value(index));
236 return index != other.index;
242 while (index < metaEnum.keyCount() && !flags.testFlag(
static_cast<EnumType>(metaEnum.value(index))))
258 return Iterator(metaEnum, flags, 0);
263 return Iterator(metaEnum, flags, metaEnum.keyCount());
282 const QWidget* widget,
const QString& sender_name,
const char* signal_name,
const QObject* receiver,
const char* method_name,
283 Qt::ConnectionType ct = Qt::AutoConnection
308static const char* enumToKey(
const T value)
310 return QMetaEnum::fromType<T>().valueToKey(value);
321static T keyToEnum(
const char* key,
bool* ok =
nullptr)
323 return static_cast<T
>(QMetaEnum::fromType<T>().keyToValue(key, ok));
332static const char* enumName()
334 return QMetaEnum::fromType<T>().enumName();
344static T keyToEnum(QString key)
346 return QMetaEnum::fromType<T>().keyToValue(key);
385 const auto count = treeView->model()->columnCount({}) - 1;
386 for (
int i = 0; i < count; i++)
388 treeView->resizeColumnToContents(i);
407 if (
auto m =
dynamic_cast<const T*
>(am))
409 return const_cast<T*
>(m);
412 if (
const auto apm =
dynamic_cast<const QAbstractProxyModel*
>(am))
414 if (
auto m =
dynamic_cast<T*
>(apm->sourceModel()))
416 return const_cast<T*
>(m);
498inline std::ostream&
operator<<(std::ostream& os,
const QRect& rect)
Definition qt_utils.h:212
bool operator!=(const Iterator &other) const
Definition qt_utils.h:234
Iterator(const QMetaEnum &metaEnum, const FlagsType &flags, int index)
Definition qt_utils.h:214
EnumType operator*() const
Definition qt_utils.h:222
Iterator & operator++()
Definition qt_utils.h:227
Wrapper class to iterate over the flags set.
Definition qt_utils.h:207
typename FlagsType::enum_type EnumType
Definition qt_utils.h:209
FlagsIterator(FlagsType flags)
Definition qt_utils.h:251
Iterator end() const
Definition qt_utils.h:261
Iterator begin() const
Definition qt_utils.h:256
Type to hold palette colors.
Definition qt_utils.h:151
PaletteColors(const QPalette &palette)
void setColors(const QPalette &palette)
QPalette getPalette() const
void styleFileDialog(QFileDialog &fd) const
#define _MISC_FUNC
Definition misc/global.h:39
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
_MISC_FUNC QModelIndex getSourceModelIndex(const QModelIndex &index)
Gets the source index in case a proxy model has been used.
_MISC_FUNC int indexFromComboBox(const QComboBox *comboBox, const QVariant &value, int default_index=-1)
Gets the index from the passed data value of the passed combo box widget.
_MISC_FUNC QPair< QLayout *, int > getTopLayoutAndIndex(const QObject *object)
Gets the top level QLayout and index of the passed object which can be a QLayout out or QWidget deriv...
_MISC_FUNC std::string trimRight(std::string s, const std::string &t=" ")
Trims a passed string right and returns it.
void resizeColumnsToContents(QTreeView *treeView)
Resizes all columns to content of a tree view except the last column.
Definition qt_utils.h:383
_MISC_FUNC QRect moveRectWithinRect(const QRect &outer, const QRect &inner)
Moves the inner in to the outer rectangle.
_MISC_FUNC QStringList getObjectNamePath(const QObject *object, bool use_rtti=false)
Gets all the parent names from the object's parent in a string list.
_MISC_FUNC bool isGuiApplication()
Checks if the running QCoreApplication is a GUI application.
_MISC_FUNC QPair< int, QFormLayout::ItemRole > getLayoutPosition(const QFormLayout *layout, QObject *target)
Gets the position (row, role) from the passed target object in te form-layout.
_MISC_FUNC std::string trim(std::string s, const std::string &t=" ")
Trims a passed string at both sides and returns it.
_MISC_FUNC int getLayoutIndex(const QBoxLayout *layout, QObject *target)
Gets the index from the passed target object in te box-layout.
_MISC_FUNC bool isValidFilePath(const QString &path)
Gets if the passed filepath is a valid name.
_MISC_FUNC void expandTreeView(QTreeView *tv, bool expand=true, const QModelIndex &index={})
Expands or collapses a tree view's items.
_MISC_FUNC void storeTreeViewState(QSettings &settings, QAnyStringView name, const QTreeView *tv, bool read)
Stores or restores column widths of a QTreeView.
_MISC_FUNC bool isValidDirectoryPath(const QString &path)
Gets if the passed directory path is a valid name.
_MISC_FUNC std::string trimLeft(std::string s, const std::string &t=" ")
Trims a passed string left and returns it.
_MISC_FUNC QMetaObject::Connection connectByName(const QWidget *widget, const QString &sender_name, const char *signal_name, const QObject *receiver, const char *method_name, Qt::ConnectionType ct=Qt::AutoConnection)
Connects signals by name of sender and name of signal.
_MISC_FUNC void dumpObjectProperties(const QObject *obj)
Dumps all the object properties in qDebug().
_MISC_FUNC void storeWindowState(QSettings &settings, QAnyStringView name, QWidget *widget, bool read)
Stores or restores the window position and size from the settings file onto the passed widget.
T * getSourceModel(const QAbstractItemModel *am)
Gets the model type pointer from the passed abstract model pointer.
Definition qt_utils.h:404
_MISC_FUNC QLayout * getWidgetLayout(const QWidget *widget)
Gets the layout containing the passed widget.
QMetaEnum flagsMetaEnum()
Gets the QMetaEnum from a given in a QObject embedded Qt type.
Definition qt_utils.h:183
std::string toString(T value, int digits=0)
The function converts number to a minimal length. It produces 'digits' significant digits in either p...
QRect operator+=(QRect &rc, const QPoint &pt)
Allows adjusting the QRect position using a QPoint.
Definition qt_utils.h:69
QSize asQSize(const QPoint &pt)
Gets the passed Qt point as a Qt size class.
Definition qt_utils.h:114
QPoint operator+(const QPoint &pt, const QSize &sz)
Allows moving a QPoint using a QSize.
Definition qt_utils.h:37
QRect & inflate(QRect &r, int sz)
Inflates the passed rect on all sides using an integer.
Definition qt_utils.h:95
std::ostream & operator<<(std::ostream &os, const QString &qs)
Operator stream a QString instance to ans std ostream.
Definition qt_utils.h:20
constexpr QRect inflated(const QRect &r, int sz)
Inflates a copy the rectangle an integer and returns it.
Definition qt_utils.h:104
QPoint operator-(const QPoint &pt, const QSize &sz)
Allows moving a QPoint using a QSize.
Definition qt_utils.h:29
QSizeF asQSizeF(const QPointF &pt)
Gets the passed Qt point as a Qt size class.
Definition qt_utils.h:124
QRect operator-=(QRect &rc, const QPoint &pt)
Allows adjusting the QRect position using a QPoint.
Definition qt_utils.h:86