From 7ae8c53a1611a239ea0c9dec07fd721d82f40d32 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 23 Mar 2016 16:16:38 +0100 Subject: [PATCH] Numeric datatypes auto aligned to right in AutoTableModel based grids. Swithced QLineEdit to QDoubleSpinBox for better number formating in commodityform.ui and accserviceform.ui. Fixed build order. --- commodity/commodityform.ui | 22 +++++++++++++++++++--- core/autotablemodel.h | 23 +++++++++++++++++++---- prodejna.pro | 1 + services/accserviceform.ui | 14 ++++++++++---- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/commodity/commodityform.ui b/commodity/commodityform.ui index e730f81..86945ae 100644 --- a/commodity/commodityform.ui +++ b/commodity/commodityform.ui @@ -72,9 +72,6 @@ - - - @@ -84,8 +81,27 @@ + + + + QAbstractSpinBox::NoButtons + + + 999999999.990000009536743 + + + + + name + shortName + code + type + price + vat + count + diff --git a/core/autotablemodel.h b/core/autotablemodel.h index ca210bc..047d0f0 100644 --- a/core/autotablemodel.h +++ b/core/autotablemodel.h @@ -50,12 +50,13 @@ public: QVariant data(const QModelIndex &index, int role) const { + QSharedPointer entity = m_list.at(index.row()); + QObject *rawEntity = (QObject*)entity.data(); + + QVariant dispData = rawEntity->property(rawEntity->metaObject()->property(index.column() + 1).name()); + if (role == Qt::DisplayRole) { - QSharedPointer entity = m_list.at(index.row()); - QObject *rawEntity = (QObject*)entity.data(); - - QVariant dispData = rawEntity->property(rawEntity->metaObject()->property(index.column() + 1).name()); if (dispData.canConvert() && qobject_cast(dispData.value())) { return qobject_cast(dispData.value())->toString(); @@ -68,6 +69,20 @@ public: return dispData; } + if (role == Qt::TextAlignmentRole) + { + if (dispData.canConvert() + || dispData.type() == QVariant::Date + || dispData.type() == QVariant::Time + || dispData.type() == QVariant::DateTime + || dispData.type() == QVariant::Int + || dispData.type() == QVariant::Double) + { + return Qt::AlignRight; + } + + return Qt::AlignLeft; + } return QVariant::Invalid; } diff --git a/prodejna.pro b/prodejna.pro index f297667..b8fd0cc 100644 --- a/prodejna.pro +++ b/prodejna.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs +CONFIG += ordered SUBDIRS += \ qdecimal \ diff --git a/services/accserviceform.ui b/services/accserviceform.ui index 75db442..fa819a6 100644 --- a/services/accserviceform.ui +++ b/services/accserviceform.ui @@ -31,9 +31,6 @@ - - - @@ -78,12 +75,21 @@ + + + + QAbstractSpinBox::NoButtons + + + 999999999.990000009536743 + + + accServiceName accServiceCode - price serviceType vatType salePossible