Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
kdialog.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of KDWinutils, KDAB's MFC to Qt migration tool.
4**
5** Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6** All rights reserved.
7**
8** This file is intended solely for use by the migration tools and services
9** provided by Klarälvdalens Datakonsult AB.
10**
11** Any other use or distribution of this software that is not otherwise agreed
12** upon in writing and signed by an authorized representative of Klarälvdalens
13** Datakonsult AB, KDAB (USA) LLC, KDAB (Deutschland) GmbH & Co. K.G.,
14** KDAB (France) SAS, KDAB (UK), Ltd., or any future subsidiary of Klarälvdalens
15** Datakonsult AB is hereby prohibited.
16**
17** Contact info@kdab.com if any conditions stated above are unclear to you.
18**
19****************************************************************************/
20
21#pragma once
22
24#include "kwidget.h"
25
26#include <QDialog>
27
28#ifdef KDWINUTILS_WITHMFC
29#include <afxwin.h>
30#endif
31
33
39class KDWINUTILS_EXPORT KDialog : public KWidgetBase<QDialog>
40{
41 Q_OBJECT
42public:
44 explicit KDialog(QWidget *pParent = nullptr, Qt::WindowFlags f = {});
45#ifdef KDWINUTILS_WITHMFC
49 KDialog(CWnd *pParent, Qt::WindowFlags f = {});
50#endif
51
56 virtual bool OnInitDialog() { return true; }
57
58protected:
63 virtual void OnOK();
68 virtual void OnCancel();
73 virtual void OnClose();
74
75 void showEvent(QShowEvent *event) override;
76 void closeEvent(QCloseEvent *event) override;
77
78private:
79 bool m_initDone = false;
80 bool m_allowClose = false;
81};
82
83template <typename T>
84template <typename U>
86{
87 auto parent = T::parent();
88 while (parent) {
89 if (auto dialog = qobject_cast<KDialog *>(parent))
90 return dialog;
91 parent = parent->parent();
92 }
93 return nullptr;
94}
95
The KDialog class is used to replace MFC KDialog.
Definition kdialog.h:40
KDialog(CWnd *pParent, Qt::WindowFlags f={})
void showEvent(QShowEvent *event) override
void closeEvent(QCloseEvent *event) override
KDialog(QWidget *pParent=nullptr, Qt::WindowFlags f={})
virtual void OnOK()
Override to perform the OK button action in a modal dialog box.
virtual void OnCancel()
Override to perform the Cancel button or ESC key action.
virtual bool OnInitDialog()
Initializes the dialog internal data.
Definition kdialog.h:56
virtual void OnClose()
Called just before closing the dialog box.
The KWidgetBase< T > class maps the MFC API of CWnd.
Definition kwidget.h:87
KDialog * GetParentDialog() const
Retrieves the parent widget as a KDialog. Returns nullptr if it's not a KDialog.
Definition kdialog.h:85
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28