qformlayout.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QFORMLAYOUT_H
  40. #define QFORMLAYOUT_H
  41. #include <QtWidgets/QLayout>
  42. QT_BEGIN_NAMESPACE
  43. class QFormLayoutPrivate;
  44. class Q_WIDGETS_EXPORT QFormLayout : public QLayout
  45. {
  46. Q_OBJECT
  47. Q_DECLARE_PRIVATE(QFormLayout)
  48. Q_PROPERTY(FieldGrowthPolicy fieldGrowthPolicy READ fieldGrowthPolicy WRITE setFieldGrowthPolicy RESET resetFieldGrowthPolicy)
  49. Q_PROPERTY(RowWrapPolicy rowWrapPolicy READ rowWrapPolicy WRITE setRowWrapPolicy RESET resetRowWrapPolicy)
  50. Q_PROPERTY(Qt::Alignment labelAlignment READ labelAlignment WRITE setLabelAlignment RESET resetLabelAlignment)
  51. Q_PROPERTY(Qt::Alignment formAlignment READ formAlignment WRITE setFormAlignment RESET resetFormAlignment)
  52. Q_PROPERTY(int horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
  53. Q_PROPERTY(int verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
  54. public:
  55. enum FieldGrowthPolicy {
  56. FieldsStayAtSizeHint,
  57. ExpandingFieldsGrow,
  58. AllNonFixedFieldsGrow
  59. };
  60. Q_ENUM(FieldGrowthPolicy)
  61. enum RowWrapPolicy {
  62. DontWrapRows,
  63. WrapLongRows,
  64. WrapAllRows
  65. };
  66. Q_ENUM(RowWrapPolicy)
  67. enum ItemRole {
  68. LabelRole = 0,
  69. FieldRole = 1,
  70. SpanningRole = 2
  71. };
  72. Q_ENUM(ItemRole)
  73. explicit QFormLayout(QWidget *parent = Q_NULLPTR);
  74. ~QFormLayout();
  75. void setFieldGrowthPolicy(FieldGrowthPolicy policy);
  76. FieldGrowthPolicy fieldGrowthPolicy() const;
  77. void setRowWrapPolicy(RowWrapPolicy policy);
  78. RowWrapPolicy rowWrapPolicy() const;
  79. void setLabelAlignment(Qt::Alignment alignment);
  80. Qt::Alignment labelAlignment() const;
  81. void setFormAlignment(Qt::Alignment alignment);
  82. Qt::Alignment formAlignment() const;
  83. void setHorizontalSpacing(int spacing);
  84. int horizontalSpacing() const;
  85. void setVerticalSpacing(int spacing);
  86. int verticalSpacing() const;
  87. int spacing() const;
  88. void setSpacing(int);
  89. void addRow(QWidget *label, QWidget *field);
  90. void addRow(QWidget *label, QLayout *field);
  91. void addRow(const QString &labelText, QWidget *field);
  92. void addRow(const QString &labelText, QLayout *field);
  93. void addRow(QWidget *widget);
  94. void addRow(QLayout *layout);
  95. void insertRow(int row, QWidget *label, QWidget *field);
  96. void insertRow(int row, QWidget *label, QLayout *field);
  97. void insertRow(int row, const QString &labelText, QWidget *field);
  98. void insertRow(int row, const QString &labelText, QLayout *field);
  99. void insertRow(int row, QWidget *widget);
  100. void insertRow(int row, QLayout *layout);
  101. void setItem(int row, ItemRole role, QLayoutItem *item);
  102. void setWidget(int row, ItemRole role, QWidget *widget);
  103. void setLayout(int row, ItemRole role, QLayout *layout);
  104. QLayoutItem *itemAt(int row, ItemRole role) const;
  105. void getItemPosition(int index, int *rowPtr, ItemRole *rolePtr) const;
  106. void getWidgetPosition(QWidget *widget, int *rowPtr, ItemRole *rolePtr) const;
  107. void getLayoutPosition(QLayout *layout, int *rowPtr, ItemRole *rolePtr) const;
  108. QWidget *labelForField(QWidget *field) const;
  109. QWidget *labelForField(QLayout *field) const;
  110. // reimplemented from QLayout
  111. void addItem(QLayoutItem *item) Q_DECL_OVERRIDE;
  112. QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE;
  113. QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE;
  114. void setGeometry(const QRect &rect) Q_DECL_OVERRIDE;
  115. QSize minimumSize() const Q_DECL_OVERRIDE;
  116. QSize sizeHint() const Q_DECL_OVERRIDE;
  117. void invalidate() Q_DECL_OVERRIDE;
  118. bool hasHeightForWidth() const Q_DECL_OVERRIDE;
  119. int heightForWidth(int width) const Q_DECL_OVERRIDE;
  120. Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
  121. int count() const Q_DECL_OVERRIDE;
  122. int rowCount() const;
  123. #if 0
  124. void dump() const;
  125. #endif
  126. private:
  127. void resetFieldGrowthPolicy();
  128. void resetRowWrapPolicy();
  129. void resetLabelAlignment();
  130. void resetFormAlignment();
  131. };
  132. QT_END_NAMESPACE
  133. #endif