~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/totool.h

  • Committer: Bazaar Package Importer
  • Author(s): Albin Tonnerre
  • Date: 2007-05-29 13:13:36 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529131336-85ygaddivvmkd3xc
Tags: 1.3.21pre22-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules: call dh_iconcache
  - Remove g++ build dependency
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /*****
 
2
*
 
3
* TOra - An Oracle Toolkit for DBA's and developers
 
4
* Copyright (C) 2003-2005 Quest Software, Inc
 
5
* Portions Copyright (C) 2005 Other Contributors
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation;  only version 2 of
 
10
* the License is valid for this program.
 
11
*
 
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.
 
16
*
 
17
* You should have received a copy of the GNU General Public License
 
18
* along with this program; if not, write to the Free Software
 
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
*
 
21
*      As a special exception, you have permission to link this program
 
22
*      with the Oracle Client libraries and distribute executables, as long
 
23
*      as you follow the requirements of the GNU GPL in regard to all of the
 
24
*      software in the executable aside from Oracle client libraries.
 
25
*
 
26
*      Specifically you are not permitted to link this program with the
 
27
*      Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech.
 
28
*      And you are not permitted to distribute binaries compiled against
 
29
*      these libraries without written consent from Quest Software, Inc.
 
30
*      Observe that this does not disallow linking to the Qt Free Edition.
 
31
*
 
32
*      You may link this product with any GPL'd Qt library such as Qt/Free
 
33
*
 
34
* All trademarks belong to their respective owners.
 
35
*
 
36
*****/
 
37
 
 
38
#ifndef TOTOOL_H
 
39
#define TOTOOL_H
 
40
 
 
41
#include "config.h"
 
42
#include "toconfiguration.h"
 
43
 
 
44
#include <map>
 
45
 
 
46
#include <qobject.h>
 
47
#include <qstring.h>
 
48
#include <qvbox.h>
 
49
 
 
50
class toConnection;
 
51
class toTimer;
 
52
 
 
53
/**
 
54
 * Abstract baseclass for tools.
 
55
 *
 
56
 * This class is the baseclass of all classes defining tools. It
 
57
 * contains functions for defining the priority and name of the tool,
 
58
 * as well as virtual functions to define it's place in the user
 
59
 * interface. Further it contains methods to access configuration
 
60
 * settings.
 
61
 *
 
62
 * To use this class you create a child which is then instantiated once
 
63
 * which inserts that tool in the global tool map (See @ref tools). You
 
64
 * should never delete a tool unless on exit. Usually tools are instantiated
 
65
 * statically in the global scope.
 
66
 */
 
67
 
 
68
class toTool : public QObject
 
