PDA

View Full Version : dec int to HEX



gyre
30th December 2007, 19:52
Hi ...
I have implemented a model through which I display using the view some numbers...
I would need something that could enable me to switch from the decimal view of them to the hex view...the problem is that I have implemented also sortfilterproxy model so I would need when the hex view is enabled to make filter model filtrate by the hex numbers and when decimal view then by decimal numbers...
Is it possible to do something like that ?
THX

marcel
30th December 2007, 19:58
Yes, you can add a flag in your model which tells it what to return to the view: decimal or hex.

You can set that flag in higher levels(from the view or main class of your app) by casting the model() returned by the view to the appropriate class.

gyre
31st December 2007, 06:27
Yes, you can add a flag in your model which tells it what to return to the view: decimal or hex.
Well this I understood...


You can set that flag in higher levels(from the view or main class of your app) by casting the model() returned by the view to the appropriate class.
This I did not at all :)...what did you mean by casting the model ?

marcel
31st December 2007, 11:33
I have implemented a model through which I display using the view some numbers...
This means you subclassed QAbstractItemModel(or one of its subclasses).
QAbstractItemView::model() returns a QAbstractItemModel.
Therefore, if your model is called MyCustomModel, in order to access specific methods of this type, you must cast the QAbstractItemModel returned by model() to MyCustomModel.
For example, you can do this in the view:


MyCustomModel * myModel = dynamic_cast<MyCustomModel*>(model());
if(myModel)
{
myModel->setMode(decOrHex); //switch to one of the two display modes
}
...

jpn
31st December 2007, 13:05
MyCustomModel * myModel = dynamic_cast<MyCustomModel*>(model());
if (myModel)
myModel->setMode(MyCustomModel::DecimalDisplay); //switch to decimal
else
myModel->setMode(MyCustomModel::HexDisplay); //switch to hex
...

Oops, Marcel. There's a nasty little bug. ;)

marcel
31st December 2007, 13:10
Oops, Marcel. There's a nasty little bug. ;)
Happy New Year! :)

jpn
31st December 2007, 13:48
Happy New Year! :)
You too, buddy. And of course, everyone else on this forum! Cheers! ;)