KDb

KDbQueryColumnInfo.h
1 /* This file is part of the KDE project
2  Copyright (C) 2003-2018 Jarosław Staniek <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KDB_QUERYCOLUMNINFO_H
21 #define KDB_QUERYCOLUMNINFO_H
22 
23 #include "kdb_export.h"
24 
25 #include <QList>
26 #include <QVector>
27 #include <QString>
28 
29 class KDbConnection;
30 class KDbField;
31 class KDbQuerySchema;
32 
33 //! @short Helper class that assigns additional information for the column in a query
34 /*! The following information is assigned:
35  - alias
36  - visibility
37  KDbQueryColumnInfo::Vector is created and returned by KDbQuerySchema::fieldsExpanded().
38  It is efficiently cached within the KDbQuerySchema object.
39 */
40 class KDB_EXPORT KDbQueryColumnInfo
41 {
42 public:
45  typedef QList<KDbQueryColumnInfo*>::ConstIterator ListIterator;
46 
47  KDbQueryColumnInfo(KDbField *f, const QString &alias, bool visible,
48  KDbQueryColumnInfo *foreignColumn = nullptr);
50 
51  //! @return field for this column
52  KDbField *field();
53 
54  //! @overload KDbField *field()
55  const KDbField *field() const;
56 
57  //! Sets the field
58  void setField(KDbField *field);
59 
60  //! @return alias for this column
61  QString alias() const;
62 
63  //! Sets the alias
64  void setAlias(const QString &alias);
65 
66  //! @return alias if it is not empty, field's name otherwise.
67  QString aliasOrName() const;
68 
69  //! @return field's caption if it is not empty, field's alias otherwise.
70  //! If alias is also empty - returns field's name.
71  QString captionOrAliasOrName() const;
72 
73  //! @return true is this column is visible
74  bool isVisible() const;
75 
76  //! Sets the visible flag
77  void setVisible(bool set);
78 
79  /*! @return index of column with visible lookup value within the 'fields expanded' vector.
80  -1 means no visible lookup value is available because there is no lookup for the column defined.
81  Cached for efficiency as we use this information frequently.
82  @see KDbLookupFieldSchema::visibleVolumn() */
83  int indexForVisibleLookupValue() const;
84 
85  /*! Sets index of column with visible lookup value within the 'fields expanded' vector. */
86  void setIndexForVisibleLookupValue(int index);
87 
88  //! @return non-nullptr if this column is a visible column for other column
89  KDbQueryColumnInfo *foreignColumn();
90 
91  //! @overload KDbQueryColumnInfo *foreignColumn();
92  const KDbQueryColumnInfo *foreignColumn() const;
93 
94  /**
95  * Returns query schema for this column
96  *
97  * @since 3.2
98  */
99  const KDbQuerySchema* querySchema() const;
100 
101  /**
102  * Returns connection for this column
103  *
104  * @since 3.2
105  */
106  KDbConnection* connection();
107 
108  /**
109  * @overload
110  *
111  * @since 3.2
112  */
113  const KDbConnection* connection() const;
114 
115 private:
116  friend class KDbQuerySchema;
117  class Private;
118  Private * const d;
119  Q_DISABLE_COPY(KDbQueryColumnInfo)
120 };
121 
122 //! Sends information about column info @a info to debug output @a dbg.
123 KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbQueryColumnInfo& info);
124 
125 #endif
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
KDbQuerySchema provides information about database query.
Meta-data for a field.
Definition: KDbField.h:71
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
Helper class that assigns additional information for the column in a query.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.