refs #617, ActionItem const correctness

This commit is contained in:
Klaus Basan
2017-02-04 00:55:13 +01:00
committed by Mathew Sutcliffe
parent d5a926bd4e
commit 372e2cf04b
2 changed files with 18 additions and 17 deletions

View File

@@ -8,18 +8,15 @@
*/ */
#include "blackgui/models/actionitem.h" #include "blackgui/models/actionitem.h"
#include <QtAlgorithms> #include <QtAlgorithms>
namespace BlackGui namespace BlackGui
{ {
namespace Models namespace Models
{ {
ActionItem::ActionItem(const QString &action, const QString &name, ActionItem *parent) : ActionItem::ActionItem(const QString &action, const QString &name, ActionItem *parent) :
m_action(action), m_actionName(name), m_parentItem(parent) m_action(action), m_actionName(name), m_parentItem(parent)
{ { }
}
ActionItem::~ActionItem() ActionItem::~ActionItem()
{ {
@@ -31,7 +28,7 @@ namespace BlackGui
m_childItems.append(item); m_childItems.append(item);
} }
ActionItem *ActionItem::findChildByName(const QString &name) ActionItem *ActionItem::findChildByName(const QString &name) const
{ {
for (auto child : m_childItems) for (auto child : m_childItems)
{ {
@@ -40,7 +37,7 @@ namespace BlackGui
return nullptr; return nullptr;
} }
ActionItem *ActionItem::getChildByRow(int row) ActionItem *ActionItem::getChildByRow(int row) const
{ {
return m_childItems.value(row); return m_childItems.value(row);
} }
@@ -50,6 +47,11 @@ namespace BlackGui
return m_childItems.count(); return m_childItems.count();
} }
bool ActionItem::hasChildren() const
{
return getChildCount() > 0;
}
int ActionItem::getColumnCount() const int ActionItem::getColumnCount() const
{ {
return 1; return 1;
@@ -65,7 +67,7 @@ namespace BlackGui
return m_actionName; return m_actionName;
} }
ActionItem *ActionItem::getParentItem() ActionItem *ActionItem::getParentItem() const
{ {
return m_parentItem; return m_parentItem;
} }
@@ -73,9 +75,7 @@ namespace BlackGui
int ActionItem::getRow() const int ActionItem::getRow() const
{ {
if (m_parentItem) { return m_parentItem->m_childItems.indexOf(const_cast<ActionItem *>(this)); } if (m_parentItem) { return m_parentItem->m_childItems.indexOf(const_cast<ActionItem *>(this)); }
return 0; return 0;
} }
} }
} }

View File

@@ -19,7 +19,6 @@ namespace BlackGui
{ {
namespace Models namespace Models
{ {
//! One single action item in a tree //! One single action item in a tree
class ActionItem class ActionItem
{ {
@@ -34,14 +33,17 @@ namespace BlackGui
void appendChild(ActionItem *child); void appendChild(ActionItem *child);
//! Find child by its name //! Find child by its name
ActionItem *findChildByName(const QString &name); ActionItem *findChildByName(const QString &name) const;
//! Get child by row //! Get child by row
ActionItem *getChildByRow(int row); ActionItem *getChildByRow(int row) const;
//! Number of childs //! Number of children
int getChildCount() const; int getChildCount() const;
//! Has children?
bool hasChildren() const;
//! Number of columns //! Number of columns
int getColumnCount() const; int getColumnCount() const;
@@ -55,16 +57,15 @@ namespace BlackGui
int getRow() const; int getRow() const;
//! Get parent item //! Get parent item
ActionItem *getParentItem(); ActionItem *getParentItem() const;
private: private:
QList<ActionItem *> m_childItems; QList<ActionItem *> m_childItems;
QString m_action; QString m_action;
QString m_actionName; QString m_actionName;
ActionItem *m_parentItem; ActionItem *m_parentItem = nullptr;
}; };
} }
} } // ns
#endif // guard #endif // guard