Entering the c++ era

Moderator: Rathinagiri

Post Reply
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Entering the c++ era

Post by mrduck » Tue Nov 15, 2011 9:11 am

Good morning.

Ricci said:
HMG4 is OOP based and "open" for enhancements of every control without touching the core but using inheritance.
It's perfectly true !

If you google for Qt sample code you will see that the standard way of using Qt is by inheritance. In this way we can override protected and virtual protected c++ methods to allows us to do almost everything.

Unfortunately hbQt doesn't allow us to do this at prg level. Python does, hbQt doesn't.

Qt is a great piece of code. And there are different possibilities to do the same thing. For example, instead of overriding a protected method, you can intercept the event or the signal. Sometimes it is enough, and infact Ricci produced Orchid, and Pritpal the more complex hbide.

But as you can see in hbQt source code, sometimes it is absolutely necessary to override a class in order to expose its methods to harbour VM. I can make examples and explain the whys if you want, but for the moment believe to me, sometimes it is absolutely necessary.

hbQt is quite complete. But is not 100% Qt. There are missing bits. The most notable for us at the moment is the implementation of the one-shot-timer.


So, what I'm trying to do ? Well, I'm trying to implement VALID/WHEN. I did a first implementation more gui-oriented (you can leave the textbox but if valid is false the background turns red) but I was requested to try to implement a more clipper-compliant VALID: if it is .F. you can't leave the field.
And since I'm not succesful in my tast at harbour level, I started trying to add c++ inheritance...

I don't know if this will solve my problems, but I should try. It will help in other situations...

What changes for HMG4 users ? Nothing, since they are using a precompiled library.

What changes for HMG4 developers ?
- have Qt SDK installed
- have harbour source code installed

And if you are a serious HMG4 core code developers you should have them installed anyway ! Qt SDK is required to compile hbQt anyway....

So, in my tests, in textbox.prg
instead of

Code: Select all

::oQtObject := QLineEdit()
we will have

Code: Select all

::oQtObject := hmgQLineEdit()
and this class will have extended functionality...

And let the other Ricci phrase come true:
When using HMG3 you always have to think "What is possible?", with HMG4 you can think "What do I want to do?"

User avatar
Rathinagiri
Posts: 5262
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 167 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Tue Nov 15, 2011 10:30 am

I agree with you Francesco. My doubt is, whether this deviation from hbQT can be done whenever required ie. along with hbQT?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Post by mrduck » Tue Nov 15, 2011 10:33 am

rathinagiri wrote:I agree with you Francesco. My doubt is, whether this deviation from hbQT can be done whenever required ie. along with hbQT?
Once tested, something can be committed back to hbQt, like the one-time-shot timer.

But others changes, like the one for VALID/WHEN implementation, are not a "simple layer above hbQt" but change hbQt/Qt inner workings... but if the changes show to be useful to others, yes, they can be ported to hbQt.

First of all, we should see if the proof-of-concept code I'm writing works or not... ;-)

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Tue Nov 15, 2011 8:19 pm

Hi MrDuck....
When I start to use HMG3 I learn a lot about Xbase; when HMG4 was started I starting to learn about OOP.

In this few days, as I write to you, I found a way to use better some Qt events: FocusIn and FocusOut.
With a good usage of them I can use TAB, SHIFT+TAB, ENTER to move around widgets on a form, known the current widget, the current form and who has the focus. To test this, I write a simple TEXTBOX object and I get satisfaction: I managed strings (without mask, but with upper/lower or right align), numbers (without mask, but with right align) and date (this with mask based on the current _SET_DATEFORMAT).

Anyway, about you post....

A) I think you don't think only to change the names of methods......(sorry if I played with words)

At the same time, we know many internal vars are (or can be considered) unusefull with HbQt usage (Roberto: I know there is a basic concept because these vars were born).
For example take a look to abstractslider.prg and see nRangeMin: with HbQt usage it's unusefull, because we can use QTobject:minimum() to get value and QTObject:setMinimum() to set (Nokia developpers/users have the same problems)
These internal vars are dangerous because (can be) used in a wrong way. For example about dial.prg. There was the lNotch var (at class definition time setted to .T.), but when the dial object was created you was not seeing any notches, because QTObject:setNotchesVisible( ::lNtoch) was not used.... I removed var (unusefull) and coded QTObject:setNotchesVisible( .T.) by default. B) I think you don't think about these problems......

I'm a great newbe. Could you please help me to understand your pow?

1) About parent system, do you think to preserve it?

2) There are many "simple" objects, for example Label. I'm in agreement with you that can be HmgLabel() and we can use HmgLabel():setText() or HmgLabel():text() to set or know value. In this way we access to Qt model.
But there are many complicated objects: for example the last one that I have rewrited (combobox) or many other - very complicated - like textbox, grid and so on. Can you give me a little example or idea about someone of these?

Why these questions? Because my wish is to have a good ended library and with this library I want write end programs. Like HMG3 or more powerfull. I don't want customizing parts o more code (I'm thinking about textbox editing system).
And many of HMG3 users like a defined library and "simple".

