Fixed several issues detected during testing / review (refs #304)

* MS report 1-5 https://dev.vatsim-germany.org/issues/304#change-1800
* Clang warning https://dev.vatsim-germany.org/boards/22/topics/1982?r=1997#message-1997
* Wrong indexes for dockable widgets, RW: https://dev.vatsim-germany.org/issues/304#note-13
* Fixed wrong offset in Fsuipc class
* Improved position handling for floating widgets opened 1st time
This commit is contained in:
Klaus Basan
2014-08-05 18:31:22 +02:00
parent 3c12cd7b30
commit 600ea2b803
15 changed files with 127 additions and 127 deletions

View File

@@ -310,8 +310,7 @@ namespace BlackCore
// warnings, if required // warnings, if required
if (!illegalIcaoCodes.isEmpty()) if (!illegalIcaoCodes.isEmpty())
{ {
const QString w = QString("Illegal ICAO code(s) in VATSIM data file: %1").arg(illegalIcaoCodes.join(", ")); qWarning() << "Illegal ICAO code(s) in VATSIM data file:" << illegalIcaoCodes.join(", ");
qWarning(w.toLatin1());
} }
} }
} }

View File

@@ -43,7 +43,6 @@ namespace BlackGui
this->connectAllWidgets(); this->connectAllWidgets();
this->setFeaturesForDockableWidgets(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable); this->setFeaturesForDockableWidgets(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable);
this->tabifyAllWidgets(); this->tabifyAllWidgets();
this->setPreferredSizesWhenFloating();
// context menu // context menu
this->setContextMenuPolicy(Qt::CustomContextMenu); this->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -103,7 +102,7 @@ namespace BlackGui
subMenuDisplay->addAction(displayMenuAction); subMenuDisplay->addAction(displayMenuAction);
c = connect(displayMenuAction, SIGNAL(triggered(bool)), signalMapperDisplay, SLOT(map())); c = connect(displayMenuAction, SIGNAL(triggered(bool)), signalMapperDisplay, SLOT(map()));
Q_ASSERT(c); Q_ASSERT(c);
signalMapperDisplay->setMapping(displayMenuAction, i); signalMapperDisplay->setMapping(displayMenuAction, i); // action to index
} }
c = connect(signalMapperToggleFloating, SIGNAL(mapped(int)), this, SLOT(toggleFloating(int))); c = connect(signalMapperToggleFloating, SIGNAL(mapped(int)), this, SLOT(toggleFloating(int)));
Q_ASSERT(c); Q_ASSERT(c);
@@ -187,10 +186,8 @@ namespace BlackGui
void CMainInfoAreaComponent::adjustSizeForAllDockWidgets() void CMainInfoAreaComponent::adjustSizeForAllDockWidgets()
{ {
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
CDockWidgetInfoArea *dw = (*i);
dw->adjustSize(); dw->adjustSize();
} }
} }
@@ -199,11 +196,18 @@ namespace BlackGui
{ {
// I fake the double click here, which queues the events in the queue // I fake the double click here, which queues the events in the queue
// and hence fires all depending signals in order // and hence fires all depending signals in order
if (!this->m_tabBar) return; // if (!this->m_tabBar) return;
for (int i = 0; i < this->m_tabBar->count(); i++) // for (int i = 0; i < this->m_tabBar->count(); i++)
// {
// // emit this->m_tabBar->tabBarDoubleClicked(i);
// this->toggleFloating(i);
// }
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{ {
emit this->m_tabBar->tabBarDoubleClicked(i); if (dw->isFloating()) continue;
dw->toggleFloating();
} }
} }
void CMainInfoAreaComponent::toggleFloating() void CMainInfoAreaComponent::toggleFloating()
@@ -259,10 +263,8 @@ namespace BlackGui
void CMainInfoAreaComponent::ps_setDockArea(Qt::DockWidgetArea area) void CMainInfoAreaComponent::ps_setDockArea(Qt::DockWidgetArea area)
{ {
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
CDockWidgetInfoArea *dw = (*i);
Qt::DockWidgetAreas newAreas = static_cast<Qt::DockWidgetAreas>(area); Qt::DockWidgetAreas newAreas = static_cast<Qt::DockWidgetAreas>(area);
Qt::DockWidgetAreas oldAreas = dw->allowedAreas(); Qt::DockWidgetAreas oldAreas = dw->allowedAreas();
if (oldAreas == newAreas) continue; if (oldAreas == newAreas) continue;
@@ -273,6 +275,7 @@ namespace BlackGui
void CMainInfoAreaComponent::ps_setInfoAreaFloating(bool floating) void CMainInfoAreaComponent::ps_setInfoAreaFloating(bool floating)
{ {
// float whole info area
this->m_infoAreaFloating = floating; this->m_infoAreaFloating = floating;
if (this->m_infoAreaFloating) if (this->m_infoAreaFloating)
{ {
@@ -297,9 +300,7 @@ namespace BlackGui
{ {
// this->setDockArea(Qt::LeftDockWidgetArea); // this->setDockArea(Qt::LeftDockWidgetArea);
this->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::East); this->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::East);
bool init = this->m_tabBar ? false : true; bool init = this->m_tabBar ? false : true;
QPoint pos = CGuiUtility::assumedMainWindowPosition(); //main window pos. not initialized yet
if (!this->m_dockableWidgets.isEmpty()) if (!this->m_dockableWidgets.isEmpty())
{ {
@@ -310,15 +311,17 @@ namespace BlackGui
Q_ASSERT(after); Q_ASSERT(after);
// trick, init widget as floating // trick, init widget as floating
// this completely initializes the tab bar and all docked widgets
if (init) if (init)
{ {
QPoint initPoint(pos.rx() + i * 25, pos.ry() + i * 20); QPoint offset(i * 25, i * 20);
after->setVisible(false); after->setVisible(false);
after->setFloating(true); after->setFloating(true);
after->move(initPoint); after->setOffsetWhenFloating(offset);
after->setPreferredSizeWhenFloating(CMainInfoAreaComponent::getPreferredSizeWhenFloating(static_cast<InfoArea>(i)));
after->setFloating(false); after->setFloating(false);
after->resetWasAlreadyFLoating();
after->setVisible(true); after->setVisible(true);
after->resetWasAlreadyFLoating();
} }
else else
{ {
@@ -339,7 +342,8 @@ namespace BlackGui
this->m_tabBar->setObjectName("comp_MainInfoAreaDockWidgetTab"); this->m_tabBar->setObjectName("comp_MainInfoAreaDockWidgetTab");
this->m_tabBar->setMovable(false); this->m_tabBar->setMovable(false);
this->m_tabBar->setElideMode(Qt::ElideNone); this->m_tabBar->setElideMode(Qt::ElideNone);
this->setDocumentMode(true); this->setDocumentMode(true); // did not notice any effect
this->setTabPixmaps();
// East / West does not work (shown, but area itself empty) // East / West does not work (shown, but area itself empty)
// South does not have any effect // South does not have any effect
@@ -347,7 +351,6 @@ namespace BlackGui
connect(this->m_tabBar, &QTabBar::tabBarDoubleClicked, this, &CMainInfoAreaComponent::ps_tabBarDoubleClicked); connect(this->m_tabBar, &QTabBar::tabBarDoubleClicked, this, &CMainInfoAreaComponent::ps_tabBarDoubleClicked);
} }
this->setTabPixmaps();
if (this->countDockedWidgets() > 0) if (this->countDockedWidgets() > 0)
{ {
this->m_tabBar->setCurrentIndex(0); this->m_tabBar->setCurrentIndex(0);
@@ -368,57 +371,50 @@ namespace BlackGui
void CMainInfoAreaComponent::connectAllWidgets() void CMainInfoAreaComponent::connectAllWidgets()
{ {
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
connect(*i, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CMainInfoAreaComponent::ps_onWidgetTopLevelChanged); connect(dw, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CMainInfoAreaComponent::ps_onWidgetTopLevelChanged);
} }
} }
void CMainInfoAreaComponent::setMarginsWhenFloating(int left, int top, int right, int bottom) void CMainInfoAreaComponent::setMarginsWhenFloating(int left, int top, int right, int bottom)
{ {
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
//! Margins when window is floating //! Margins when window is floating
(*i)->setMarginsWhenFloating(left, top, right, bottom); dw->setMarginsWhenFloating(left, top, right, bottom);
} }
} }
void CMainInfoAreaComponent::setMarginsWhenDocked(int left, int top, int right, int bottom) void CMainInfoAreaComponent::setMarginsWhenDocked(int left, int top, int right, int bottom)
{ {
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
//! Margins when window is floating //! Margins when window is docked
(*i)->setMarginsWhenDocked(left, top, right, bottom); dw->setMarginsWhenDocked(left, top, right, bottom);
} }
} }
void CMainInfoAreaComponent::setPreferredSizesWhenFloating() QSize CMainInfoAreaComponent::getPreferredSizeWhenFloating(InfoArea area)
{ {
if (this->m_dockableWidgets.isEmpty()) return; switch (area)
for (int i = 0; i < this->m_dockableWidgets.size(); i++)
{ {
InfoArea ia = static_cast<InfoArea>(i); case InfoAreaAircrafts:
switch (ia) case InfoAreaAtc:
{ case InfoAreaUsers:
case InfoAreaAircrafts: case InfoAreaLog:
case InfoAreaAtc: case InfoAreaSimulator:
case InfoAreaUsers: return QSize(400, 300);
case InfoAreaLog: break;
case InfoAreaSimulator: case InfoAreaMappings:
this->m_dockableWidgets[i]->setPreferredSizeWhenFloating(QSize(400, 300)); case InfoAreaSettings:
break; case InfoAreaTextMessages:
case InfoAreaMappings: case InfoAreaFlightPlan:
case InfoAreaSettings: return QSize(600, 400);
case InfoAreaTextMessages: break;
case InfoAreaFlightPlan: default:
this->m_dockableWidgets[i]->setPreferredSizeWhenFloating(QSize(600, 400)); return QSize(400, 300);
break; break;
default:
break;
}
} }
} }
@@ -451,34 +447,31 @@ namespace BlackGui
} }
} }
CDockWidgetInfoArea *CMainInfoAreaComponent::getDockableWidgetByIndex(int index) const
{
if (index >= this->m_dockableWidgets.count() || index < 0) return nullptr;
return this->m_dockableWidgets.at(index);
}
CDockWidgetInfoArea *CMainInfoAreaComponent::selectedDockableWidget() const
{
if (!this->m_tabBar) return nullptr;
int i = this->m_tabBar->currentIndex();
return getDockableWidgetByIndex(i);
}
int CMainInfoAreaComponent::countDockedWidgets() const int CMainInfoAreaComponent::countDockedWidgets() const
{ {
if (!this->m_tabBar) return 0; if (!this->m_tabBar) return 0;
return this->m_tabBar->count(); return this->m_tabBar->count();
} }
CDockWidgetInfoArea *CMainInfoAreaComponent::getDockableWidgetByTabIndex(int tabBarIndex) const
{
if (tabBarIndex >= this->m_dockableWidgets.count() || tabBarIndex < 0) return nullptr;
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
if (dw->isFloating()) continue; // not in tab bar
if (tabBarIndex == 0) return dw;
tabBarIndex--;
}
return nullptr;
}
int CMainInfoAreaComponent::widgetToTabBarIndex(const CDockWidgetInfoArea *dockWidget) int CMainInfoAreaComponent::widgetToTabBarIndex(const CDockWidgetInfoArea *dockWidget)
{ {
if (!dockWidget) return -1; if (!dockWidget) return -1;
if (dockWidget->isFloating()) return -1; if (dockWidget->isFloating()) return -1;
int tabBarIndex = 0; int tabBarIndex = 0;
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
CDockWidgetInfoArea *dw = (*i);
if (dw->isFloating()) continue; // not in tab bar if (dw->isFloating()) continue; // not in tab bar
if (dw == dockWidget) return tabBarIndex; if (dw == dockWidget) return tabBarIndex;
tabBarIndex++; tabBarIndex++;
@@ -488,9 +481,8 @@ namespace BlackGui
void CMainInfoAreaComponent::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features) void CMainInfoAreaComponent::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features)
{ {
for (int i = 0; i < this->m_dockableWidgets.size(); i++) for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{ {
CDockWidgetInfoArea *dw = this->m_dockableWidgets.at(i);
dw->setFeatures(features); dw->setFeatures(features);
} }
} }
@@ -506,11 +498,9 @@ namespace BlackGui
} }
} }
void CMainInfoAreaComponent::ps_tabBarDoubleClicked(int index) void CMainInfoAreaComponent::ps_tabBarDoubleClicked(int tabBarIndex)
{ {
CDockWidgetInfoArea *dw = (index >= 0) ? CDockWidgetInfoArea *dw = this->getDockableWidgetByTabIndex(tabBarIndex);
this->getDockableWidgetByIndex(index) :
this->selectedDockableWidget();
if (!dw) return; if (!dw) return;
dw->toggleFloating(); dw->toggleFloating();
} }
@@ -529,7 +519,6 @@ namespace BlackGui
{ {
QString qss = CStyleSheetUtility::instance().style(CStyleSheetUtility::fileNameMainInfoArea()); QString qss = CStyleSheetUtility::instance().style(CStyleSheetUtility::fileNameMainInfoArea());
this->setStyleSheet(qss); this->setStyleSheet(qss);
if (this->m_tabBar) if (this->m_tabBar)
{ {
QString qss = CStyleSheetUtility::instance().style(CStyleSheetUtility::fileNameDockWidgetTab()); QString qss = CStyleSheetUtility::instance().style(CStyleSheetUtility::fileNameDockWidgetTab());
@@ -551,10 +540,8 @@ namespace BlackGui
{ {
if (show == this->m_showTabTexts) return; if (show == this->m_showTabTexts) return;
this->m_showTabTexts = show; this->m_showTabTexts = show;
QList<CDockWidgetInfoArea *>::iterator i; for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
{ {
CDockWidgetInfoArea *dw = (*i);
dw->showTitleWhenDocked(show); dw->showTitleWhenDocked(show);
} }
} }

View File

@@ -139,11 +139,8 @@ namespace BlackGui
//! Corresponding dockable widgets //! Corresponding dockable widgets
QList<CDockWidgetInfoArea *> dockableWidgets() const; QList<CDockWidgetInfoArea *> dockableWidgets() const;
//! Corresponding dockable widget //! Corresponding dockable widget for given tab index
CDockWidgetInfoArea *getDockableWidgetByIndex(int index) const; CDockWidgetInfoArea *getDockableWidgetByTabIndex(int tabBarIndex) const;
//! Selected dockable widget
CDockWidgetInfoArea *selectedDockableWidget() const;
//! Features of the dockable widgets //! Features of the dockable widgets
void setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features); void setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features);
@@ -167,14 +164,14 @@ namespace BlackGui
void setMarginsWhenDocked(int left, int top, int right, int bottom); void setMarginsWhenDocked(int left, int top, int right, int bottom);
//! Set window sizes when floating //! Set window sizes when floating
void setPreferredSizesWhenFloating(); static QSize getPreferredSizeWhenFloating(InfoArea area);
//! Info area to icon //! Info area to icon
static const QPixmap &infoAreaToPixmap(InfoArea infoArea); static const QPixmap &infoAreaToPixmap(InfoArea infoArea);
private slots: private slots:
//! Tab bar has been double clicked //! Tab bar has been double clicked
void ps_tabBarDoubleClicked(int index); void ps_tabBarDoubleClicked(int tabBarIndex);
//! A widget has changed its top level //! A widget has changed its top level
void ps_onWidgetTopLevelChanged(CDockWidget *widget, bool topLevel); void ps_onWidgetTopLevelChanged(CDockWidget *widget, bool topLevel);

View File

@@ -33,7 +33,7 @@ namespace BlackGui
this->ui->tvp_LiveData->addOrUpdateByName(name, value, icon); this->ui->tvp_LiveData->addOrUpdateByName(name, value, icon);
} }
void CSimulatorComponent::addOrUpdateByName(const QString &name, const QString &value, CIcons::IconIndexes iconIndex) void CSimulatorComponent::addOrUpdateByName(const QString &name, const QString &value, CIcons::IconIndex iconIndex)
{ {
this->addOrUpdateByName(name, value, CIconList::iconForIndex(iconIndex)); this->addOrUpdateByName(name, value, CIconList::iconForIndex(iconIndex));
} }

