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.
print
Josef Rokos 9 years ago
parent 96685d2bed
commit 7ae8c53a16

@ -72,9 +72,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1">
<widget class="QLineEdit" name="price"/>
</item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QLineEdit" name="count"/> <widget class="QLineEdit" name="count"/>
</item> </item>
@ -84,8 +81,27 @@
<item row="5" column="1"> <item row="5" column="1">
<widget class="QComboBox" name="vat"/> <widget class="QComboBox" name="vat"/>
</item> </item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="price">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<double>999999999.990000009536743</double>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>name</tabstop>
<tabstop>shortName</tabstop>
<tabstop>code</tabstop>
<tabstop>type</tabstop>
<tabstop>price</tabstop>
<tabstop>vat</tabstop>
<tabstop>count</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

@ -50,12 +50,13 @@ public:
QVariant data(const QModelIndex &index, int role) const QVariant data(const QModelIndex &index, int role) const
{ {
QSharedPointer<T> 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) if (role == Qt::DisplayRole)
{ {
QSharedPointer<T> 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*>() && qobject_cast<ComboItem*>(dispData.value<QObject*>())) if (dispData.canConvert<QObject*>() && qobject_cast<ComboItem*>(dispData.value<QObject*>()))
{ {
return qobject_cast<ComboItem*>(dispData.value<QObject*>())->toString(); return qobject_cast<ComboItem*>(dispData.value<QObject*>())->toString();
@ -68,6 +69,20 @@ public:
return dispData; return dispData;
} }
if (role == Qt::TextAlignmentRole)
{
if (dispData.canConvert<QDecDouble>()
|| 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; return QVariant::Invalid;
} }

@ -1,4 +1,5 @@
TEMPLATE = subdirs TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += \ SUBDIRS += \
qdecimal \ qdecimal \

@ -31,9 +31,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QLineEdit" name="price"/>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
@ -78,12 +75,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="price">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<double>999999999.990000009536743</double>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>accServiceName</tabstop> <tabstop>accServiceName</tabstop>
<tabstop>accServiceCode</tabstop> <tabstop>accServiceCode</tabstop>
<tabstop>price</tabstop>
<tabstop>serviceType</tabstop> <tabstop>serviceType</tabstop>
<tabstop>vatType</tabstop> <tabstop>vatType</tabstop>
<tabstop>salePossible</tabstop> <tabstop>salePossible</tabstop>

Loading…
Cancel
Save