File indexing completed on 2024-10-13 12:38:24
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 #include "KDbQueryColumnInfo.h" 0021 #include "KDbQuerySchema_p.h" 0022 #include "KDbTableSchema.h" 0023 #include "KDbField.h" 0024 #include "KDbField_p.h" 0025 #include "kdb_debug.h" 0026 0027 KDbQueryColumnInfo::KDbQueryColumnInfo(KDbField *f, const QString& alias, bool visible, 0028 KDbQueryColumnInfo *foreignColumn) 0029 : d(new Private(f, alias, visible, foreignColumn)) 0030 { 0031 } 0032 0033 KDbQueryColumnInfo::~KDbQueryColumnInfo() 0034 { 0035 delete d; 0036 } 0037 0038 KDbField* KDbQueryColumnInfo::field() 0039 { 0040 return d->field; 0041 } 0042 0043 const KDbField* KDbQueryColumnInfo::field() const 0044 { 0045 return d->field; 0046 } 0047 0048 void KDbQueryColumnInfo::setField(KDbField *field) 0049 { 0050 d->field = field; 0051 } 0052 0053 QString KDbQueryColumnInfo::alias() const 0054 { 0055 return d->alias; 0056 } 0057 0058 void KDbQueryColumnInfo::setAlias(const QString &alias) 0059 { 0060 d->alias = alias; 0061 } 0062 0063 QString KDbQueryColumnInfo::aliasOrName() const 0064 { 0065 return d->alias.isEmpty() ? d->field->name() : d->alias; 0066 } 0067 0068 QString KDbQueryColumnInfo::captionOrAliasOrName() const 0069 { 0070 return d->field->caption().isEmpty() ? aliasOrName() : d->field->caption(); 0071 } 0072 0073 bool KDbQueryColumnInfo::isVisible() const 0074 { 0075 return d->visible; 0076 } 0077 0078 void KDbQueryColumnInfo::setVisible(bool set) 0079 { 0080 d->visible = set; 0081 } 0082 0083 int KDbQueryColumnInfo::indexForVisibleLookupValue() const 0084 { 0085 return d->indexForVisibleLookupValue; 0086 } 0087 0088 void KDbQueryColumnInfo::setIndexForVisibleLookupValue(int index) 0089 { 0090 d->indexForVisibleLookupValue = index; 0091 } 0092 0093 KDbQueryColumnInfo *KDbQueryColumnInfo::foreignColumn() 0094 { 0095 return d->foreignColumn; 0096 } 0097 0098 const KDbQueryColumnInfo *KDbQueryColumnInfo::foreignColumn() const 0099 { 0100 return d->foreignColumn; 0101 } 0102 0103 const KDbQuerySchema* KDbQueryColumnInfo::querySchema() const 0104 { 0105 return d->querySchema; 0106 } 0107 0108 KDbConnection* KDbQueryColumnInfo::connection() 0109 { 0110 return d->connection; 0111 } 0112 0113 const KDbConnection* KDbQueryColumnInfo::connection() const 0114 { 0115 return d->connection; 0116 } 0117 0118 QDebug operator<<(QDebug dbg, const KDbQueryColumnInfo& info) 0119 { 0120 QString fieldName; 0121 if (info.field()->name().isEmpty()) { 0122 fieldName = QLatin1String("<NONAME>"); 0123 } else { 0124 fieldName = info.field()->name(); 0125 } 0126 dbg.nospace() 0127 << (info.field()->table() ? (info.field()->table()->name() + QLatin1Char('.')) : QString()) 0128 + fieldName; 0129 debug(dbg, *info.field(), KDbFieldDebugNoOptions); 0130 dbg.nospace() 0131 << qPrintable(info.alias().isEmpty() ? QString() : (QLatin1String(" AS ") + info.alias())) 0132 << qPrintable(QLatin1String(info.isVisible() ? nullptr : " [INVISIBLE]")); 0133 return dbg.space(); 0134 }