Looks good to me.
But, performance is slow, if I have more number of tables (about more than
10 tables).
I have modified your patch, but for some reason not working..
PFA.. (please check if we can do something about it..)
--
Thanks & Regards,
Ashesh Vashi
EnterpriseDB INDIA: Enterprise Postgres Company<http://www.enterprisedb.com>
On Wed, Apr 14, 2010 at 12:29 AM, Guillaume Lelarge
<[email protected]>wrote:
> Le 13/04/2010 09:01, Guillaume Lelarge a écrit :
> > Hi Ashesh,
> >
> > Le 12/04/2010 11:14, Ashesh Vashi a écrit :
> >> [...]
> >> Right click on GQB will popup a menu (Refresh).
> >> This will adjust the size of the scroll windows, if the table's size
> goes
> >> beyond the current size.
> >>
> >
> > I checked your patch this morning. Works great. Thanks Ashesh.
> >
> >> 1200x800 is the default minimum size of the scrolled window defined by
> the
> >> constants:
> >> *#define GQB_MIN_WIDTH 1280*
> >> *#define GQB_MIN_HEIGHT 800*
> >> *
> >> *
> >> I tried adding the same code, when adding a new table/view.
> >> But, if I select a table for next to get created (by double click on
> >> left-side tree) and then press left clicks few times, the application is
> >> crashing.. Hence, just added this code to work with the pop-up menu. :-(
> >>
> >
> > Didn't try this, but will do tonight. It would be better if it
> > automatically grows the canvas size.
> >
>
> It seems to work with this patch (to apply above your own patch). Can
> you try it, please? It didn't crash for me, but I'm not a good tester.
>
>
> --
> Guillaume.
> http://www.postgresqlfr.org
> http://dalibo.com
>
Index: include/gqb/gqbEvents.h
===================================================================
--- include/gqb/gqbEvents.h (revision 8266)
+++ include/gqb/gqbEvents.h (working copy)
@@ -24,6 +24,7 @@
GQB_RMJ_DELETE = 2000,
GQB_RMJ_SETTYPE,
GQB_RMT_DELETE,
- GQB_RMT_SETALIAS
+ GQB_RMT_SETALIAS,
+ GQB_REFRESH
};
#endif
Index: include/gqb/gqbViewController.h
===================================================================
--- include/gqb/gqbViewController.h (revision 8266)
+++ include/gqb/gqbViewController.h (working copy)
@@ -30,6 +30,9 @@
#include "gqb/gqbGridJoinTable.h"
#include "gqb/gqbBrowser.h"
+#define GQB_MIN_WIDTH 1280
+#define GQB_MIN_HEIGHT 800
+
class gqbView;
enum pointerMode
@@ -67,7 +70,7 @@
public:
gqbController(gqbModel *_model, wxWindow *gqbParent, wxNotebook *gridParent, wxSize size);
~gqbController();
- void addTableToModel(gqbTable *table, wxPoint p);
+ 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);
@@ -124,29 +127,32 @@
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..)
+ // 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
+ 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
+ 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;
+ 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
+ // 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;
@@ -155,11 +161,14 @@
pointerMode mode; // pointer is used as normally or as in joins by example
wxImage joinCursorImage;
wxCursor joinCursor;
- wxMenu *m_rightJoins, *m_rightTables;
+ 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()
};
Index: frm/frmQuery.cpp
===================================================================
--- frm/frmQuery.cpp (revision 8266)
+++ frm/frmQuery.cpp (working copy)
@@ -467,7 +467,7 @@
// Graphical Canvas
// initialize values
model=new gqbModel();
- controller = new gqbController(model,sqlNotebook, outputPane, wxSize(1280,800));
+ controller = new gqbController(model,sqlNotebook, outputPane, wxSize(GQB_MIN_WIDTH, GQB_MIN_HEIGHT));
firstTime=true; // Inform to GQB that the tree of table haven't filled.
gqbUpdateRunning = false; // Are we already updating the SQL query - event recursion protection.
adjustSizesTimer=NULL; // Timer used to avoid a bug when close outputPane
Index: gqb/gqbView.cpp
===================================================================
--- gqb/gqbView.cpp (revision 8266)
+++ gqb/gqbView.cpp (working copy)
@@ -47,6 +47,7 @@
EVT_MENU(GQB_RMJ_DELETE, gqbView::OnMenuJoinDelete)
EVT_MENU(GQB_RMT_DELETE, gqbView::OnMenuTableDelete)
EVT_MENU(GQB_RMT_SETALIAS, gqbView::OnMenuTableSetAlias)
+EVT_MENU(GQB_REFRESH, gqbView::OnRefresh)
END_EVENT_TABLE()
gqbView::gqbView(wxWindow *gqbParent, wxNotebook *gridParent, wxSize size, gqbController *controller, gqbModel *model)
@@ -72,6 +73,7 @@
joinCursor= wxCursor(joinCursorImage);
m_rightJoins=NULL;
m_rightTables=NULL;
+ m_gqbPopup=NULL;
jTempSelected=NULL;
cTempSelected=NULL;
@@ -102,6 +104,8 @@
this->orderByLGridTable = new gqbGridOrderTable(1,model->getOrdByAvailColumns(),model->getOrdByAvailParents(),NULL);
this->orderByRGridTable = new gqbGridOrderTable(2,model->getOrdByColumns(), model->getOrdByParents(),model->getOrdByKind());
this->orderPanel = new gqbOrderPanel(controller->getTabs(), orderByLGridTable, orderByRGridTable);
+
+ SetVirtualSizeHints(size);
}
@@ -117,6 +121,9 @@
if(m_rightJoins)
delete m_rightJoins;
+
+ if (m_gqbPopup)
+ delete m_gqbPopup;
}
@@ -154,6 +161,9 @@
m_rightTables = new wxMenu;
m_rightTables->Append(GQB_RMT_SETALIAS, _("&Set Alias for table"));
m_rightTables->Append(GQB_RMT_DELETE, _("&Delete Table"));
+ m_rightTables->AppendSeparator();
+ m_rightTables->Append(GQB_REFRESH, _("&Refresh"));
+
}
cTempSelected=(gqbQueryObject *) (gqbObjectCollection *) anySelected;
jTempSelected=NULL;
@@ -166,12 +176,23 @@
{
m_rightJoins = new wxMenu;
m_rightJoins->Append(GQB_RMJ_DELETE, _("&Delete Join"));
+ m_rightJoins->AppendSeparator();
+ m_rightJoins->Append(GQB_REFRESH, _("&Refresh"));
}
cTempSelected=NULL;
jTempSelected=(gqbQueryJoin *) anySelected;;
PopupMenu(m_rightJoins, event.GetPosition());
}
}
+ else
+ {
+ if(!m_gqbPopup)
+ {
+ m_gqbPopup = new wxMenu;
+ m_gqbPopup->Append(GQB_REFRESH, _("&Refresh"));
+ }
+ PopupMenu(m_gqbPopup, event.GetPosition());
+ }
}
@@ -645,3 +666,87 @@
this->Refresh();
}
+
+void gqbView::OnRefresh(wxCommandEvent& ev)
+{
+ updateModelSize(NULL, true);
+ this->Update();
+}
+
+
+/*
+* updateModelSize
+* - Update the model size.
+* - Calculate the maximum width and maximum height of the model
+* * When removed a table/view from model, the obj parameter must be null,
+* and update parameter should be true, otherwise update parameter should
+* be false (Dragging event)
+*/
+void gqbView::updateModelSize(gqbQueryObject* obj, bool updateAnyWay)
+{
+ static int callCount = 0;
+ callCount++;
+ if (!obj)
+ {
+ // Do not update model size, everytime it gets called
+ // Update the size once in 10 times
+ // Update the size only if update flag is true
+ if (callCount < 10 && !updateAnyWay)
+ return;
+ callCount = 0;
+ // Figure out the actual model size.
+ // Remove table
+ int w = 0, h = 0, maxW = 0, maxH = 0;
+ if(!iterator)
+ // Get an iterator for the objects (tables/views) in the model.
+ iterator = this->model->createQueryIterator();
+ else
+ iterator->ResetIterator();
+
+ while (iterator->HasNext())
+ {
+ gqbQueryObject *tmp= (gqbQueryObject *)iterator->Next();;
+ w = tmp->position.x + tmp->getWidth();
+ h = tmp->position.y + tmp->getHeight();
+
+ if (maxW < w)
+ maxW = w;
+ if (maxH < h)
+ maxH = h;
+ }
+
+ // Reset Model size
+ modelSize.Set(maxW, maxH);
+ }
+ else
+ {
+ int w = 0, h = 0;
+ w = obj->position.x + obj->getWidth();
+ h = obj->position.y + obj->getHeight();
+
+ if (w > modelSize.GetWidth())
+ modelSize.SetWidth(w);
+ if (h > modelSize.GetHeight())
+ modelSize.SetHeight(h);
+ }
+ bool updateView = false;
+
+ if ((modelSize.GetWidth() > GQB_MIN_WIDTH || canvasSize.GetWidth() > GQB_MIN_WIDTH) &&
+ modelSize.GetWidth() != canvasSize.GetWidth())
+ {
+ canvasSize.SetWidth((modelSize.GetWidth() > GQB_MIN_WIDTH ? modelSize.GetWidth() : GQB_MIN_WIDTH));
+ updateView = true;
+ }
+ if ((modelSize.GetHeight() > GQB_MIN_HEIGHT || canvasSize.GetHeight() > GQB_MIN_HEIGHT) &&
+ modelSize.GetHeight() != canvasSize.GetHeight())
+ {
+ canvasSize.SetHeight((modelSize.GetHeight() > GQB_MIN_HEIGHT ? modelSize.GetHeight() : GQB_MIN_HEIGHT));
+ updateView = true;
+ }
+
+ if (updateView)
+ {
+ SetVirtualSize(canvasSize);
+ }
+}
+
Index: gqb/gqbController.cpp
===================================================================
--- gqb/gqbController.cpp (revision 8266)
+++ gqb/gqbController.cpp (working copy)
@@ -29,7 +29,7 @@
wxWindowID CTL_NTBKPANELS = ::wxNewId();
-gqbController::gqbController(gqbModel *_model, wxWindow *gqbParent, wxNotebook *gridParent, wxSize size=wxSize(800,1280))
+gqbController::gqbController(gqbModel *_model, wxWindow *gqbParent, wxNotebook *gridParent, wxSize size=wxSize(GQB_MIN_WIDTH, GQB_MIN_HEIGHT))
: wxObject()
{
pparent = gqbParent;
@@ -80,10 +80,11 @@
// Add a table to the model
-void gqbController::addTableToModel(gqbTable *table, wxPoint p)
+gqbQueryObject* gqbController::addTableToModel(gqbTable *table, wxPoint p)
{
gqbQueryObject *added = model->addTable(table,p);
view->newTableAdded(added);
+ return added;
}
Index: gqb/gqbBrowser.cpp
===================================================================
--- gqb/gqbBrowser.cpp (revision 8266)
+++ gqb/gqbBrowser.cpp (working copy)
@@ -127,8 +127,13 @@
if(result==wxDragCopy)
{
controller->getView()->CalcUnscrolledPosition(xx,yy,&xx,&yy);
- controller->addTableToModel(item,wxPoint(xx,yy));
+ gqbQueryObject* queryObj = controller->addTableToModel(item,wxPoint(xx,yy));
controller->getView()->Refresh();
+ if (queryObj)
+ {
+ controller->getView()->Update();
+ controller->getView()->updateModelSize(queryObj, false);
+ }
}
}
}
--
Sent via pgadmin-support mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support