Scale identity combobox and send/cancel buttons according to screen DPI.
[kdepim.git] / messageviewer / autoqpointer.h
blob6a428676915f597e25c5097d948b556b7139af6f
1 /*
2 * autoqpointer.h - QPointer which on destruction deletes object
3 * This is a (mostly) verbatim, private copy of kdepim/kalarm/lib/autoqpointer.h
5 * Copyright © 2009 by David Jarvie <djarvie@kde.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef MESSAGEVIEWER_AUTOQPOINTER_H
23 #define MESSAGEVIEWER_AUTOQPOINTER_H
25 #include <QPointer>
26 #include <QObject>
28 #include <kdemacros.h>
30 namespace MessageViewer {
32 /**
33 * A QPointer which when destructed, deletes the object it points to.
35 * @author David Jarvie <djarvie@kde.org>, Marc Mutz <mutz@kde.org>
37 template <class T>
38 class AutoQPointer
40 Q_DISABLE_COPY( AutoQPointer )
41 struct SafeBool { void func() {} };
42 typedef void (SafeBool::*save_bool)();
43 QPointer<QObject> o;
44 public:
45 AutoQPointer() : o() {}
46 explicit AutoQPointer( T * p ) : o(p) {}
47 ~AutoQPointer() { delete o; }
48 T * data() const { return static_cast<T*>(o.data()); }
49 T * get() const { return data(); }
50 bool isNull() const { return o.isNull(); }
51 T * operator->() const { return data(); }
52 T & operator*() const { return *data(); }
53 #if 0 // enable when all users of operator T*() have been converted to use .get()
54 operator save_bool() const { return isNull() ? 0 : &SafeBool::func ; }
55 #else
56 // unsafe - use explicit .get()
57 KDE_DEPRECATED operator T*() const { return get(); }
58 // unsafe - only provided to prevent the above warning in bool contexts
59 operator bool() const { return get(); }
60 #endif
66 #endif // MESSAGEVIEWER_AUTOQPOINTER_H