File: gqbViewController.h

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (241 lines) | stat: -rw-r--r-- 7,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbViewController.h - View and Controller implementation for MVC Pattern of GQB
//
//////////////////////////////////////////////////////////////////////////

#ifndef GQBCONTROLLER_H
#define GQBCONTROLLER_H

#include <wx/dcbuffer.h>
#include <wx/notebook.h>
#include <wx/splitter.h>
#include <wx/dnd.h>
#include <wx/dataobj.h>
#include <wx/aui/aui.h>

// App headers
#include "ctl/ctlAuiNotebook.h"
#include "gqb/gqbObject.h"
#include "gqb/gqbModel.h"
#include "gqb/gqbQueryObjs.h"
#include "gqb/gqbGraphBehavior.h"
#include "gqb/gqbColumn.h"
#include "gqb/gqbGridProjTable.h"
#include "gqb/gqbGridRestTable.h"
#include "gqb/gqbGridOrderTable.h"
#include "gqb/gqbGridJoinTable.h"
#include "gqb/gqbBrowser.h"

#define GQB_MIN_WIDTH  1280
#define GQB_MIN_HEIGHT 800

class gqbView;

enum pointerMode
{
    pt_normal,
    pt_join
};

// Utility Class to avoid a bug when the event sash resize is called
class gqbSplitter: public wxSplitterWindow
{
public:
	gqbSplitter(wxWindow *parent, wxWindowID id, const wxPoint &point, const wxSize &size, long style);
	void setTablesBrowser(gqbBrowser *b)
	{
		tablesBrowser = b;
	};
	void setBrowserPanel(wxPanel *p)
	{
		browserPanel = p;
	};

private:
	void onVerticalSashResize(wxSplitterEvent &event);
	gqbBrowser *tablesBrowser;        // tables Browser Tree
	wxPanel *browserPanel;            // Container of tables Browser Tree
	DECLARE_EVENT_TABLE()
};

// This enum is useful to select particular page from the tabs
enum tabsIndex
{
    ti_colsGridPanel = 0,
    ti_criteriaPanel,
    ti_orderPanel,
    ti_joinsPanel
};

class gqbController: public wxObject
{
public:
	gqbController(gqbModel *_model, wxWindow *gqbParent, ctlAuiNotebook *gridParent, wxSize size);
	~gqbController();
	gqbQueryObject *addTableToModel(gqbTable *table, wxPoint p);
	gqbQueryJoin *addJoin(gqbQueryObject *sTable, gqbColumn *sColumn, gqbQueryObject *dTable, gqbColumn *dColumn, type_Join kind);
	void removeJoin(gqbQueryJoin *join);
	void removeTableFromModel(gqbQueryObject *table, gqbGridProjTable *gridTable, gqbGridOrderTable *orderLTable, gqbGridOrderTable *orderRTable);
	void unsetModelSelected(bool queryTable);
	void processColumnInModel(gqbQueryObject *table, gqbColumn *column, gqbGridProjTable *gridTable);
	void setPointerMode(pointerMode pm);      // Find selected table with their coordinates point
	gqbView *getView()
	{
		return view;
	};
	void nullView()
	{
		view = NULL;
	};
	gqbObject *getModelSelected(wxPoint &pt, gqbQueryObject *lastSelected, gqbQueryJoin *lastJoinSelected, bool mark);
	wxString generateSQL();
	wxSplitterWindow *getViewContainer()
	{
		return gqbMainContainer;
	};
	wxSplitterWindow *getDialogParent()
	{
		return (wxSplitterWindow *) gqbContainer;
	};
	void setSashVertPosition(int pos);
	void setSashHorizPosition(int pos);
	int getSashHorizPosition();
	gqbBrowser *getTablesBrowser()
	{
		return tablesBrowser;
	};
	wxNotebook *getTabs()
	{
		return tabs;
	};
	void emptyModel();
	void calcGridColsSizes();
	gqbQueryRestriction *addRestriction();
	int getTableCount()
	{
		return model->tablesCount();
	};

protected:
	gqbView *view;						// owned by caller application shouldn't be destroy by this class
	wxWindow *pparent;					// GQB-TODO: deberia ser privada no se porque no funciona [la estoy usando?]
	gqbModel *model;					// owned by caller application shouldn't be destroy by this class
	wxNotebook *tabs;
	gqbSplitter *gqbContainer;			// container of canvas & tables browser.
	wxSplitterWindow *gqbMainContainer;
	gqbBrowser *tablesBrowser;			// tables Browser Tree
	wxPanel *browserPanel;				// Container of tables Browser Tree
};

