Quellcode durchsuchen

Add form layouts

Neal Wilson vor 5 Jahren
Ursprung
Commit
619b5d1653
Signiert von: Neal Wilson <neal@typica.us> GPG-Schlüssel-ID: 2A0BDDE701E66EB9
1 geänderte Dateien mit 49 neuen und 0 gelöschten Zeilen
  1. 49
    0
      src/typica.w

+ 49
- 0
src/typica.w Datei anzeigen

@@ -4682,6 +4682,8 @@ void populateWidget(QDomElement element, QStack<QWidget *> *widgetStack,@|
4682 4682
                     QStack<QLayout *> *layoutStack);
4683 4683
 void populateStackedLayout(QDomElement element, QStack<QWidget *> *widgetStack,
4684 4684
                            QStack<QLayout *> *layoutStack);
4685
+void populateFormLayout(QDomElement element, QStack<QWidget *> *widgetStack,@|
4686
+                        QStack<QLayout *> *layoutStack);
4685 4687
 void addTemperatureDisplayToSplitter(QDomElement element,@|
4686 4688
                                      QStack<QWidget *> *widgetStack,
4687 4689
                                      QStack<QLayout *> *layoutStack);
@@ -5026,6 +5028,12 @@ else if(layoutType == "stack")
5026 5028
     layoutStack->push(layout);
5027 5029
     populateStackedLayout(element, widgetStack, layoutStack);
5028 5030
 }
5031
+else if(layoutType == "form")
5032
+{
5033
+    layout = new QFormLayout;
5034
+    layoutStack->push(layout);
5035
+    populateFormLayout(element, widgetStack, layoutStack);
5036
+}
5029 5037
 if(element.hasAttribute("id"))
5030 5038
 {
5031 5039
     layout->setObjectName(element.attribute("id"));
@@ -5040,6 +5048,47 @@ if(element.hasAttribute("margin"))
5040 5048
     layout->setContentsMargins(m, m, m, m);
5041 5049
 }
5042 5050
 
5051
+@ Any direct child of a form layout must be a {\tt <row>} element to specify
5052
+the label for the given row. The field for the given row will always be a
5053
+|QVBoxLayout| containing whatever is specified by children of the {\tt <row>}.
5054
+
5055
+@<Functions for scripting@>=
5056
+void populateFormLayout(QDomElement element, QStack<QWidget *> *widgetStack,
5057
+                        QStack<QLayout *> *layoutStack)
5058
+{
5059
+    QDomNodeList children = element.childNodes();
5060
+    QFormLayout *layout = qobject_cast<QFormLayout *>(layoutStack->top());
5061
+    for(int i = 0; i < children.count(); i++)
5062
+    {
5063
+        QDomNode current;
5064
+        QDomElement currentElement;
5065
+        current = children.at(i);
5066
+        if(current.isElement())
5067
+        {
5068
+            currentElement = current.toElement();
5069
+            if(currentElement.tagName() == "row")
5070
+            {
5071
+                QString label = QString();
5072
+                if(currentElement.hasAttribute("label"))
5073
+                {
5074
+                    label = currentElement.attribute("label");
5075
+                }
5076
+                QVBoxLayout *childLayout = new QVBoxLayout;
5077
+                layoutStack->push(childLayout);
5078
+                populateBoxLayout(currentElement, widgetStack, layoutStack);
5079
+                if(label.isEmpty())
5080
+                {
5081
+                    layout->addRow(childLayout);
5082
+                }
5083
+                else
5084
+                {
5085
+                    layout->addRow(label, childLayout);
5086
+                }
5087
+            }
5088
+        }
5089
+    }
5090
+}
5091
+
5043 5092
 @ Stacked layouts are a bit different from the other types. A stacked layout has
5044 5093
 an arbitrary number of {\tt <page>} children which are just a |QWidget| which
5045 5094
 can have the same child elements as {\tt <widget>} elements elsewhere. Only the

Laden…
Abbrechen
Speichern