diff --git a/src/blackmisc/icon.cpp b/src/blackmisc/icon.cpp index 1f4001cd9..665094e5e 100644 --- a/src/blackmisc/icon.cpp +++ b/src/blackmisc/icon.cpp @@ -7,7 +7,8 @@ * contained in the LICENSE file. */ -#include "icon.h" +#include "blackmisc/icon.h" +#include "blackmisc/iconlist.h" #include "blackmisc/pq/angle.h" namespace BlackMisc @@ -47,4 +48,17 @@ namespace BlackMisc return s; } + const CIcon &CIcon::iconByIndex(CIcons::IconIndex index) + { + return iconByIndex(static_cast(index)); + } + + const CIcon &CIcon::iconByIndex(int index) + { + // changed to index / at based approach during #322 (after Sleepy profiling) + // this seems to be faster as the findBy approach previously used, but required synced indexes + Q_ASSERT_X(index >= 0 && index < CIconList::allIcons().size(), "iconForIndex", "wrong index"); + return CIconList::allIcons()[index]; + } + } // namespace diff --git a/src/blackmisc/icon.h b/src/blackmisc/icon.h index 1ca9ef7c2..6ba277766 100644 --- a/src/blackmisc/icon.h +++ b/src/blackmisc/icon.h @@ -67,6 +67,12 @@ namespace BlackMisc //! \copydoc CValueObject::convertToQString virtual QString convertToQString(bool i18n = false) const override; + //! Icon for given index + static const CIcon &iconByIndex(CIcons::IconIndex index); + + //! Icon for given index + static const CIcon &iconByIndex(int index); + private: BLACK_ENABLE_TUPLE_CONVERSION(CIcon) int m_index = static_cast(CIcons::NotSet); diff --git a/src/blackmisc/iconlist.cpp b/src/blackmisc/iconlist.cpp index a8162c43c..80b350084 100644 --- a/src/blackmisc/iconlist.cpp +++ b/src/blackmisc/iconlist.cpp @@ -151,14 +151,11 @@ namespace BlackMisc const CIcon &CIconList::iconByIndex(CIcons::IconIndex index) { - return iconByIndex(static_cast(index)); + return CIcon::iconByIndex(index); } const CIcon &CIconList::iconByIndex(int index) { - // changed to index / at based approach during #322 (after Sleepy profiling) - // this seems to be faster as the findBy approach previously used, but required synced indexes - Q_ASSERT_X(index >= 0 && index < allIcons().size(), "iconForIndex", "wrong index"); - return allIcons()[index]; + return CIcon::iconByIndex(index); } } diff --git a/src/blackmisc/iconlist.h b/src/blackmisc/iconlist.h index 1261dd208..0a9b4727f 100644 --- a/src/blackmisc/iconlist.h +++ b/src/blackmisc/iconlist.h @@ -46,11 +46,12 @@ namespace BlackMisc static const CIconList &allIcons(); //! Icon for given index + //! \deprecated Use CIcon::iconByIndex instead. static const CIcon &iconByIndex(CIcons::IconIndex index); //! Icon for given index + //! \deprecated Use CIcon::iconByIndex instead. static const CIcon &iconByIndex(int index); - }; }