]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDialog.h
fix memory leaks
[lyx.git] / src / frontends / qt4 / GuiDialog.h
1 // -*- C++ -*-
2 /**
3  * \file GuiDialog.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUIDIALOG_H
13 #define GUIDIALOG_H
14
15 #include "Dialog.h"
16 #include "ButtonController.h"
17
18 #include "insets/InsetCommandParams.h"
19
20 #include <QDialog>
21 #include <QObject>
22
23 class QCloseEvent;
24 class QShowEvent;
25
26 namespace lyx {
27 namespace frontend {
28
29 /** \c Dialog collects the different parts of a Model-Controller-View
30  *  split of a generic dialog together.
31  */
32 class GuiDialog : public QDialog, public Dialog
33 {
34         Q_OBJECT
35
36 public:
37         /// \param lv is the access point for the dialog to the LyX kernel.
38         /// \param name is the identifier given to the dialog by its parent
39         /// container.
40         explicit GuiDialog(GuiView & lv, std::string const & name);
41         ~GuiDialog();
42
43 public Q_SLOTS:
44         /** \name Buttons
45          *  These methods are publicly accessible because they are invoked
46          *  by the View when the user presses... guess what ;-)
47          */
48         // Restore button clicked
49         void slotRestore();
50         // OK button clicked
51         void slotOK();
52         // Apply button clicked
53         void slotApply();
54         // Close button clicked or closed from WindowManager
55         void slotClose();
56
57 public:
58         /** Check whether we may apply our data.
59          *
60          *  The buttons are disabled if not and (re-)enabled if yes.
61          */
62         void checkStatus();
63         void setButtonsValid(bool valid);
64
65         /** \name Dialog Components
66          *  Methods to access the various components making up a dialog.
67          */
68         //@{
69         ButtonController const & bc() const { return bc_; }
70         ButtonController & bc() { return bc_; }
71         //@}
72
73         void setViewTitle(docstring const & title);
74
75
76         /// the dialog has changed contents
77         virtual void changed();
78
79         /// default: do nothing
80         virtual void applyView() {}
81         /// default: do nothing
82         virtual void updateContents() {}
83         ///
84         void closeEvent(QCloseEvent *);
85         ///
86         void showEvent(QShowEvent *);
87
88 protected:
89         /// Hide the dialog.
90         virtual void hideView();
91         /// Create the dialog if necessary, update it and display it.
92         virtual void showView();
93         ///
94         virtual bool isVisibleView() const;
95         /// is the dialog currently valid ?
96         virtual bool isValid() { return true; }
97
98 public:
99         /** \name Container Access
100          *  These methods are publicly accessible because they are invoked
101          *  by the parent container acting on commands from the LyX kernel.
102          */
103         //@{
104         /// \param data is a string encoding of the data to be displayed.
105         /// It is passed to the Controller to be translated into a useable form.
106         void showData(std::string const & data);
107         void updateData(std::string const & data);
108
109         void hide();
110
111         //@}
112
113         /** When applying, it's useful to know whether the dialog is about
114          *  to close or not (no point refreshing the display for example).
115          */
116         bool isClosing() const { return is_closing_; }
117
118         void apply();
119
120         /// Update the display of the dialog whilst it is still visible.
121         virtual void updateView();
122
123 private:
124         ButtonController bc_;
125         /// are we updating ?
126         bool updating_;
127
128         bool is_closing_;
129 };
130
131
132 class GuiCommand : public GuiDialog
133 {
134 public:
135         /// We need to know with what sort of inset we're associated.
136         // FIXME This should probably be an InsetCode
137         GuiCommand(GuiView &, std::string const & name);
138         ///
139         bool initialiseParams(std::string const & data);
140         /// clean-up on hide.
141         void clearParams() { params_.clear(); }
142         /// clean-up on hide.
143         void dispatchParams();
144         ///
145         bool isBufferDependent() const { return true; }
146
147 protected:
148         ///
149         InsetCommandParams params_;
150         //FIXME It should be possible to eliminate lfun_name_
151         //now and recover that information from params().insetType().
152         //But let's not do that quite yet.
153         /// Flags what action is taken by Kernel::dispatch()
154         std::string const lfun_name_;
155 };
156
157 } // namespace frontend
158 } // namespace lyx
159
160 #endif // GUIDIALOG_H