2#include <QAbstractProxyModel>
19inline std::ostream&
operator<<(std::ostream& os,
const QString& qs)
22 return os << qs.toUtf8().constData();
28inline QPoint
operator-(
const QPoint& pt,
const QSize& sz)
30 return {pt.x() - sz.width(), pt.y() - sz.height()};
36inline QPoint
operator+(
const QPoint& pt,
const QSize& sz)
38 return {pt.x() + sz.width(), pt.y() + sz.height()};
44inline QRect
operator+(
const QRect& rc,
const QSize& sz)
46 return {rc.topLeft(), rc.size() + sz};
52inline QRect
operator-(
const QRect& rc,
const QSize& sz)
54 return {rc.topLeft(), rc.size() - sz};
60inline QRect
operator+(
const QRect& rc,
const QPoint& pt)
62 return {rc.topLeft() + pt, rc.size()};
70 rc = {rc.topLeft() + pt, rc.size()};
77inline QRect
operator-(
const QRect& rc,
const QPoint& pt)
79 return {rc.topLeft() - pt, rc.size()};
87 rc = {rc.topLeft() - pt, rc.size()};
96 r.adjust(-sz, -sz, sz, sz);
105 return r.adjusted(-sz, -sz, sz, sz);
115 return {pt.x(), pt.y()};
125 return {pt.x(), pt.y()};
165 typedef QPair<QPalette::ColorRole, QColor> Pair;
181template<
typename T,
typename F>
184 static_assert(std::is_base_of_v<QObject, T>,
"Type T must be a QObject-derived class!");
185 return T::staticMetaObject.enumerator(T::staticMetaObject.indexOfEnumerator(QMetaEnum::fromType<F>().name()));
204template<
typename QObjectType,
typename FlagsType>
213 Iterator(
const QMetaEnum& metaEnum,
const FlagsType& flags,
int index)
223 return static_cast<EnumType>(metaEnum.value(index));
235 return index != other.index;
241 while (index < metaEnum.keyCount() && !flags.testFlag(
static_cast<EnumType>(metaEnum.value(index))))
257 return Iterator(metaEnum, flags, 0);
262 return Iterator(metaEnum, flags, metaEnum.keyCount());
281 const QWidget* widget,
const QString& sender_name,
const char* signal_name,
const QObject* receiver,
const char* method_name,
282 Qt::ConnectionType ct = Qt::AutoConnection
307static const char* enumToKey(
const T value)
309 return QMetaEnum::fromType<T>().valueToKey(value);
320static T keyToEnum(
const char* key,
bool* ok =
nullptr)
322 return static_cast<T
>(QMetaEnum::fromType<T>().keyToValue(key, ok));
331static const char* enumName()
333 return QMetaEnum::fromType<T>().enumName();
343static T keyToEnum(
const QString& key)
345 return QMetaEnum::fromType<T>().keyToValue(key);
393 const auto count = treeView->model()->columnCount({}) - 1;
394 for (
int i = 0; i < count; i++)
396 treeView->resizeColumnToContents(i);
415 if (
auto m =
dynamic_cast<const T*
>(am))
417 return const_cast<T*
>(m);
420 if (
const auto apm =
dynamic_cast<const QAbstractProxyModel*
>(am))
422 if (
auto m =
dynamic_cast<T*
>(apm->sourceModel()))
424 return const_cast<T*
>(m);
517inline std::ostream&
operator<<(std::ostream& os,
const QRect& rect)
Definition qt_utils.h:211
bool operator!=(const Iterator &other) const
Definition qt_utils.h:233
Iterator(const QMetaEnum &metaEnum, const FlagsType &flags, int index)
Definition qt_utils.h:213
EnumType operator*() const
Definition qt_utils.h:221
Iterator & operator++()
Definition qt_utils.h:226
typename FlagsType::enum_type EnumType
Definition qt_utils.h:208
FlagsIterator(FlagsType flags)
Definition qt_utils.h:250
Iterator end() const
Definition qt_utils.h:260
Iterator begin() const
Definition qt_utils.h:255
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 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 deri...
_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 the content of a tree view except the last column.
Definition qt_utils.h:391
_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 the 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 the box-layout.
_MISC_FUNC bool isValidFilePath(const QString &path)
Gets if the passed filepath is a valid name.
_MISC_FUNC QModelIndex modelIndexFromString(const QString &str, const QAbstractItemModel *model)
Converts a path back into a QModelIndex instance.
_MISC_FUNC void expandTreeView(QTreeView *tv, bool expand=true, const QModelIndex &index={})
Expands or collapses a tree view's items.
_MISC_FUNC int indexFromComboBoxByText(const QComboBox *comboBox, const QString &value, int default_index=-1)
Gets the index from the passed item text of the passed combo box widget.
_MISC_FUNC QString modelIndexToString(const QModelIndex &index)
Converts a QModelIndex instance to a QString path.
_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 int indexFromComboBoxByData(const QComboBox *comboBox, const QVariant &value, int default_index=-1)
Gets the index from the passed data value of the passed combo box widget.
T * getSourceModel(const QAbstractItemModel *am)
Gets the model type pointer from the passed abstract model pointer.
Definition qt_utils.h:412
_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:182
std::string toString(T value, int digits=0)
The function converts number to a minimal length. It produces 'digits' significant digits in either p...
void _MISC_FUNC dimPalette(QPalette &palette, float factor)
Dims the 'Disabled' color group using the 'Normal' group and blend factor.
QColor _MISC_FUNC blendToward(const QColor &from, const QColor &to, float factor)
Blends a color towards another color using a factor.
QRect operator+=(QRect &rc, const QPoint &pt)
Allows adjusting the QRect position using a QPoint.
Definition qt_utils.h:68
QSize asQSize(const QPoint &pt)
Gets the passed Qt point as a Qt size class.
Definition qt_utils.h:113
QPoint operator+(const QPoint &pt, const QSize &sz)
Allows moving a QPoint using a QSize.
Definition qt_utils.h:36
QRect & inflate(QRect &r, int sz)
Inflates the passed rect on all sides using an integer.
Definition qt_utils.h:94
std::ostream & operator<<(std::ostream &os, const QString &qs)
Operator stream a QString instance to ans std ostream.
Definition qt_utils.h:19
constexpr QRect inflated(const QRect &r, int sz)
Inflates a copy the rectangle an integer and returns it.
Definition qt_utils.h:103
QPoint operator-(const QPoint &pt, const QSize &sz)
Allows moving a QPoint using a QSize.
Definition qt_utils.h:28
QSizeF asQSizeF(const QPointF &pt)
Gets the passed Qt point as a Qt size class.
Definition qt_utils.h:123
QRect operator-=(QRect &rc, const QPoint &pt)
Allows adjusting the QRect position using a QPoint.
Definition qt_utils.h:85