1 /*
2 uiextractor.cpp
3
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
6
7 Copyright (C) 2011-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
9
10 Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11 accordance with GammaRay Commercial License Agreement provided with the Software.
12
13 Contact info@kdab.com if any conditions of this licensing are not clear to you.
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29 #include "uiextractor.h"
30
31 #ifdef HAVE_QT_DESIGNER
32 #include <QDebug>
33 #include <QLocale>
34 #include <QMetaObject>
35 #include <QMetaProperty>
36
37 using namespace GammaRay;
38
checkProperty(QObject * obj,const QString & prop) const39 bool UiExtractor::checkProperty(QObject *obj, const QString &prop) const
40 {
41 const QMetaObject *mo = obj->metaObject();
42 const QMetaProperty mp = mo->property(mo->indexOfProperty(prop.toLatin1()));
43
44 // TODO come up with some more aggressive filtering
45 if (mp.isValid() && mp.isDesignable(obj) && mp.isStored(obj) && mp.isWritable()) {
46 const QVariant value = mp.read(obj);
47
48 // try to figure out the default by resetting to it
49 if (mp.isResettable()) {
50 mp.reset(obj);
51 if (mp.read(obj) == value)
52 return false;
53 mp.write(obj, value);
54 return true;
55 }
56
57 // some guessing for non-resettable properties
58 if (value.isNull() || !value.isValid())
59 return false;
60
61 if (value.type() == QVariant::String)
62 return !value.toString().isEmpty();
63 else if (value.type() == QVariant::Locale)
64 return value.toLocale() != QLocale::system();
65
66 return true;
67 }
68
69 return false;
70 }
71
72 #endif
73