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