Browse Source

Disallow entry of negative quantities of green coffee in new batch window

Neal Wilson 5 years ago
parent
commit
a56c5cfb29
Signed by: neal <neal@typica.us> GPG Key ID: D6F25C90DD5819DF
2 changed files with 33 additions and 8 deletions
  1. 1
    1
      config/Windows/newbatch.xml
  2. 32
    7
      src/typica.w

+ 1
- 1
config/Windows/newbatch.xml View File

48
                                 <label>Green Coffee:</label>
48
                                 <label>Green Coffee:</label>
49
                                 <sqltablearray columns="3" id="greens">
49
                                 <sqltablearray columns="3" id="greens">
50
                                     <column name="Coffee" delegate="sql" showdata="true" null="true" nulltext="Delete" nulldata="delete" data="0" display="1">SELECT id, name FROM coffees WHERE quantity &lt;&gt; 0 ORDER BY name</column>
50
                                     <column name="Coffee" delegate="sql" showdata="true" null="true" nulltext="Delete" nulldata="delete" data="0" display="1">SELECT id, name FROM coffees WHERE quantity &lt;&gt; 0 ORDER BY name</column>
51
-                                    <column name="Weight" delegate="numeric" />
51
+                                    <column name="Weight" delegate="positivenumeric" />
52
                                     <column name="Remaining" />
52
                                     <column name="Remaining" />
53
                                 </sqltablearray>
53
                                 </sqltablearray>
54
                                 <layout type="horizontal">
54
                                 <layout type="horizontal">

+ 32
- 7
src/typica.w View File

5984
 {
5984
 {
5985
     @<Assign numeric column delegate@>@;
5985
     @<Assign numeric column delegate@>@;
5986
 }
5986
 }
5987
+else if(currentElement.attribute("delegate") == "positivenumeric")
5988
+{
5989
+	@<Assign positive numeric column delegate@>@;
5990
+}
5987
 
5991
 
5988
 @ When using a |SaltModel|, there are times where the array values being
5992
 @ When using a |SaltModel|, there are times where the array values being
5989
 inserted are identification numbers representing some record that already exists
5993
 inserted are identification numbers representing some record that already exists
6028
 delegate->setWidget(widget);
6032
 delegate->setWidget(widget);
6029
 view->setItemDelegateForColumn(currentColumn, delegate);
6033
 view->setItemDelegateForColumn(currentColumn, delegate);
6030
 
6034
 
6031
-@ Another common use is allowing numeric values. At present this only
6032
-restricts input to numbers, however it may be useful to provide other options
6033
-such as restricting the range of allowed values in the future.
6035
+@ Another common use is allowing numeric values.
6034
 
6036
 
6035
 @<Assign numeric column delegate@>=
6037
 @<Assign numeric column delegate@>=
6036
 NumericDelegate *delegate = new NumericDelegate;
6038
 NumericDelegate *delegate = new NumericDelegate;
6037
 view->setItemDelegateForColumn(currentColumn, delegate);
6039
 view->setItemDelegateForColumn(currentColumn, delegate);
6038
 
6040
 
6041
+@ It is also possible to restrict allowed numeric values to non-negative
6042
+values.
6043
+
6044
+@<Assign positive numeric column delegate@>=
6045
+NumericDelegate *delegate = new NumericDelegate(true);
6046
+view->setItemDelegateForColumn(currentColumn, delegate);
6047
+
6039
 @ The |NumericDelegate| will only set the display value to a number, but it
6048
 @ The |NumericDelegate| will only set the display value to a number, but it
6040
 will perform mathematical calculations that are entered into the editor as
6049
 will perform mathematical calculations that are entered into the editor as
6041
 well. This allows a person to type something like $13.26+5.06$ with the result
6050
 well. This allows a person to type something like $13.26+5.06$ with the result
6046
 {
6055
 {
6047
     @[Q_OBJECT@]@;
6056
     @[Q_OBJECT@]@;
6048
     public:@/
6057
     public:@/
6049
-        NumericDelegate(QObject *parent = NULL);
6058
+        NumericDelegate(bool positiveOnly = false, QObject *parent = NULL);
6050
         QWidget *createEditor(QWidget *parent,
6059
         QWidget *createEditor(QWidget *parent,
6051
                               const QStyleOptionViewItem &option,@|
6060
                               const QStyleOptionViewItem &option,@|
6052
                               const QModelIndex &index) const;
6061
                               const QModelIndex &index) const;
6056
         void updateEditorGeometry(QWidget *editor,
6065
         void updateEditorGeometry(QWidget *editor,
6057
                                   const QStyleOptionViewItem &option,@|
6066
                                   const QStyleOptionViewItem &option,@|
6058
                                   const QModelIndex &index) const;
6067
                                   const QModelIndex &index) const;
6068
+	private:
6069
+		bool m_positiveOnly;
6059
 };
6070
 };
6060
 
6071
 
6061
 @ There is nothing special about the constructor.
6072
 @ There is nothing special about the constructor.
6062
 
6073
 
6063
 @<NumericDelegate implementation@>=
6074
 @<NumericDelegate implementation@>=
6064
-NumericDelegate::NumericDelegate(QObject *parent) :
6065
-    QItemDelegate(parent)
6075
+NumericDelegate::NumericDelegate(bool positiveOnly, QObject *parent) :
6076
+    QItemDelegate(parent), m_positiveOnly(positiveOnly)
6066
 {
6077
 {
6067
     /* Nothing needs to be done here. */
6078
     /* Nothing needs to be done here. */
6068
 }
6079
 }
6099
     QScriptValue result = engine->evaluate(line->text());
6110
     QScriptValue result = engine->evaluate(line->text());
6100
     if(result.isNumber())
6111
     if(result.isNumber())
6101
     {
6112
     {
6102
-        model->setData(index, result.toVariant(), Qt::DisplayRole);
6113
+		if(m_positiveOnly)
6114
+		{
6115
+			if(result.toNumber() < 0)
6116
+			{
6117
+				model->setData(index, QVariant(), Qt::DisplayRole);
6118
+			}
6119
+			else
6120
+			{
6121
+				model->setData(index, result.toVariant(), Qt::DisplayRole);
6122
+			}
6123
+		}
6124
+		else
6125
+		{
6126
+			model->setData(index, result.toVariant(), Qt::DisplayRole);
6127
+		}
6103
     }
6128
     }
6104
     else
6129
     else
6105
     {
6130
     {

Loading…
Cancel
Save