View File

@@ -39,7 +39,7 @@ namespace BlackGui
void addOrUpdateByName(const QString &name, const QString &value, const BlackMisc::CIcon &icon); void addOrUpdateByName(const QString &name, const QString &value, const BlackMisc::CIcon &icon);
//! Simple add or update name / value pair //! Simple add or update name / value pair
void addOrUpdateByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndexes iconIndex); void addOrUpdateByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex);
//! Number of entries //! Number of entries
int rowCount() const; int rowCount() const;

View File

@@ -10,6 +10,7 @@
#include "dockwidget.h" #include "dockwidget.h"
#include "blackmisc/icons.h" #include "blackmisc/icons.h"
#include "blackgui/stylesheetutility.h" #include "blackgui/stylesheetutility.h"
#include "blackgui/guiutility.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QStyleOption> #include <QStyleOption>
#include <QPainter> #include <QPainter>
@@ -126,6 +127,15 @@ namespace BlackGui
{ {
this->resize(this->m_preferredSizeWhenFloating); this->resize(this->m_preferredSizeWhenFloating);
} }
// and move
QPoint mainWindowPos = BlackGui::CGuiUtility::mainWindowPosition();
if (!mainWindowPos.isNull())
{
int x = mainWindowPos.x() + this->m_offsetWhenFloating.x();
int y = mainWindowPos.y() + this->m_offsetWhenFloating.y();
this->move(x, y);
}
} }
this->m_wasAlreadyFloating = true; this->m_wasAlreadyFloating = true;
} }

