2017-05-23 16:08:53 +01:00
|
|
|
#include "bindingmodel.h"
|
|
|
|
#include "ControllerInfo.h"
|
|
|
|
|
|
|
|
#define CONFIG_PREFIX ("input")
|
|
|
|
#define CONFIG_BINDING_TYPE ("bindingtype")
|
|
|
|
|
|
|
|
CBindingModel::CBindingModel(QObject *parent)
|
|
|
|
:QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CBindingModel::~CBindingModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CBindingModel::rowCount(const QModelIndex & /*parent*/) const
|
|
|
|
{
|
|
|
|
return PS2::CControllerInfo::MAX_BUTTONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CBindingModel::columnCount(const QModelIndex & /*parent*/) const
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CBindingModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
auto binding = m_inputManager->GetBinding(static_cast<PS2::CControllerInfo::BUTTON>(index.row()));
|
|
|
|
if (binding != nullptr)
|
|
|
|
{
|
|
|
|
switch (index.column())
|
|
|
|
{
|
|
|
|
case 0:
|
2017-06-13 04:51:38 +01:00
|
|
|
{
|
|
|
|
std::string str(PS2::CControllerInfo::m_buttonName[index.row()]);
|
|
|
|
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
|
|
|
|
return QVariant(str.c_str());
|
|
|
|
}
|
2017-05-23 16:08:53 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-06-13 04:51:38 +01:00
|
|
|
return QVariant(binding->GetBindingTypeName());
|
2017-05-23 16:08:53 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-06-13 04:51:38 +01:00
|
|
|
return QVariant(binding->GetDescription().c_str());
|
2017-05-23 16:08:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBindingModel::Setup(CInputBindingManager* inputManager)
|
|
|
|
{
|
|
|
|
m_inputManager = inputManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBindingModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
|
|
|
{
|
|
|
|
if (orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
m_h_header.insert(section, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QAbstractTableModel::setHeaderData(section, orientation, value, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CBindingModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
if (section < m_h_header.size())
|
|
|
|
return m_h_header.at(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QAbstractTableModel::headerData(section, orientation, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBindingModel::Refresh()
|
|
|
|
{
|
|
|
|
QAbstractTableModel::layoutChanged();
|
|
|
|
}
|