As you know, I'm an idealist and I hope that those who read and use HMGx libraries, sometimes make a contribution with source code. For example: I wish to use drag and drop between combobox. Is there someone had experience with drag and drop? Can give is contribute in this direction?

Many times I write you: I'm not a great technician. Please, put a lot of patience and try to understand me!

Many thanks for you help.

Cheers
Luigi from Italy
www.L3W.it

Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Post by Ricci » Tue Nov 15, 2011 9:44 pm

l3whmg wrote:I wish to use drag and drop between combobox. Is there someone had experience with drag and drop?
Only with the "drop" part, this is easy.

Your plan is to move one element from the combobox list to another combobox via drag and drop, is this what you want?

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Post by mrduck » Tue Nov 15, 2011 11:21 pm

Luigi, no, I don't want to do any of the thing you describe

Please look at the sample I put in my message:

So, in my tests, in textbox.prg instead of

Code: Select all

::oQtObject := QLineEdit()
we will have

Code: Select all

		
::oQtObject := hmgQLineEdit()
and this class will have extended functionality...

Please note that I'm subclassing QT widgets, not hmg4...

Why should be able to do this ? several reasons, I try to explain again:
a - adding methods not present in hbQt
b - be able to access c++ protected and virtual protected methods from prg code
and the last
c - because it's months I wanted to try to do it... :-)
c bis - because 99% of the docs we find on Qt are for c++ language or for Python were you can use Qt like from c++ (there is a full layer)

a)
hbQt is built on Qt4.5. In a few weeks Qt4.8 will be released. This means that hbQt will (should) work on systems that have later versions but you can't use the new features. For example I would like to implement QLineEdit:setPlaceholderText.
Or implement the one-shot-timer. I can commit the one-shot-timer to hbQT main code since it's supported in Qt4.5 and it is only badly implemented, but I can't commit setPlaceholderText.
HBQTableView at the basis of VGRID is a nice piece of code but I think it can be better designed to better suit our needs. For example now if you want to subclass VGRID onQuery, you have to copy a lot of code... instead of having a big switch statement, we should have several different specialized methods so that we may override the ones we need to change...
Would you give a party for this tomorrow ? No, I don't think so, but later we may discover that with better organized and modularized code we have more power in our hands !
And please remember I don't want to change the Qt methods, I want to add NEW methods/values to EXPAND functionality (that must be specifically enabled)... so you will have the best of both worlds: full Qt compliance, possibility to expand using prg code.
b)
I know your work on TAB/BACKTAB. And I see you are working with FocusIn/FocusOut events... Good ! It works ! No problem with your code at all.
If you read docs about events you may read that there are 5 places where you can "intercept" them ( http://doc.qt.nokia.com/qq/qq11-events.html section "Event Handling and Filtering" )
There are five "levels" of event dispatching and sometimes some events are intercepted in the first stages and not visible to the the levels we have access to.

I tried to use focusIn/focusOut to simulate a VALID. Success was partial. There may be flow in my logic, of course, so I ask you to expand your test program with this:
create a form with 5 textbox(), called A B C D E.
B and D have a VALID that always returns .F. so, in any way you enter B or D you won't be allowed to exit from the textbox.
Then please set a debug message (HB_TRACE or a row in a listbox or a textfile), on onGetFocus of A B C D E and onLostFocus of A C E (B and D you may have the debug message too but also code to forbid exiting the widget).
I repeat, my code can be flawed, so I don't add anything. Please try to move in any direction with TAB/BACKTAB AND CLICKING ON WIDGETS !
Enter widget B in any way and then click on C, on D where you want, set focus on another window then click on different widgets in the test windos, please test different combinations !
Then tell me what you see in the logs.
Ricci, please have a try you too!

I had problems in achieving what should be standard to achieve... and probably I saw a way to do it subclassing Qt QLineEdit and try to intercept events earlier. I'm probably wrong too but then:

c and c-bis)
I just wanted to do this... :-) I wanted to be able to use setPlaceholderText, to test some nice features I see on the internet, to do what Ricci said "what I need to do with HMG4" ?

So, finally, to answer your questions: you are off-track. And I hope I explained above better my idea.

I can summarize:
Imagine that the code in BITMAP():__HmgUpdateImage can be made really easier using a QLabel [virtual] protected method.... In order to "expose" the method at prg level it is mandatory by c++ (due to virtual protected rules) to subclass. So I subclass c++ QLabel into c++ hmgQLabel to which I add the methods and so I'm finally able to create the harbour level class hmgQLabel and expose the methods.
Of course in BITMAP I now have to to oQtObject := hmgQLabel() if I want to use these new methods...

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Wed Nov 16, 2011 8:54 am

Hi
for Ricci: yes :mrgreen:

MrDuck: I'm thinking :roll:

Cheers
Luigi from Italy
www.L3W.it

Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Post by Ricci » Wed Nov 16, 2011 9:48 pm

l3whmg wrote: for Ricci: yes :mrgreen:
I didn´t get it to work but this may help you: http://www.informit.com/articles/article.aspx?p=1405546 (2nd part of the article).

User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Post by l3whmg » Thu Nov 17, 2011 8:59 am

Thanks, I'll read it.
Cheers
Luigi from Italy
www.L3W.it

Post Reply