mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
GCS/core: sort gadgets by name in combobox and options page.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1269 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
487b61473e
commit
c7da7718e2
@ -31,6 +31,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include "icore.h"
|
||||
#include "coreplugin/uavgadgetinstancemanager.h"
|
||||
#include "coreplugin/uavgadgetoptionspagedecorator.h"
|
||||
//#include "coreimpl.h"
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
@ -51,6 +52,27 @@ Q_DECLARE_METATYPE(::PageData)
|
||||
using namespace Core;
|
||||
using namespace Core::Internal;
|
||||
|
||||
// Helpers to sort by category. id
|
||||
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
|
||||
{
|
||||
const UAVGadgetOptionsPageDecorator *gp1 = qobject_cast<const UAVGadgetOptionsPageDecorator*>(p1);
|
||||
const UAVGadgetOptionsPageDecorator *gp2 = qobject_cast<const UAVGadgetOptionsPageDecorator*>(p2);
|
||||
if (gp1 && (gp2 == NULL))
|
||||
return false;
|
||||
if (gp2 && (gp1 == NULL))
|
||||
return true;
|
||||
if (const int cc = QString::localeAwareCompare(p1->trCategory(), p2->trCategory()))
|
||||
return cc < 0;
|
||||
return QString::localeAwareCompare(p1->trName(), p2->trName()) < 0;
|
||||
}
|
||||
|
||||
static inline QList<Core::IOptionsPage*> sortedOptionsPages()
|
||||
{
|
||||
QList<Core::IOptionsPage*> rc = ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
|
||||
qStableSort(rc.begin(), rc.end(), optionsPageLessThan);
|
||||
return rc;
|
||||
}
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
||||
const QString &pageId)
|
||||
: QDialog(parent),
|
||||
@ -93,8 +115,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
||||
|
||||
QMap<QString, QTreeWidgetItem *> categories;
|
||||
|
||||
QList<IOptionsPage*> pages =
|
||||
ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
|
||||
QList<IOptionsPage*> pages = sortedOptionsPages();
|
||||
|
||||
int index = 0;
|
||||
foreach (IOptionsPage *page, pages) {
|
||||
|
@ -86,13 +86,23 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge
|
||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||
QStringList sl = im->classIds();
|
||||
int index = 0;
|
||||
bool startFromOne = false;
|
||||
foreach(QString classId, sl)
|
||||
{
|
||||
if (classId == QString("EmptyGadget")) {
|
||||
m_defaultIndex = 0;
|
||||
startFromOne = true;
|
||||
m_uavGadgetList->insertItem(0, im->gadgetName(classId), classId);
|
||||
m_uavGadgetList->insertSeparator(1);
|
||||
} else {
|
||||
m_uavGadgetList->addItem(im->gadgetName(classId), classId);
|
||||
|
||||
int i = startFromOne ? 1 : 0;
|
||||
for ( ; i < m_uavGadgetList->count(); i++)
|
||||
{
|
||||
if (QString::localeAwareCompare(m_uavGadgetList->itemText(i), im->gadgetName(classId)) > 0)
|
||||
break;
|
||||
}
|
||||
m_uavGadgetList->insertItem(i, im->gadgetName(classId), classId);
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user