View File

@@ -66,9 +66,12 @@ namespace BlackGui
//! Was widget already floating //! Was widget already floating
bool wasAlreadyFloating() const { return this->m_wasAlreadyFloating; } bool wasAlreadyFloating() const { return this->m_wasAlreadyFloating; }
//! Size when floating //! Size when floating first time
void setPreferredSizeWhenFloating(const QSize &size) { this->m_preferredSizeWhenFloating = size; } void setPreferredSizeWhenFloating(const QSize &size) { this->m_preferredSizeWhenFloating = size; }
//! Position offset when floating first time
void setOffsetWhenFloating(const QPoint &point) { this->m_offsetWhenFloating = point; }
public slots: public slots:
//! Toggle floating //! Toggle floating
void toggleFloating(); void toggleFloating();
@@ -109,7 +112,8 @@ namespace BlackGui
QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes
bool m_windowTitleWhenDocked = true; bool m_windowTitleWhenDocked = true;
bool m_wasAlreadyFloating = false; bool m_wasAlreadyFloating = false;
QSize m_preferredSizeWhenFloating; QSize m_preferredSizeWhenFloating; //!< preferred size men floating 1st time
QPoint m_offsetWhenFloating; //!< initial offset to main window when floating first time
//! Empty widget with no size //! Empty widget with no size
void initTitleBarWidgets(); void initTitleBarWidgets();

