OverrideParameters in QControl constructor

Login or register to post comments
1 reply [Last post]
Offline
Joined: 03/07/2011

Hello and welcome. I'm new to forum, but not new to Qcodo/Qcubed. In fact I'm using it in my almost every web project since Qcodo beta3. I think it's the time to try to give something back to the QCommunity :) For the good start, proposition of a little modification that could be very useful.

I've already created a ticket for this:
http://trac.qcu.be/projects/qcubed/ticket/706

Some controls (e.g. QDataGridColumn, QCheckBoxColumn) have a nice feature - you can set control's parameters in constructor. I'm using it heavily during creation datagrid columns and found it very useful. I wondered if it could be possible to have that with other common controls (buttons, labels etc). I tried to copy few lines of code from QDataGridColumn constructor to QControlBase and - what a surprise - it worked.

Code added to QControlBase constructor:

$objOverrideArray = func_get_args();
if(count($objOverrideArray) > 2)
try
{
unset($objOverrideArray[0]);
unset($objOverrideArray[1]);
$this->OverrideAttributes($objOverrideArray);
}
catch(QCallerException $objExc)
{
$objExc->IncrementOffset();
throw $objExc;
}

Now I can have:

$this->lblTitle = new QLabel($this, null, 'CssClass=panelTitle', 'Text=Bounces');

instead of:
$this->lblTitle = new QLabel($this);
$this->lblTitle->CssClass = 'panelTitle';
$this->lblTitle->Text = 'Bounces';

another example:
$this->btnDelete = new QButton($this, null, array(
'Text' => 'Delete','ForeColor' => 'red',
'Width' => 100,'Visible' => $this->mctIspDomain->EditMode));

It seems to be fully backward-compatible. If you don't like this method, you can set parameters the old way.

I'm not sure if QControlBase class is the best place for this modification. Some controls that inherit from QControlBase have own custom constructors. We can't simply pass third parameter up to parent class constructor, because this modification uses variable number of parameters. Correct me if I'm wrong.
I've tested it with some controls and it works with QButton, QLabel, but not with QTextBox, QDataGrid. Maybe the best solution is to apply this modification to every control class?

darq

profnotime's picture
Offline
Joined: 01/13/2009

Nice one darq.
In my opinion, both the old way and the suggested way should be available if implemented (like it is with Adobe Flex). This is because some people new to OOP & QCubed might find it easier understanding it the old way i.e:

$this->lblTitle = new QLabel($this);
$this->lblTitle->CssClass = 'panelTitle';
$this->lblTitle->Text = 'Bounces';

While the gurus like you, might find the suggested way nice and handy. I remember how I started using Qcodo. First I used the Generated Objects only, designing my own templates myself, no controls, nothing!, till my confidence soared and I stepped into the full thing. Now I write custom controls, Plugins, custom url routings and whatever is named under the sun :D with Qcubed. So one step @ a time. But I think its a beautiful suggestion there.