KDb

KDbTableViewColumn.h
1 /* This file is part of the KDE project
2  Copyright (C) 2002 Lucijan Busch <[email protected]>
3  Copyright (C) 2003 Daniel Molkentin <[email protected]>
4  Copyright (C) 2003-2017 JarosÅ‚aw Staniek <[email protected]>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this program; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20 
21  Original Author: Till Busch <[email protected]>
22  Original Project: buX (www.bux.at)
23 */
24 
25 #ifndef KDB_TABLEVIEWCOLUMN_H
26 #define KDB_TABLEVIEWCOLUMN_H
27 
28 #include "kdb_export.h"
29 
30 #include "KDbField.h"
31 
32 class KDbQueryColumnInfo;
33 class KDbQuerySchema;
34 class KDbTableViewColumn;
35 class KDbTableViewData;
36 class KDbValidator;
37 
38 //! Definition of a single column for table view.
39 /*! @todo improve API */
40 class KDB_EXPORT KDbTableViewColumn
41 {
42 public:
43  /*! Specifies if the associated KDbField object is owned by the column so it will be
44  automatically destroyed when needed by this column. */
45  enum class FieldIsOwned {
46  Yes,
47  No
48  };
49 
50  /*! Not db-aware ctor. if @a isOwned is Yes, the field @a will be owned by this column so it will be
51  automatically destroyed when needed by this column. */
52  explicit KDbTableViewColumn(KDbField *f, FieldIsOwned isOwned = FieldIsOwned::No);
53 
54  /*! Not db-aware, convenience ctor, like above. The field is created using specified parameters that are
55  equal to these accepted by KDbField ctor. The column will be the owner
56  of this automatically generated field.
57  */
58  KDbTableViewColumn(const QString &name, KDbField::Type ctype,
59  KDbField::Constraints cconst = KDbField::NoConstraints,
60  KDbField::Options options = KDbField::NoOptions,
61  int maxLength = 0, int precision = 0,
62  QVariant defaultValue = QVariant(),
63  const QString &caption = QString(),
64  const QString &description = QString());
65 
66  /*! Not db-aware, convenience ctor, simplified version of the above. */
67  KDbTableViewColumn(const QString &name, KDbField::Type ctype, const QString &caption,
68  const QString &description = QString());
69 
70  //! Db-aware version.
71  KDbTableViewColumn(const KDbQuerySchema &query, KDbQueryColumnInfo *aColumnInfo,
72  KDbQueryColumnInfo *aVisibleLookupColumnInfo = nullptr);
73 
74  virtual ~KDbTableViewColumn();
75 
76  virtual bool acceptsFirstChar(const QChar &ch) const;
77 
78  /*! @return true if the column is read-only
79  For db-aware column this can depend on whether the column
80  is in parent table of this query. @see setReadOnly() */
81  bool isReadOnly() const;
82 
83  //! forces readOnly flag to be set to @a ro
84  //! @todo synchronize this with table view:
85  void setReadOnly(bool ro);
86 
87  //! Column visibility. By default column is visible.
88  bool isVisible() const;
89 
90  //! Changes column visibility.
91  //! KDbTableViewData is informed about this change.
92  //! @todo react on changes of KDbQueryColumnInfo::visible too
93  void setVisible(bool v);
94 
95  /*! Sets icon for displaying in the caption area (header). */
96  void setIcon(const QIcon &icon);
97 
98  /*! @return bame of icon displayed in the caption area (header). */
99  QIcon icon() const;
100 
101  /*! If @a visible is true, caption has to be displayed in the column's header,
102  (or field's name if caption is empty. True by default. */
103  void setHeaderTextVisible(bool visible);
104 
105  /*! @return true if caption has to be displayed in the column's header,
106  (or field's name if caption is empty. */
107  bool isHeaderTextVisible() const;
108 
109  /*! @return whatever is available:
110  - field's caption
111  - or field's alias (from query)
112  - or finally - field's name */
113  QString captionAliasOrName() const;
114 
115  /*! Assigns validator @a v for this column.
116  If the validator has no parent object, it will be owned by the column,
117  so you don't need to care about destroying it. */
118  void setValidator(KDbValidator *v);
119 
120  //! @return validator assigned for this column of 0 if there is no validator assigned.
121  KDbValidator* validator() const;
122 
123  /*! For not-db-aware data only:
124  Sets related data @a data for this column, what defines simple one-field,
125  one-to-many relationship between this column and the primary key in @a data.
126  The relationship will be used to generate a popup editor instead of just regular editor.
127  This assignment has no result if @a data has no primary key defined.
128  @a data is owned, so is will be destroyed when needed. It is also destroyed
129  when another data (or @c nullptr) is set for the same column. */
130  void setRelatedData(KDbTableViewData *data);
131 
132  /*! For not-db-aware data only:
133  Related data @a data for this column, what defines simple one-field.
134  @c nullptr by default. @see setRelatedData() */
135  KDbTableViewData *relatedData();
136 
137  //! @overload
138  const KDbTableViewData *relatedData() const;
139 
140  /*! @return field for this column.
141  For db-aware information is taken from columnInfo(). */
142  KDbField* field();
143 
144  //! @overload
145  const KDbField* field() const;
146 
147  /*! Only usable if related data is set (ie. this is for combo boxes).
148  Sets 'editable' flag for this column, what means a new value can be entered
149  by hand. This is similar to QComboBox::setEditable(). */
150  void setRelatedDataEditable(bool set);
151 
152  /*! Only usable if related data is set (ie. this is for combo boxes).
153  @return 'editable' flag for this column.
154  False by default. @see setRelatedDataEditable(bool). */
155  bool isRelatedDataEditable() const;
156 
157  /*! A rich field information for db-aware data.
158  For not-db-aware data it is always 0 (use field() instead). */
159  KDbQueryColumnInfo* columnInfo();
160 
161  //! @overload
162  const KDbQueryColumnInfo* columnInfo() const;
163 
164  /*! A rich field information for db-aware data. Specifies information for a column
165  that should be visible instead of columnInfo. For example case see
166  @ref KDbQueryColumnInfo::Vector KDbQuerySchema::fieldsExpanded(KDbQuerySchema::FieldsExpandedMode mode = Default)
167 
168  For not-db-aware data it is always @c nullptr. */
169  KDbQueryColumnInfo* visibleLookupColumnInfo();
170 
171  //! @overload
172  const KDbQueryColumnInfo* visibleLookupColumnInfo() const;
173 
174  //! @return true if data is stored in DB, not only in memeory.
175  bool isDBAware() const;
176 
177  /*! Sets visible width for this column to @a w (usually in pixels or points).
178  0 means there is no hint for the width. */
179  void setWidth(int w);
180 
181  /*! @return width of this field (usually in pixels or points).
182  0 (the default) means there is no hint for the width. */
183  int width() const;
184 
185 protected:
186  //! special ctor that does not allocate d member;
187  explicit KDbTableViewColumn(bool);
188 
189  //! used by KDbTableViewData::addColumn()
190  void setData(KDbTableViewData *data);
191 
192 private:
193  class Private;
194  Private * const d;
195 
196  friend class KDbTableViewData;
197  friend KDB_EXPORT QDebug operator<<(QDebug, const KDbTableViewColumn&);
199 };
200 
201 //! Sends information about column @a column to debug output @a dbg.
202 //! @since 3.1
203 KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbTableViewColumn &column);
204 
205 #endif
Definition of a single column for table view.
A list of records to allow configurable sorting and more.
A validator extending QValidator with offline-checking for value's validity.
Definition: KDbValidator.h:41
KDbQuerySchema provides information about database query.
Meta-data for a field.
Definition: KDbField.h:71
KDbTableViewColumn * column(int c)
Helper class that assigns additional information for the column in a query.
Q_DISABLE_COPY(Class)
QList< T > & operator<<(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Sep 26 2022 04:04:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.