View File

@@ -21,38 +21,48 @@ namespace BlackGui
this->read(); this->read();
} }
const QString CStyleSheetUtility::fontStyleAsString(const QFont &font) const QString &CStyleSheetUtility::fontStyleAsString(const QFont &font)
{ {
static const QString n("normal");
static const QString i("italic");
static const QString o("oblique");
static const QString e;
switch (font.style()) switch (font.style())
{ {
case QFont::StyleNormal: return "normal"; case QFont::StyleNormal: return n;
case QFont::StyleItalic: return "italic"; case QFont::StyleItalic: return i;
case QFont::StyleOblique: return "oblique"; case QFont::StyleOblique: return o;
default: return ""; default: return e;
} }
} }
const QString CStyleSheetUtility::fontWeightAsString(const QFont &font) const QString &CStyleSheetUtility::fontWeightAsString(const QFont &font)
{ {
if (font.weight() < static_cast<int>(QFont::Normal)) if (font.weight() < static_cast<int>(QFont::Normal))
{ {
return "light"; static const QString l("light");
return l;
} }
else if (font.weight() < static_cast<int>(QFont::DemiBold)) else if (font.weight() < static_cast<int>(QFont::DemiBold))
{ {
return "normal"; static const QString n("normal");
return n;
} }
else if (font.weight() < static_cast<int>(QFont::Bold)) else if (font.weight() < static_cast<int>(QFont::Bold))
{ {
return "demibold"; static const QString d("demibold");
return d;
} }
else if (font.weight() < static_cast<int>(QFont::Black)) else if (font.weight() < static_cast<int>(QFont::Black))
{ {
return "bold"; static const QString b("bold");
return b;
} }
else else
{ {
return "black"; static const QString b("black");
return b;
} }
} }

