zbenjamin's blog

blog about qt and qxt related stuff

Dienstag, 22. Januar 2008

qxt po module

Hi there,

i know it has been a long time since i wrote my last blog. Sorry for that.
But now i'm back and want to introduce a new module that is currently
more in planning than in an implemented state, but it slowly evolves.
Me and Mark started to work on a module called the PO module. PO means Persistent Objects.
Now some of you will get excited because it seems object persistence is a feature that is really
needed out there. We still need to figure out some basic stuff but i want to show you the current state.

So what does it take to make your objects persistent? Here is the good part: Not much.
The PO module uses the Qt property system to load and save your object dynamically.
So your Objects only need to be derivered from QObject and add a small Macro:

QXT_DECLARE_PERSISTENT(YourObject);

Every Q_PROPERTY in your Object that sets STORED to true is pushed into the Database.
To register a Object with a database you have to create a QxtPOManager:

QxtPOManager manager;
manager.registerPOType < YourFirstObject > ();
manager.registerPOType < YourSecondObject > ();
manager.registerPOType < YourThirdObject > ();

Thats everything. After you did that work your classes are fully useable with the PO module.
The manager will handle load/save/deletetion of your objects.
Well there is still a lot of work to do so don't expect something in the next time. I guess before libqxt 0.3.3 or .0.3.4 there will be nothing useable. But we are working on it and will provide a tarball when there is something to test.
If someone is interested or has expirience with creating peristence frameworks and wants to contribute, post a comment to this blog, write me a mail or join the #qxt channel on irc freenode and just ask.

zbenjamin
"your friendly developer from the neighbourhood"

p.s. the ScheduleView is still in work, but we are currently testing if there is a better way to
implement it.

Montag, 27. August 2007

About locks and validations

Hi there,

last time i added two new classes to Qxt:
  • QxtStringValidator
  • QxtFileLock.

QxtStringValidator was initialliy a class to validate over a QStringList, but this was not really worth to put it into Qxt. So i decided to make it more powerfull. Now it provides a String based validation over a QAbstractItemModel. :


QxtStringValidator validator = new QxtStringValidator();
validator->setLookupModel(myCoolCustomModel);

/*now we have to choose the right column
this will lookup in column 3, starting from row 0
*/
validator->setStartModelIndex(myCoolCustomModel->index(0,3));
//case insensitive lookup
validator->setCaseSensitivity(Qt::CaseInsensitive);
//and now set the validator to a lineEdit
lineEdit->setValidator(validator);

There are some other features like :
  • wrapping lookup
  • case sensitive/insensitive lookup
  • recursive lookups
  • looking up different model rows
And it is also possible to use a QStringList as data source (never forget your roots ;) ).

QxtFileLock is something i had in my mind for a long time since i thought about writing a isam filemanager based on QT. The first thing i realized was that there is no file lock available in Qt. Well it is possible but not using a nice crossplattform class like Qt offers them. So here is my solution for that:


void doSomeOpOnFile()
{
off_t lockStart = 0x10;
off_t lockLength = 20;
QxtFileLock readLock(&file,
lockStart,lockLength,QxtFileLock::ReadLock);
if(readLock.lock())
{
/*do some read operations*/
/*the lock gets cleaned up after it is deleted it is not needed to call unlock()*/
QxtFileLock writeLock (
&file,lockStart,lockLength,QxtFileLock::WriteLock);
if(writeLock.lock())
{
/*do some write operations*/
}
}
/*in this case we don't have to care about releasing the lock. QxtFileLock will do it when the instance is destroyed*/
}

I had to do some extra work on *nix based systems. On *nix a lock does not behave like a normal unix lock. In fact on *nix locks are process wide, means a process can get a lock on a file as often as it wants to. With QxtFileLock this is not possible, locks are threads and handles bound. That means: A Thread can writelock the same region of a file twice only if it uses the SAME handle. If a different handle holds the lock a call to lock() will fail.
On *nix we use fcntl and on windows LockFileEx to implement the locking stuff.

Attention: don't mix QxtFileLock and lockf or flock on linux they are NOT compatible.
Also use only fcntl to lock the files in other apps.

Well i hope these two classes can go into the 0.2.4 release.
Due to vacation and other things i had to do the QxtScheduleView did not make it into the trunk.

zbenjamin
"your friendly developer from the neighbourhood"

Montag, 23. Juli 2007

The raise of QxtScheduleView







After long time of developing (well the real work did not took so long, but there were so much other things to do) i have some working QxtScheduleView class.
I already used it in one of my other apps and it worked nice ;).

Its a plannig app for modelplane shows.The Item Color indicates collisions of the plane's rc - quartz. So yellow indicates it may work, and red ... well i think you know the answer.

Now after i got this stuff working i have to refactor the class and that will take some time.

I'm not shure if i can put QxtScheduleView in the next release of libqxt.
But it will go into trunk in the next weeks. It also lacks all kind of docs so noone will know how to use it.
After i have QxtScheduleView finished for trunk i will start hacking the QxtScheduleWidget . It will have a internal Model and QxtScheduleWidgetItem that will make your life easier.

Well if someone wants to have a look at the current state,
the source can be checked out of my repository:

zbenjamin's sandbox
(https://libqxt.svn.sourceforge.net/svnroot/libqxt/sandbox/zbenjamin/QxtScheduleView/)

cya zbenjamin
"your friendly developer from the neighbourhood"