Question

I'm using these classes:

QHash: rapresenting all the objects of the scene (cannot modify this class)

QList: rapresenting all the objects selected. It contains IDs (saved as int)

//DrawSelectedObjects(){

QHash<QString, SceneObject*>& hash=sc->getObj();
QList<int> tempList = HitsList;

int counter =0;

for (QHash<QString,SceneObject*>::ConstIterator i = hash.begin();i!=hash.end();++i) {

     if (tempList.startsWith(counter)) {
            .
            Draw_as_selected()
            .
            tempList.removeOne(counter);
     }
}
}

So,for example if I select the object #77,its ID is saved in Hitslist (QList).

After that HitsList is sorted and DrawSelectedObjects() is called.

It has to iterate the QHash until counter=77 and Draw_as_selected(). After that,The first element of the QList is removed, pulling to the front the second one.

This function is called EVERY time one object is selected. With small imported scenes its all ok,but when I'm using files >10MB I can see some output lag (its obvious, because I am iterating through a huge QHash).

Could you suggest me a more efficient way to do this? Any help would be appreciated.

EDIT:

Thank you for your reply.The problem is that I can't get rid of that QList<int> (iI can push only integers on top of OpenGL selection stack).

So another way from the above solution is to do QString.toInt() for every element of the QHash and save them into the QList<int>.

The fact is...how find out the correct QString on the hash using the int (calculated now by conversion from QString, no more from counter) on the QList?

Was it helpful?

Solution

If the way you access objects in the hash is using a QString (I guess the "name" of an object, instead of its ID), then you should also use a list of QString to store the selected objects.

QHash<QString, SceneObject*> & hash = getAllObjects();
QList<QString> & tempList = getSelectedObjects();

foreach(QString name, tempList)
    hash[name]->drawAsSelected(); // or drawAsSelected(hash[name]) depending on your design
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top