View File

@@ -96,10 +96,10 @@ namespace BlackGui
explicit CStyleSheetUtility(QObject *parent = nullptr); explicit CStyleSheetUtility(QObject *parent = nullptr);
//! Font style as string //! Font style as string
static const QString fontStyleAsString(const QFont &font); static const QString &fontStyleAsString(const QFont &font);
//! Font weight as string //! Font weight as string
static const QString fontWeightAsString(const QFont &font); static const QString &fontWeightAsString(const QFont &font);
}; };
} }

View File

@@ -28,7 +28,7 @@ namespace BlackMisc
CIcon() {} CIcon() {}
//! Constructor. //! Constructor.
CIcon(CIcons::IconIndexes index, const QString &descriptiveText) : CIcon( CIcons::IconIndex index, const QString &descriptiveText) :
m_index(static_cast<int>(index)), m_descriptiveText(descriptiveText) {} m_index(static_cast<int>(index)), m_descriptiveText(descriptiveText) {}
//! \copydoc CValueObject::toQVariant //! \copydoc CValueObject::toQVariant
@@ -38,7 +38,7 @@ namespace BlackMisc
const QString &getDescriptiveText() const { return this->m_descriptiveText; } const QString &getDescriptiveText() const { return this->m_descriptiveText; }
//! Index //! Index
CIcons::IconIndexes getIndex() const { return static_cast<CIcons::IconIndexes>(this->m_index);} CIcons::IconIndex getIndex() const { return static_cast< CIcons::IconIndex>(this->m_index);}
//! Corresponding pixmap //! Corresponding pixmap
QPixmap toPixmap() const; QPixmap toPixmap() const;

