File indexing completed on 2024-12-01 07:24:58
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003-2018 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KDB_QUERYCOLUMNINFO_H 0021 #define KDB_QUERYCOLUMNINFO_H 0022 0023 #include "kdb_export.h" 0024 0025 #include <QList> 0026 #include <QVector> 0027 #include <QString> 0028 0029 class KDbConnection; 0030 class KDbField; 0031 class KDbQuerySchema; 0032 0033 //! @short Helper class that assigns additional information for the column in a query 0034 /*! The following information is assigned: 0035 - alias 0036 - visibility 0037 KDbQueryColumnInfo::Vector is created and returned by KDbQuerySchema::fieldsExpanded(). 0038 It is efficiently cached within the KDbQuerySchema object. 0039 */ 0040 class KDB_EXPORT KDbQueryColumnInfo 0041 { 0042 public: 0043 typedef QVector<KDbQueryColumnInfo*> Vector; 0044 typedef QList<KDbQueryColumnInfo*> List; 0045 typedef QList<KDbQueryColumnInfo*>::ConstIterator ListIterator; 0046 0047 KDbQueryColumnInfo(KDbField *f, const QString &alias, bool visible, 0048 KDbQueryColumnInfo *foreignColumn = nullptr); 0049 ~KDbQueryColumnInfo(); 0050 0051 //! @return field for this column 0052 KDbField *field(); 0053 0054 //! @overload KDbField *field() 0055 const KDbField *field() const; 0056 0057 //! Sets the field 0058 void setField(KDbField *field); 0059 0060 //! @return alias for this column 0061 QString alias() const; 0062 0063 //! Sets the alias 0064 void setAlias(const QString &alias); 0065 0066 //! @return alias if it is not empty, field's name otherwise. 0067 QString aliasOrName() const; 0068 0069 //! @return field's caption if it is not empty, field's alias otherwise. 0070 //! If alias is also empty - returns field's name. 0071 QString captionOrAliasOrName() const; 0072 0073 //! @return true is this column is visible 0074 bool isVisible() const; 0075 0076 //! Sets the visible flag 0077 void setVisible(bool set); 0078 0079 /*! @return index of column with visible lookup value within the 'fields expanded' vector. 0080 -1 means no visible lookup value is available because there is no lookup for the column defined. 0081 Cached for efficiency as we use this information frequently. 0082 @see KDbLookupFieldSchema::visibleVolumn() */ 0083 int indexForVisibleLookupValue() const; 0084 0085 /*! Sets index of column with visible lookup value within the 'fields expanded' vector. */ 0086 void setIndexForVisibleLookupValue(int index); 0087 0088 //! @return non-nullptr if this column is a visible column for other column 0089 KDbQueryColumnInfo *foreignColumn(); 0090 0091 //! @overload KDbQueryColumnInfo *foreignColumn(); 0092 const KDbQueryColumnInfo *foreignColumn() const; 0093 0094 /** 0095 * Returns query schema for this column 0096 * 0097 * @since 3.2 0098 */ 0099 const KDbQuerySchema* querySchema() const; 0100 0101 /** 0102 * Returns connection for this column 0103 * 0104 * @since 3.2 0105 */ 0106 KDbConnection* connection(); 0107 0108 /** 0109 * @overload 0110 * 0111 * @since 3.2 0112 */ 0113 const KDbConnection* connection() const; 0114 0115 private: 0116 friend class KDbQuerySchema; 0117 class Private; 0118 Private * const d; 0119 Q_DISABLE_COPY(KDbQueryColumnInfo) 0120 }; 0121 0122 //! Sends information about column info @a info to debug output @a dbg. 0123 KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbQueryColumnInfo& info); 0124 0125 #endif