69
{
 
70
    Q_OBJECT
 
71
private:
 
72
    /**
 
73
     * Name of the tool.
 
74
     */
 
75
    QCString Name;
 
76
    /**
 
77
     * Key of the tool, this is used for sorting.
 
78
     */
 
79
    QCString Key;
 
80
    /**
 
81
     * Priority, used to determine in which order the tools should be listed.
 
82
     */
 
83
    int Priority;
 
84
    /**
 
85
     * A map of @ref Key to tools. Used to keep track of the different tools
 
86
     * available.
 
87
     */
 
88
    static std::map<QCString, toTool *> *Tools;
 
89
    /**
 
90
     * Contain the pixmap of this tool if any. Used for the toolbar and menu entries.
 
91
     */
 
92
    QPixmap *ButtonPicture;
 
93
 
 
94
 
 
95
protected:
 
96
    /**
 
97
     * Should return the xpm used to create the @ref ButtonPicture.
 
98
     */
 
99
    virtual const char **pictureXPM(void);
 
100
public:
 
101
    /**
 
102
     * Get the name.
 
103
     *
 
104
     * @return Name of tool.
 
105
     */
 
106
    QCString name() const
 
107
    {
 
108
        return Name;
 
109
    }
 
110
    /**
 
111
     * Get the name.
 
112
     *
 
113
     * @return Name of tool.
 
114
     */
 
115
    QCString key() const
 
116
    {
 
117
        return Key;
 
118
    }
 
119
    /**
 
120
     * Get the priority.
 
121
     *
 
122
     * @return Priority of tool.
 
123
     */
 
124
    int priority() const
 
125
    {
 
126
        return Priority;
 
127
    }
 
128
    /**
 
129
     * This should never be called, but if it is. Erases the tool from the list of
 
130
     * available tools. WARNING: It will not remove any of it's open tools.
 
131
     */
 
132
    ~toTool();
 
133
 
 
134
    /**
 
135
     * Create a tool. Remember that usually the main window is not created here.
 
136
     *
 
137
     * @param priority Priority of the created tool.
 
138
     * @param name Name of tool.
 
139
     */
 
140
    toTool(int priority, const char *name);
 
141
    /**
 
142
     * Get the image to display in the toolbar.
 
143
     *
 
144
     * @return Pointer to image in toolbar or NULL if no image should be displayed.
 
145
     */
 
146
    virtual const QPixmap *toolbarImage();
 
147
    /**
 
148
     * Get the name of the menuitem to be displayed in the menu.
 
149
     *
 
150
     * @return A string containing the name of the menuentry or NULL if no menuentry should
 
151
     *         be created.
 
152
     */
 
153
    virtual const char *menuItem()
 
154
    {
 
155
        return NULL;
 
156
    }
 
157
    /**
 
158
     * Get toolbar tip of the toolbar button. Defaults to same as @ref menuItem.
 
159
     *
 
160
     * @return Toolbar tip string.
 
161
     */
 
162
    virtual const char *toolbarTip()
 
163
    {
 
164
        return menuItem();
 
165
    }
 
166
 
 
167
    /** Check if the tool can handle a specific connection. Default is to only handle
 
168
     * connections from the provider Oracle.
 
169
     * @return True if connection can be handled.
 
170
     */
 
171
    virtual bool canHandle(toConnection &conn);
 
172
    /**
 
173
     * This function is called as a last step after the main widget is created. It could
 
174
     * be used to insert the tool pretty much anywhere in the user interface if the toolmenu,
 
175
     * toolbar is not sufficient.
 
176
     *
 
177
     * @param toolid The tool menu id that should be used if it inserts a custom menu entry.
 
178
     */
 
179
    virtual void customSetup(int toolid);
 
180
    /**
 
181
     * Create a new tool window.
 
182
     *
 
183
     * @param parent Parent window, which is the worksheet of the main window.
 
184
     * @param connection The database connection that this tool should operate on.
 
185
     */
 
186
    virtual QWidget *toolWindow(QWidget *parent, toConnection &connection) = 0;
 
187
    /**
 
188
     * Create and return configuration tab for this tool. The returned widget should also
 
189
     * be a childclass of @ref toSettingTab.
 
190
     *
 
191
     * @return A pointer to the widget containing the setup tab for this tool or NULL of
 
192
     * no settings are available.
 
193
     */
 
194
    virtual QWidget *configurationTab(QWidget *parent);
 
195
 
 
196
    /** Display an about dialog for this tool.
 
197
     * @param parent The parent widget of the about dialog.
 
198
     */
 
199
    virtual void about(QWidget *parent);
 
200
    /** Indicate whether or not this tool has an about dialog.
 
201
     */
 
202
    virtual bool hasAbout(void)
 
203
    {
 
204
        return false;
 
205
    }
 
206
 
 
207
    /**
 
208
     * Get access to the map of tools. Don't modify it. Observe that the index string is not
 
209
     * the name of the tool but an internal key used to get tools sorted in the correct
 
210
     * priority order.
 
211
     *
 
212
     * @see Tools
 
213
     * @return A reference to the tool map.
 
214
     */
 
215
    static std::map<QCString, toTool *> &tools(void)
 
216
    {
 
217
        if (!Tools)
 
218
            Tools = new std::map<QCString, toTool *>;
 
219
        return *Tools;
 
220
    }
 
221
    /**
 
222
     * Get a pointer to the tool with a specified key.
 
223
     *
 
224
     * @see Tools
 
225
     * @return A pointer to the tool or NULL if tool doesn't exist.
 
226
     */
 
227
    static toTool *tool(const QCString &key);
 
228
 
 
229
  /**
 
230
   * Get tool specific settings.
 
231
   *
 
232
   * Setting names are hierachical separated by ':' instead of '/' usually used
 
233
   * in filenames. As an example all settings for the tool 'Example' would be
 
234
   * under the 'Example:{settingname}' name.
 
235
   *
 
236
   * @param tag The name of the configuration setting.
 
237
   * @param def Contents of this setting.
 
238
   */
 
239
  const QString &config(const QCString &tag,const QCString &def);
 
240
 
 
241
  /**
 
242
   * Change toolspecific setting. Depending on the implementation this can change the
 
243
   * contents on disk or not.
 
244
   *
 
245
   * Setting names are hierachical separated by ':' instead of '/' usually used
 
246
   * in filenames. As an example all settings for the tool 'Example' would be
 
247
   * under the 'Example:{settingname}' name.
 
248
   *
 
249
   * @param tag The name of the configuration setting.
 
250
   * @param def Default value of the setting, if it is not available.
 
251
   */
 
252
  void setConfig(const QCString &tag,const QString &value);
 
253
 
 
254
  virtual void closeWindow(toConnection &connection) = 0;
 
255
 
 
256
public slots:
 
257
    /**
 
258
     * Create a window of the current tool. This function sets up a toolwindow for
 
259
     * this tool. It calls the @ref toolWindow function to get widget and sets it
 
260
     * up properly.
 
261
     */
 
262
    void createWindow(void);
 
263
 
 
264
 
 
265
};
 