View File

@@ -15,7 +15,7 @@ namespace BlackMisc
CSequence<CIcon>(other) CSequence<CIcon>(other)
{ } { }
CIcon CIconList::findByIndex(CIcons::IconIndexes index) const CIcon CIconList::findByIndex(CIcons::IconIndex index) const
{ {
return this->findBy(&CIcon::getIndex, index).frontOrDefault(); return this->findBy(&CIcon::getIndex, index).frontOrDefault();
} }

View File

@@ -34,7 +34,7 @@ namespace BlackMisc
CIconList(const CSequence<CIcon> &other); CIconList(const CSequence<CIcon> &other);
//! Find by index //! Find by index
CIcon findByIndex(CIcons::IconIndexes index) const; CIcon findByIndex(CIcons::IconIndex index) const;
//! \copydoc CValueObject::asQVariant //! \copydoc CValueObject::asQVariant
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
@@ -126,24 +126,18 @@ namespace BlackMisc
} }
//! Icon for given index //! Icon for given index
static const CIcon &iconForIndex(CIcons::IconIndexes index) static const CIcon &iconForIndex(CIcons::IconIndex index)
{ {
// remark, find by is copy, need reference of icon auto foundRange = allIcons().findBy(&CIcon::getIndex, index);
int s = allIcons().size(); if (!foundRange.isEmpty()) { return foundRange.front(); }
for (int i = 0; i < s; i++)
{
if (allIcons()[i].getIndex() == index)
{
return allIcons()[i];
}
}
Q_ASSERT_X(false, "iconForIndex", "Missing index"); Q_ASSERT_X(false, "iconForIndex", "Missing index");
return iconForIndex(CIcons::StandardIconUnknown16); return iconForIndex(CIcons::StandardIconUnknown16);
} }
//! Icon for given index //! Icon for given index
static const CIcon &iconForIndex(int index) { static const CIcon &iconForIndex(int index)
return iconForIndex(static_cast<CIcons::IconIndexes>(index)); {
return iconForIndex(static_cast<CIcons::IconIndex>(index));
} }
}; };

