File indexing completed on 2024-04-28 04:18:50
0001 /* 0002 Gwenview: an image viewer 0003 Copyright 2018 Anthony Fieroni <bvbfan@abv.bg> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public License 0007 as published by the Free Software Foundation; either version 2 0008 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. 0018 0019 */ 0020 #ifndef DIALOGGUARD_H 0021 #define DIALOGGUARD_H 0022 0023 // std 0024 #include <utility> 0025 0026 // Qt 0027 #include <QPointer> 0028 0029 template<class T> 0030 class DialogGuard 0031 { 0032 QPointer<T> m_dialog; 0033 0034 public: 0035 template<class... Args> 0036 DialogGuard(Args &&...args) 0037 { 0038 m_dialog = new T(std::forward<Args>(args)...); 0039 } 0040 0041 ~DialogGuard() 0042 { 0043 delete m_dialog; 0044 } 0045 0046 T *data() const 0047 { 0048 return m_dialog.data(); 0049 } 0050 0051 T *operator->() const 0052 { 0053 return m_dialog.data(); 0054 } 0055 0056 operator bool() const 0057 { 0058 return !m_dialog.isNull(); 0059 } 0060 }; 0061 0062 #endif // DIALOGGUARD_H