2#include <QAbstractProxyModel>
18inline std::ostream&
operator<<(std::ostream& os,
const QString& qs)
20 return os << qs.toStdString();
26inline QPoint
operator-(
const QPoint& pt,
const QSize& sz)
28 return {pt.x() - sz.width(), pt.y() - sz.height()};
34inline QPoint
operator+(
const QPoint& pt,
const QSize& sz)
36 return {pt.x() + sz.width(), pt.y() + sz.height()};
42inline QRect
operator+(
const QRect& rc,
const QSize& sz)
44 return {rc.topLeft(), rc.size() + sz};
50inline QRect
operator-(
const QRect& rc,
const QSize& sz)
52 return {rc.topLeft(), rc.size() - sz};
58inline QRect
operator+(
const QRect& rc,
const QPoint& pt)
60 return {rc.topLeft() + pt, rc.size()};
68 rc = {rc.topLeft() + pt, rc.size()};
75inline QRect
operator-(
const QRect& rc,
const QPoint& pt)
77 return {rc.topLeft() - pt, rc.size()};
85 rc = {rc.topLeft() - pt, rc.size()};
94 r.adjust(-sz, -sz, sz, sz);
103 return r.adjusted(-sz, -sz, sz, sz);
113 return {pt.x(), pt.y()};
123 return {pt.x(), pt.y()};
163 typedef QPair<QPalette::ColorRole, QColor> Pair;
178 const QWidget* widget,
const QString& sender_name,
const char* signal_name,
const QObject* receiver,
const char* method_name,
179 Qt::ConnectionType ct = Qt::AutoConnection
205static const char* enumToKey(
const T value)
207 return QMetaEnum::fromType<T>().valueToKey(value);
218static T keyToEnum(
const char* key,
bool* ok =
nullptr)
220 return static_cast<T
>(QMetaEnum::fromType<T>().keyToValue(key, ok));
229static const char* enumName()
231 return QMetaEnum::fromType<T>().enumName();
241static T keyToEnum(QString key)
243 return QMetaEnum::fromType<T>().keyToValue(key);
277 const auto count = treeView->model()->columnCount({}) - 1;
278 for (
int i = 0; i < count; i++)
280 treeView->resizeColumnToContents(i);
299 if (
auto m =
dynamic_cast<const T*
>(am))
301 return const_cast<T*
>(m);
304 if (
const auto apm =
dynamic_cast<const QAbstractProxyModel*
>(am))
306 if (
auto m =
dynamic_cast<T*
>(apm->sourceModel()))
308 return const_cast<T*
>(m);
338inline std::ostream&
operator<<(std::ostream& os,
const QRect& rect)
Type to hold palette colors.
Definition qt_utils.h:148
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.
void resizeColumnsToContents(QTreeView *treeView)
Resizes all columns to content of a tree view except the last column.
Definition qt_utils.h:275
_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 int getLayoutIndex(const QBoxLayout *layout, QObject *target)
Gets the index from the passed target object in te box-layout.
_MISC_FUNC void expandTreeView(QTreeView *tv, bool expand=true, const QModelIndex &index={})
Expands or collapses a tree view's items.
_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().
T * getSourceModel(const QAbstractItemModel *am)
Gets the model type pointer from the passed abstract model pointer.
Definition qt_utils.h:296
_MISC_FUNC QLayout * getWidgetLayout(const QWidget *widget)
Gets the layout containing the passed widget.
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:66
QSize asQSize(const QPoint &pt)
Gets the passed Qt point as a Qt size class.
Definition qt_utils.h:111
QPoint operator+(const QPoint &pt, const QSize &sz)
Allows moving a QPoint using a QSize.
Definition qt_utils.h:34
QRect & inflate(QRect &r, int sz)
Inflates the passed rect on all sides using an integer.
Definition qt_utils.h:92
std::ostream & operator<<(std::ostream &os, const QString &qs)
Operator stream a QString instance to ans std ostream.
Definition qt_utils.h:18
constexpr QRect inflated(const QRect &r, int sz)
Inflates a copy the rectangle an integer and returns it.
Definition qt_utils.h:101
QPoint operator-(const QPoint &pt, const QSize &sz)
Allows moving a QPoint using a QSize.
Definition qt_utils.h:26
QSizeF asQSizeF(const QPointF &pt)
Gets the passed Qt point as a Qt size class.
Definition qt_utils.h:121
QRect operator-=(QRect &rc, const QPoint &pt)
Allows adjusting the QRect position using a QPoint.
Definition qt_utils.h:83