zaphod.b
28th July 2010, 15:13
Hi all,
to give you an idea of what I am trying to do:
My application loads a bunch of perspective plugins. Each perspective provides an action to activate itself. All actions are added to a QActionGroup that resides inside PerspectiveManager. Before the actions are presented in a toolbar, they need to be sorted.
I am not able to sort the list of actions as provided by QActionGroup::actions(). So far, I tend to relate my problem to the iterator's const-ness, but I may be mistaken. Please have a look:
QToolBar *PerspectiveManager::toolBar()
{
//version 1 -- This doesn't sort:
//QAlgorithmsPrivate::qSortHelper(..) returns immediately
//due to RandomAccessIterator end < RandomAccessIterator start
qSort(actionGroup_.actions().begin(),
actionGroup_.actions().end(),
sortOrder);
//version 2 -- "Force non-const iterator" (?)
//This enters sortOrder(..), but QAction *one and two
//are not accessible there
QList<QAction*>::iterator it1 = actionGroup_.actions().begin();
QList<QAction*>::iterator it2 = actionGroup_.actions().end();
qSort(it1,
it2,
sortOrder);
toolBar_.clear();
toolBar_.addActions(actionGroup_.actions());
return &toolBar_;
}
//Not called when trying to sort as in version 1
bool PerspectiveManager::sortOrder(QAction *one, QAction *two)
{
//demonstrate that one and two are not accessible in version 2
//(running into SIGSEGV)
QString s1(one->text());
QString s2(two->text());
//sorting shall be done via meta object system
bool b = //one is somehow "less than" two
return b;
}
Bad thing is, I had it running in mock code, but am not getting there again... :confused:
Thanks for you consideration!
to give you an idea of what I am trying to do:
My application loads a bunch of perspective plugins. Each perspective provides an action to activate itself. All actions are added to a QActionGroup that resides inside PerspectiveManager. Before the actions are presented in a toolbar, they need to be sorted.
I am not able to sort the list of actions as provided by QActionGroup::actions(). So far, I tend to relate my problem to the iterator's const-ness, but I may be mistaken. Please have a look:
QToolBar *PerspectiveManager::toolBar()
{
//version 1 -- This doesn't sort:
//QAlgorithmsPrivate::qSortHelper(..) returns immediately
//due to RandomAccessIterator end < RandomAccessIterator start
qSort(actionGroup_.actions().begin(),
actionGroup_.actions().end(),
sortOrder);
//version 2 -- "Force non-const iterator" (?)
//This enters sortOrder(..), but QAction *one and two
//are not accessible there
QList<QAction*>::iterator it1 = actionGroup_.actions().begin();
QList<QAction*>::iterator it2 = actionGroup_.actions().end();
qSort(it1,
it2,
sortOrder);
toolBar_.clear();
toolBar_.addActions(actionGroup_.actions());
return &toolBar_;
}
//Not called when trying to sort as in version 1
bool PerspectiveManager::sortOrder(QAction *one, QAction *two)
{
//demonstrate that one and two are not accessible in version 2
//(running into SIGSEGV)
QString s1(one->text());
QString s2(two->text());
//sorting shall be done via meta object system
bool b = //one is somehow "less than" two
return b;
}
Bad thing is, I had it running in mock code, but am not getting there again... :confused:
Thanks for you consideration!