266
 
 
267
#include "tohelp.h"
 
268
 
 
269
/**
 
270
 * Abstract baseclass for widgets defining tool settings.
 
271
 */
 
272
 
 
273
class toSettingTab : public toHelpContext
 
274
{
 
275
public:
 
276
    /**
 
277
     * Default constructor.
 
278
     * @param ctx Help context for this setting tab.
 
279
     */
 
280
    toSettingTab(const QString &ctx)
 
281
            : toHelpContext(ctx)
 
282
    { }
 
283
    /**
 
284
     * This function is called to save the contents of the widget when
 
285
     * a user has pressed the ok button of the dialog. It should simply
 
286
     * save the values in the dialog to the appropriate configuration
 
287
     * entry using the @ref toTool::setConfig function.
 
288
     */
 
289
    virtual void saveSetting(void) = 0;
 
290
};
 
291
 
 
292
/** This class is used to hold connections for @ref toResult classes.
 
293
 * Must be multiply inherited by a widget otherwise it will go kaboom.
 
294
 * It will dynamic cast itself to a QWidget from time to time so if that
 
295
 * doesn't resolve correctly it will not work.
 
296
 */
 
297
class toConnectionWidget
 
298
{
 
299
    toConnection *Connection;
 
300
    QWidget *Widget;
 
301
public:
 
302
    /** Constructor with the connection it should be set to initially.
 
303
     */
 
304
    toConnectionWidget(toConnection &conn, QWidget *widget);
 
305
    /** Constructor without a connection. Will inherit the connection from a parent connection widget.
 
306
     */
 
307
    toConnectionWidget(QWidget *widget);
 
308
    /** Destructor.
 
309
     */
 
310
    virtual ~toConnectionWidget();
 
311
    /** Change connection of the widget.
 
312
     */
 
313
    virtual void setConnection(toConnection &conn);
 
314
    /** Get the connection it is pointed to.
 
315
     */
 
316
    virtual toConnection &connection();
 
317
};
 
318
 
 
319
/** Simple baseclass for widgets defining the main tool widget. It is in
 
320
 * no way mandatory and all it does is register the widget in the connetion.
 
321
 */
 
322
class toToolWidget : public QVBox, public toHelpContext, public toConnectionWidget
 
323
{
 
324
    Q_OBJECT
 
325
    toTimer *Timer;
 
326
    toTool &Tool;
 
327
private slots:
 
328
    void parentConnection(void);
 
329
signals:
 
330
    /** Emitted when the connection is changed.
 
331
     */
 
332
    void connectionChange(void);
 
333
public:
 
334
    /** Create widget.
 
335
     * @param ctx Help context for this tool.
 
336
     * @param parent Parent widget.
 
337
     * @param conn Connection of widget.
 
338
     * @param name Name of widget.
 
339
     */
 
340
    toToolWidget(toTool &tool,
 
341
                 const QString &ctx,
 
342
                 QWidget *parent,
 
343
                 toConnection &conn,
 
344
                 const char *name = NULL);
 
345
    ~toToolWidget();
 
346
    /** Get the current connection.
 
347
     * @return Reference to connection.
 
348
     */
 
349
    toConnection &connection()
 
350
    {
 
351
        return toConnectionWidget::connection();
 
352
    }
 
353
    /** Get the tool for this tool widget.
 
354
     * @return Reference to a tool object.
 
355
     */
 
356
    toTool &tool(void)
 
357
    {
 
358
        return Tool;
 
359
    }
 
360
    /** Check if this tool can handle a specific connection.
 
361
     * @param provider Name of connection.
 
362
     * @return True if connection is handled.
 
363
     */
 
364
    virtual bool canHandle(toConnection &conn)
 
365
    {
 
366
        return Tool.canHandle(conn);
 
367
    }
 
368
    /** Change connection of tool.
 
369
     */
 
370
    void setConnection(toConnection &conn);
 
371
    /** Get timer of tool. Used by some results to get update time.
 
372
     * @return Pointer to a timer object.
 
373
     */
 
374
    toTimer *timer(void);
 
375
 
 
376
    /** Export data to a map.
 
377
     * @param data A map that can be used to recreate the data of a chart.
 
378
     * @param prefix Prefix to add to the map.
 
379
     */
 
380
    virtual void exportData(std::map<QCString, QString> &data, const QCString &prefix);
 
381
    /** Import data
 
382
     * @param data Data to read from a map.
 
383
     * @param prefix Prefix to read data from.
 
384
     */
 
385
    virtual void importData(std::map<QCString, QString> &data, const QCString &prefix);
 
386
};
 
387
 
 
388
#endif