class gqbView: public wxScrolledWindow
{
public:
	gqbView(wxWindow *gqbParent, ctlAuiNotebook *gridParent, wxSize size, gqbController *controller, gqbModel *model);
	~gqbView();
	void SaveAsImage(const wxString &path, wxBitmapType imgType);
	bool canSaveAsImage();
	void drawAll(wxMemoryDC &bdc, bool adjustScrolling);
	void setPointerMode(pointerMode pm);

	// Events for wxScrolledWindow
	void onPaint(wxPaintEvent &event);
	void onMotion(wxMouseEvent &event);
	void onDoubleClick(wxMouseEvent &event);
	void onRightClick(wxMouseEvent &event);
	void onErase(wxEraseEvent &event);
	void onEraseBackGround(wxEraseEvent &event);
	void OnKeyDown(wxKeyEvent &event);
	void OnSize(wxSizeEvent &event);
	wxPanel *getColsGridPanel()
	{
		return (wxPanel *)projectionPanel;
	};
	wxPanel *getCriteriaPanel()
	{
		return (wxPanel *)criteriaPanel;
	};
	wxPanel *getOrderPanel()
	{
		return (wxPanel *)orderPanel;
	};
	wxPanel *getJoinsPanel()
	{
		return joinsPanel;
	}
	void newTableAdded(gqbQueryObject *item);
	bool clickOnJoin (gqbQueryJoin *join, wxPoint &pt, wxPoint &origin, wxPoint &dest);
	void updateTable(gqbQueryObject *table);
	const wxSize &getModelSize()
	{
		return modelSize;
	}

	// Functions for all gqb extra Panels (projection, criteria..)
	void emptyPanelsData();

	void updateModelSize(gqbQueryObject *obj, bool updateAnyWay);

private:
	gqbController *controller;                                  // owned by caller application shouldn't be destroy
	// by this class
	gqbModel *model;                                            // owned by caller application shouldn't be destroy
	// by this class
	gqbGraphBehavior *graphBehavior;                            // This points to the Graph behavior for objects,
	// if change the way objects were draw changes too.
	gqbIteratorBase *iterator;                                  //include here for reuse of iterator, should be
	// delete when class destroy
	wxPanel *projectionPanel, *criteriaPanel, *orderPanel, *joinsPanel;
	gqbGridProjTable *gridTable;                                // Data model for the columns grid internals
	gqbGridRestTable *restrictionsGridTable;                    // Data model for restricions grid internals
	gqbGridJoinTable *joinsGridTable;                           // Data model for joins grid internals

	gqbGridOrderTable *orderByLGridTable, *orderByRGridTable;   // Data model for order by grid internals
	wxSize canvasSize, modelSize;
	bool changeTOpressed;

	// just a point to the selected item on the collection, shouldn't be destroy inside this class
	gqbQueryObject *collectionSelected, *joinSource, *joinDest, *cTempSelected;
	gqbQueryJoin *joinSelected, *jTempSelected;
	gqbColumn *joinSCol, *joinDCol;
	int pressed, selected, refreshRate;
	wxPoint pos, jpos;            // Position of the last event of the mouse & the first event of a join event
	pointerMode mode;             // pointer is used as normally or as in joins by example
	wxImage joinCursorImage;
	wxCursor joinCursor;
	wxMenu *m_rightJoins, *m_rightTables, *m_gqbPopup;
	void OnMenuJoinDelete(wxCommandEvent &event);
	void OnMenuTableDelete(wxCommandEvent &event);
	void OnMenuTableSetAlias(wxCommandEvent &event);
	void OnRefresh(wxCommandEvent &ev);

	wxArrayString joinTypeChoices;

	DECLARE_EVENT_TABLE()
};

// A drop target that do nothing only accept text, if accept then tree add table to model
class DnDText : public wxTextDropTarget
{
public:
	DnDText(gqbBrowser *tablesBrowser)
	{
		tree = tablesBrowser;
	}
	virtual bool OnDropText(wxCoord x, wxCoord y, const wxString &text)
	{
		tree->setDnDPoint(x, y);
		return true;
	}

private:
	gqbBrowser *tree;
};

#endif