mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #617, renamed ActionItem to CActionItem
This commit is contained in:
committed by
Mathew Sutcliffe
parent
372e2cf04b
commit
cf51a7efca
@@ -14,21 +14,21 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
ActionItem::ActionItem(const QString &action, const QString &name, ActionItem *parent) :
|
||||
CActionItem::CActionItem(const QString &action, const QString &name, CActionItem *parent) :
|
||||
m_action(action), m_actionName(name), m_parentItem(parent)
|
||||
{ }
|
||||
|
||||
ActionItem::~ActionItem()
|
||||
CActionItem::~CActionItem()
|
||||
{
|
||||
qDeleteAll(m_childItems);
|
||||
}
|
||||
|
||||
void ActionItem::appendChild(ActionItem *item)
|
||||
void CActionItem::appendChild(CActionItem *item)
|
||||
{
|
||||
m_childItems.append(item);
|
||||
}
|
||||
|
||||
ActionItem *ActionItem::findChildByName(const QString &name) const
|
||||
CActionItem *CActionItem::findChildByName(const QString &name) const
|
||||
{
|
||||
for (auto child : m_childItems)
|
||||
{
|
||||
@@ -37,44 +37,44 @@ namespace BlackGui
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ActionItem *ActionItem::getChildByRow(int row) const
|
||||
CActionItem *CActionItem::getChildByRow(int row) const
|
||||
{
|
||||
return m_childItems.value(row);
|
||||
}
|
||||
|
||||
int ActionItem::getChildCount() const
|
||||
int CActionItem::getChildCount() const
|
||||
{
|
||||
return m_childItems.count();
|
||||
}
|
||||
|
||||
bool ActionItem::hasChildren() const
|
||||
bool CActionItem::hasChildren() const
|
||||
{
|
||||
return getChildCount() > 0;
|
||||
}
|
||||
|
||||
int ActionItem::getColumnCount() const
|
||||
int CActionItem::getColumnCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString ActionItem::getAction() const
|
||||
QString CActionItem::getAction() const
|
||||
{
|
||||
return m_action;
|
||||
}
|
||||
|
||||
QString ActionItem::getActionName() const
|
||||
QString CActionItem::getActionName() const
|
||||
{
|
||||
return m_actionName;
|
||||
}
|
||||
|
||||
ActionItem *ActionItem::getParentItem() const
|
||||
CActionItem *CActionItem::getParentItem() const
|
||||
{
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
int ActionItem::getRow() const
|
||||
int CActionItem::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<CActionItem *>(this)); }
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,23 +20,23 @@ namespace BlackGui
|
||||
namespace Models
|
||||
{
|
||||
//! One single action item in a tree
|
||||
class ActionItem
|
||||
class CActionItem
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
ActionItem(const QString &action, const QString &name, ActionItem *parentItem = nullptr);
|
||||
CActionItem(const QString &action, const QString &name, CActionItem *parentItem = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~ActionItem();
|
||||
~CActionItem();
|
||||
|
||||
//! Append a new child
|
||||
void appendChild(ActionItem *child);
|
||||
void appendChild(CActionItem *child);
|
||||
|
||||
//! Find child by its name
|
||||
ActionItem *findChildByName(const QString &name) const;
|
||||
CActionItem *findChildByName(const QString &name) const;
|
||||
|
||||
//! Get child by row
|
||||
ActionItem *getChildByRow(int row) const;
|
||||
CActionItem *getChildByRow(int row) const;
|
||||
|
||||
//! Number of children
|
||||
int getChildCount() const;
|
||||
@@ -57,13 +57,13 @@ namespace BlackGui
|
||||
int getRow() const;
|
||||
|
||||
//! Get parent item
|
||||
ActionItem *getParentItem() const;
|
||||
CActionItem *getParentItem() const;
|
||||
|
||||
private:
|
||||
QList<ActionItem *> m_childItems;
|
||||
QList<CActionItem *> m_childItems;
|
||||
QString m_action;
|
||||
QString m_actionName;
|
||||
ActionItem *m_parentItem = nullptr;
|
||||
CActionItem *m_parentItem = nullptr;
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BlackGui
|
||||
{
|
||||
CActionModel::CActionModel(QObject *parent) :
|
||||
QAbstractItemModel(parent),
|
||||
m_rootItem(new ActionItem(QString(), QString()))
|
||||
m_rootItem(new CActionItem(QString(), QString()))
|
||||
{
|
||||
setupModelData();
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace BlackGui
|
||||
int CActionModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ?
|
||||
static_cast<ActionItem *>(parent.internalPointer())->getColumnCount() :
|
||||
static_cast<CActionItem *>(parent.internalPointer())->getColumnCount() :
|
||||
m_rootItem->getColumnCount();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace BlackGui
|
||||
{
|
||||
if (!index.isValid()) { return QVariant(); }
|
||||
|
||||
const ActionItem *item = static_cast<ActionItem *>(index.internalPointer());
|
||||
const CActionItem *item = static_cast<CActionItem *>(index.internalPointer());
|
||||
|
||||
if (role == Qt::DisplayRole) { return item->getActionName(); }
|
||||
if (role == ActionRole) { return item->getAction(); }
|
||||
@@ -51,7 +51,7 @@ namespace BlackGui
|
||||
Qt::ItemFlags CActionModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) { return 0; }
|
||||
const ActionItem *item = static_cast<ActionItem *>(index.internalPointer());
|
||||
const CActionItem *item = static_cast<CActionItem *>(index.internalPointer());
|
||||
const Qt::ItemFlags flags = QAbstractItemModel::flags(index);
|
||||
const bool selectable = item && !item->hasChildren(); // only leafs are selectable
|
||||
return selectable ? flags | Qt::ItemIsSelectable : flags & ~Qt::ItemIsSelectable;
|
||||
@@ -61,11 +61,11 @@ namespace BlackGui
|
||||
{
|
||||
if (!hasIndex(row, column, parent)) { return QModelIndex(); }
|
||||
|
||||
const ActionItem *parentItem = parent.isValid() ?
|
||||
static_cast<ActionItem *>(parent.internalPointer()) :
|
||||
const CActionItem *parentItem = parent.isValid() ?
|
||||
static_cast<CActionItem *>(parent.internalPointer()) :
|
||||
m_rootItem.data();
|
||||
|
||||
ActionItem *childItem = parentItem->getChildByRow(row);
|
||||
CActionItem *childItem = parentItem->getChildByRow(row);
|
||||
return childItem ?
|
||||
createIndex(row, column, childItem) :
|
||||
QModelIndex();
|
||||
@@ -75,8 +75,8 @@ namespace BlackGui
|
||||
{
|
||||
if (!index.isValid()) { return {}; }
|
||||
|
||||
ActionItem *childItem = static_cast<ActionItem *>(index.internalPointer());
|
||||
ActionItem *parentItem = childItem->getParentItem();
|
||||
CActionItem *childItem = static_cast<CActionItem *>(index.internalPointer());
|
||||
CActionItem *parentItem = childItem->getParentItem();
|
||||
|
||||
if (parentItem == m_rootItem.data()) { return {}; }
|
||||
|
||||
@@ -85,29 +85,29 @@ namespace BlackGui
|
||||
|
||||
int CActionModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
ActionItem *parentItem;
|
||||
CActionItem *parentItem;
|
||||
if (parent.column() > 0) { return 0; }
|
||||
|
||||
if (!parent.isValid()) { parentItem = m_rootItem.data(); }
|
||||
else { parentItem = static_cast<ActionItem *>(parent.internalPointer()); }
|
||||
else { parentItem = static_cast<CActionItem *>(parent.internalPointer()); }
|
||||
|
||||
return parentItem->getChildCount();
|
||||
}
|
||||
|
||||
void CActionModel::setupModelData()
|
||||
{
|
||||
m_rootItem.reset(new ActionItem(QString(), QString()));
|
||||
m_rootItem.reset(new CActionItem(QString(), QString()));
|
||||
|
||||
for (const auto &actionPath : BlackCore::CInputManager::instance()->allAvailableActions())
|
||||
{
|
||||
const auto tokens = actionPath.split("/", QString::SkipEmptyParts);
|
||||
ActionItem *parentItem = m_rootItem.data();
|
||||
CActionItem *parentItem = m_rootItem.data();
|
||||
for (const auto &token : tokens)
|
||||
{
|
||||
ActionItem *child = parentItem->findChildByName(token);
|
||||
CActionItem *child = parentItem->findChildByName(token);
|
||||
if (child == nullptr)
|
||||
{
|
||||
child = new ActionItem(actionPath, token, parentItem);
|
||||
child = new CActionItem(actionPath, token, parentItem);
|
||||
parentItem->appendChild(child);
|
||||
}
|
||||
Q_ASSERT(child);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
class ActionItem;
|
||||
class CActionItem;
|
||||
|
||||
/*!
|
||||
* Action tree model, used with hotkey actions
|
||||
@@ -69,7 +69,7 @@ namespace BlackGui
|
||||
//! Init model data
|
||||
void setupModelData();
|
||||
|
||||
QScopedPointer<ActionItem> m_rootItem;
|
||||
QScopedPointer<CActionItem> m_rootItem;
|
||||
};
|
||||
}
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user