refs #413 Moved iconByIndex method from CIconList to CIcon, to reduce coupling.

This commit is contained in:
Mathew Sutcliffe
2015-05-04 20:23:27 +01:00
parent d476c9b709
commit 03707db182
4 changed files with 25 additions and 7 deletions

View File

@@ -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<int>(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

View File

@@ -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<int>(CIcons::NotSet);

View File

@@ -151,14 +151,11 @@ namespace BlackMisc
const CIcon &CIconList::iconByIndex(CIcons::IconIndex index)
{
return iconByIndex(static_cast<int>(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);
}
}

View File

@@ -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);
};
}