mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-27 16:54:15 +01:00
OP-781: cleaned up; added comments; removed some debug code; fixed tabs
into spaces
This commit is contained in:
parent
87632e6e13
commit
d0447b5e06
@ -126,10 +126,9 @@ 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;
|
||||||
|
QTreeWidgetItem *initialItem = 0;
|
||||||
foreach (IOptionsPage *page, pages) {
|
foreach (IOptionsPage *page, pages) {
|
||||||
PageData pageData;
|
PageData pageData;
|
||||||
pageData.index = index;
|
pageData.index = index;
|
||||||
@ -143,9 +142,6 @@ 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
|
||||||
@ -174,12 +170,10 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
|
|
||||||
m_pages.append(page);
|
m_pages.append(page);
|
||||||
|
|
||||||
// creating all option pages upfront is slow, so we create placeholder widgets instead
|
// creating all option pages upfront is slow, so we create place holder widgets instead
|
||||||
// the real option page widget will be created later when the user selects it
|
// 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...
|
// the place holder is a QLabel and we assume that no option page will be a QLabel...
|
||||||
QLabel * placeholderWidget = new QLabel(stackedPages);
|
QLabel * placeholderWidget = new QLabel(stackedPages);
|
||||||
placeholderWidget->setText("page placeholder");
|
|
||||||
// add widget
|
|
||||||
stackedPages->addWidget(placeholderWidget);
|
stackedPages->addWidget(placeholderWidget);
|
||||||
|
|
||||||
if (page->id() == initialPage && currentCategory == initialCategory) {
|
if (page->id() == initialPage && currentCategory == initialCategory) {
|
||||||
@ -199,20 +193,13 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "initialItem: " << initialItem;
|
|
||||||
if (initialItem) {
|
if (initialItem) {
|
||||||
qDebug() << "initialItem text: " << initialItem->text(0);
|
if (!initialItem->parent()) {
|
||||||
qDebug() << "initialItem selected: " << initialItem->isSelected();
|
// item has no parent, meaning it is single child
|
||||||
qDebug() << "initialItem parent: " << initialItem->parent();
|
// so select category item instead as single child are not added to the tree
|
||||||
if (!initialItem->parent()) {
|
initialItem = categories.value(initialCategory);
|
||||||
// item has no parent, meaning it is single child
|
}
|
||||||
// so select category item instead
|
pageTree->setCurrentItem(initialItem);
|
||||||
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;
|
||||||
@ -229,11 +216,11 @@ SettingsDialog::~SettingsDialog()
|
|||||||
QList<QTreeWidgetItem *> *categoryItemList = m_categoryItemsMap.value(category);
|
QList<QTreeWidgetItem *> *categoryItemList = m_categoryItemsMap.value(category);
|
||||||
delete categoryItemList;
|
delete categoryItemList;
|
||||||
}
|
}
|
||||||
// delete placeholders
|
// delete place holders
|
||||||
for(int i = 0; i < stackedPages->count(); i++) {
|
for (int i = 0; i < stackedPages->count(); i++) {
|
||||||
QLabel * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
QLabel * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
if (widget) {
|
if (widget) {
|
||||||
delete widget;
|
delete widget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,7 +228,6 @@ SettingsDialog::~SettingsDialog()
|
|||||||
void SettingsDialog::pageSelected()
|
void SettingsDialog::pageSelected()
|
||||||
{
|
{
|
||||||
QTreeWidgetItem *item = pageTree->currentItem();
|
QTreeWidgetItem *item = pageTree->currentItem();
|
||||||
qDebug() << "pageSelected: " << item;
|
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -249,15 +235,15 @@ 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
|
// check if we are looking at a place holder or not
|
||||||
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(index));
|
QWidget *widget = dynamic_cast<QLabel*>(stackedPages->widget(index));
|
||||||
if (widget) {
|
if (widget) {
|
||||||
// get rid of placeholder
|
// place holder found, get rid of it...
|
||||||
stackedPages->removeWidget(widget);
|
stackedPages->removeWidget(widget);
|
||||||
delete widget;
|
delete widget;
|
||||||
// insert real page
|
// and replace place holder with actual option page
|
||||||
IOptionsPage *page = m_pages.at(index);
|
IOptionsPage *page = m_pages.at(index);
|
||||||
stackedPages->insertWidget(index, page->createPage(stackedPages));
|
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
|
||||||
@ -344,41 +330,39 @@ void SettingsDialog::disableApplyOk(bool disable)
|
|||||||
|
|
||||||
void SettingsDialog::accept()
|
void SettingsDialog::accept()
|
||||||
{
|
{
|
||||||
m_applied = true;
|
m_applied = true;
|
||||||
for(int i = 0; i < m_pages.size(); i++) {
|
for (int i = 0; i < m_pages.size(); i++) {
|
||||||
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
IOptionsPage * page = m_pages.at(i);
|
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)
|
for (int i = 0; i < m_pages.size(); i++) {
|
||||||
for(int i = 0; i < m_pages.size(); i++) {
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
if (!widget) {
|
||||||
if (!widget) {
|
IOptionsPage * page = m_pages.at(i);
|
||||||
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)
|
for (int i = 0; i < m_pages.size(); i++) {
|
||||||
for(int i = 0; i < m_pages.size(); i++) {
|
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
||||||
QWidget * widget = dynamic_cast<QLabel*>(stackedPages->widget(i));
|
if (!widget) {
|
||||||
if (!widget) {
|
IOptionsPage * page = m_pages.at(i);
|
||||||
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