mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-781: initial commit for slow Option Dialog creation fix; fix consists
in lazilly creating option pages when user selects them instead of creating them all upfront. Dummy placeholder widget (QLabel) are initially created instead of the real option page; this commit also fixes a minor issue where the left tree selection would not be in sync with the displayed option page (see Jira for more details).
This commit is contained in:
parent
54c459627d
commit
87632e6e13
@ -38,6 +38,7 @@
|
|||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
#include <QtGui/QHeaderView>
|
#include <QtGui/QHeaderView>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
|
#include <QtGui/QLabel>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct PageData {
|
struct PageData {
|
||||||
@ -91,10 +92,12 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
#endif
|
#endif
|
||||||
QString initialCategory = categoryId;
|
QString initialCategory = categoryId;
|
||||||
QString initialPage = pageId;
|
QString initialPage = pageId;
|
||||||
|
qDebug() << "SettingsDialog constructor initial category: " << initialCategory << ", initial page: " << initialPage;
|
||||||
if (initialCategory.isEmpty() && initialPage.isEmpty()) {
|
if (initialCategory.isEmpty() && initialPage.isEmpty()) {
|
||||||
QSettings *settings = ICore::instance()->settings();
|
QSettings *settings = ICore::instance()->settings();
|
||||||
initialCategory = settings->value("General/LastPreferenceCategory", QVariant(QString())).toString();
|
initialCategory = settings->value("General/LastPreferenceCategory", QVariant(QString())).toString();
|
||||||
initialPage = settings->value("General/LastPreferencePage", QVariant(QString())).toString();
|
initialPage = settings->value("General/LastPreferencePage", QVariant(QString())).toString();
|
||||||
|
qDebug() << "SettingsDialog settings initial category: " << initialCategory << ", initial page: " << initialPage;
|
||||||
m_windowWidth = settings->value("General/SettingsWindowWidth", 0).toInt();
|
m_windowWidth = settings->value("General/SettingsWindowWidth", 0).toInt();
|
||||||
m_windowHeight = settings->value("General/SettingsWindowHeight", 0).toInt();
|
m_windowHeight = settings->value("General/SettingsWindowHeight", 0).toInt();
|
||||||
}
|
}
|
||||||
@ -123,6 +126,8 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
|
|
||||||
QList<IOptionsPage*> pages = sortedOptionsPages();
|
QList<IOptionsPage*> pages = sortedOptionsPages();
|
||||||
|
|
||||||
|
QTreeWidgetItem *initialItem = 0;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
bool firstUavGadgetOptionsPageFound = false;
|
bool firstUavGadgetOptionsPageFound = false;
|
||||||
foreach (IOptionsPage *page, pages) {
|
foreach (IOptionsPage *page, pages) {
|
||||||
@ -138,6 +143,9 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
QString trCategories = page->trCategory();
|
QString trCategories = page->trCategory();
|
||||||
QString currentCategory = page->category();
|
QString currentCategory = page->category();
|
||||||
|
|
||||||
|
//qDebug() << "currentCategory: " << currentCategory;
|
||||||
|
//qDebug() << "page id: " << page->id();
|
||||||
|
|
||||||
QTreeWidgetItem *categoryItem;
|
QTreeWidgetItem *categoryItem;
|
||||||
if (!categories.contains(currentCategory)) {
|
if (!categories.contains(currentCategory)) {
|
||||||
// Above the first gadget option we insert a separator
|
// Above the first gadget option we insert a separator
|
||||||
@ -165,11 +173,17 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
categoryItemList->append(item);
|
categoryItemList->append(item);
|
||||||
|
|
||||||
m_pages.append(page);
|
m_pages.append(page);
|
||||||
stackedPages->addWidget(page->createPage(stackedPages));
|
|
||||||
|
// creating all option pages upfront is slow, so we create placeholder widgets instead
|
||||||
|
// the real option page widget will be created later when the user selects it
|
||||||
|
// the placeholder is a QLabel and we assume that no option page will be a QLabel...
|
||||||
|
QLabel * placeholderWidget = new QLabel(stackedPages);
|
||||||
|
placeholderWidget->setText("page placeholder");
|
||||||
|
// add widget
|
||||||
|
stackedPages->addWidget(placeholderWidget);
|
||||||
|
|
||||||
if (page->id() == initialPage && currentCategory == initialCategory) {
|
if (page->id() == initialPage && currentCategory == initialCategory) {
|
||||||
stackedPages->setCurrentIndex(stackedPages->count());
|
initialItem = item;
|
||||||
pageTree->setCurrentItem(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
@ -185,6 +199,22 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "initialItem: " << initialItem;
|
||||||
|
if (initialItem) {
|
||||||
|
qDebug() << "initialItem text: " << initialItem->text(0);
|
||||||
|
qDebug() << "initialItem selected: " << initialItem->isSelected();
|
||||||
|
qDebug() << "initialItem parent: " << initialItem->parent();
|
||||||
|
if (!initialItem->parent()) {
|
||||||
|
// item has no parent, meaning it is single child
|
||||||
|
// so select category item instead
|
||||||
|
initialItem = categories.value(initialCategory);
|
||||||
|
qDebug() << "initialItem text: " << initialItem->text(0);
|
||||||
|
qDebug() << "initialItem selected: " << initialItem->isSelected();
|
||||||
|
qDebug() << "initialItem parent: " << initialItem->parent();
|
||||||
|
}
|
||||||
|
pageTree->setCurrentItem(initialItem);
|
||||||
|
}
|
||||||
|
|
||||||
QList<int> sizes;
|
QList<int> sizes;
|
||||||
sizes << 150 << 300;
|
sizes << 150 << 300;
|
||||||
splitter->setSizes(sizes);
|
splitter->setSizes(sizes);
|
||||||
@ -199,11 +229,19 @@ SettingsDialog::~SettingsDialog()
|
|||||||
QList<QTreeWidgetItem *> *categoryItemList = m_categoryItemsMap.value(category);
|
QList<QTreeWidgetItem *> *categoryItemList = m_categoryItemsMap.value(category);
|
||||||
delete categoryItemList;
|
delete categoryItemList;
|
||||||
}
|
}
|
||||||
|
// delete placeholders
|
||||||
|
for(int i = 0; i < stackedPages->count(); i++) {
|
||||||
|
QLabel * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
|
if (widget) {
|
||||||
|
delete widget;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::pageSelected()
|
void SettingsDialog::pageSelected()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = pageTree->currentItem();
|
QTreeWidgetItem *item = pageTree->currentItem();
|
||||||
|
qDebug() << "pageSelected: " << item;
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -211,6 +249,16 @@ void SettingsDialog::pageSelected()
|
|||||||
int index = data.index;
|
int index = data.index;
|
||||||
m_currentCategory = data.category;
|
m_currentCategory = data.category;
|
||||||
m_currentPage = data.id;
|
m_currentPage = data.id;
|
||||||
|
// check if we are looking at a placeholder or not
|
||||||
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(index));
|
||||||
|
if (widget) {
|
||||||
|
// get rid of placeholder
|
||||||
|
stackedPages->removeWidget(widget);
|
||||||
|
delete widget;
|
||||||
|
// insert real page
|
||||||
|
IOptionsPage *page = m_pages.at(index);
|
||||||
|
stackedPages->insertWidget(index, page->createPage(stackedPages));
|
||||||
|
}
|
||||||
stackedPages->setCurrentIndex(index);
|
stackedPages->setCurrentIndex(index);
|
||||||
// If user selects a toplevel item, select the first child for them
|
// If user selects a toplevel item, select the first child for them
|
||||||
// I.e. Top level items are not really selectable
|
// I.e. Top level items are not really selectable
|
||||||
@ -297,26 +345,40 @@ void SettingsDialog::disableApplyOk(bool disable)
|
|||||||
void SettingsDialog::accept()
|
void SettingsDialog::accept()
|
||||||
{
|
{
|
||||||
m_applied = true;
|
m_applied = true;
|
||||||
foreach (IOptionsPage *page, m_pages) {
|
for(int i = 0; i < m_pages.size(); i++) {
|
||||||
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
|
if (!widget) {
|
||||||
|
IOptionsPage * page = m_pages.at(i);
|
||||||
page->apply();
|
page->apply();
|
||||||
page->finish();
|
page->finish();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
done(QDialog::Accepted);
|
done(QDialog::Accepted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::reject()
|
void SettingsDialog::reject()
|
||||||
{
|
{
|
||||||
foreach (IOptionsPage *page, m_pages)
|
// foreach (IOptionsPage *page, m_pages)
|
||||||
|
for(int i = 0; i < m_pages.size(); i++) {
|
||||||
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
|
if (!widget) {
|
||||||
|
IOptionsPage * page = m_pages.at(i);
|
||||||
page->finish();
|
page->finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
done(QDialog::Rejected);
|
done(QDialog::Rejected);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsDialog::apply()
|
void SettingsDialog::apply()
|
||||||
{
|
{
|
||||||
foreach (IOptionsPage *page, m_pages)
|
// foreach (IOptionsPage *page, m_pages)
|
||||||
|
for(int i = 0; i < m_pages.size(); i++) {
|
||||||
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
|
if (!widget) {
|
||||||
|
IOptionsPage * page = m_pages.at(i);
|
||||||
page->apply();
|
page->apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
m_applied = true;
|
m_applied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user