View File

@@ -19,14 +19,13 @@ namespace BlackMisc
//! Standard icons //! Standard icons
class CIcons class CIcons
{ {
private:
//! Constructor, use class static only
CIcons();
public: public:
//! Constructor, use class static only
CIcons() = delete;
//! Index for each icon, allows to send them via DBus, efficiently store them, etc. //! Index for each icon, allows to send them via DBus, efficiently store them, etc.
enum IconIndexes enum IconIndex
{ {
NotSet, NotSet,
StandardIconInfo16, StandardIconInfo16,
@@ -606,7 +605,7 @@ namespace BlackMisc
// ------------------------------------------------------------- // -------------------------------------------------------------
//! Pixmap by given index //! Pixmap by given index
static const QPixmap &pixmapByIndex(IconIndexes index) static const QPixmap &pixmapByIndex(IconIndex index)
{ {
switch (index) switch (index)
{ {
@@ -687,7 +686,7 @@ namespace BlackMisc
} }
//! Pixmap by given index rotated //! Pixmap by given index rotated
static QPixmap pixmapByIndex(IconIndexes index, int rotateDegrees) static QPixmap pixmapByIndex(IconIndex index, int rotateDegrees)
{ {
const QPixmap original = pixmapByIndex(index); const QPixmap original = pixmapByIndex(index);
if (rotateDegrees == 0) return original; if (rotateDegrees == 0) return original;

View File

@@ -154,7 +154,7 @@ namespace BlackMisc
case IndexIcon: case IndexIcon:
if (variant.canConvert<int>()) if (variant.canConvert<int>())
{ {
CIcons::IconIndexes index = static_cast<CIcons::IconIndexes>(variant.toInt()); CIcons::IconIndex index = static_cast<CIcons::IconIndex>(variant.toInt());
this->m_icon = CIconList::iconForIndex(index); this->m_icon = CIconList::iconForIndex(index);
} }
else else

View File

@@ -126,7 +126,7 @@ namespace BlackSimPlugin
// COM Settings, transponder, SB3 // COM Settings, transponder, SB3
FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult) && FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult) &&
FSUIPC_Read(0x7b92, 1, &xpdrIdentSb3Raw, &dwResult) && FSUIPC_Read(0x7b93, 1, &xpdrIdentSb3Raw, &dwResult) &&
// Speeds, situation // Speeds, situation
FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult) && FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult) &&