2017-05-23 16:08:53 +01:00
|
|
|
#include "bindingmodel.h"
|
|
|
|
#include "ControllerInfo.h"
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
#define CONFIG_PREFIX ("input")
|
|
|
|
#define CONFIG_BINDING_TYPE ("bindingtype")
|
2017-05-23 16:08:53 +01:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
CBindingModel::CBindingModel(QObject* parent)
|
|
|
|
: QAbstractTableModel(parent)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CBindingModel::~CBindingModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
int CBindingModel::rowCount(const QModelIndex& /*parent*/) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
return PS2::CControllerInfo::MAX_BUTTONS;
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
int CBindingModel::columnCount(const QModelIndex& /*parent*/) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
QVariant CBindingModel::data(const QModelIndex& index, int role) const
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(role == Qt::DisplayRole)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
auto binding = m_inputManager->GetBinding(static_cast<PS2::CControllerInfo::BUTTON>(index.row()));
|
2018-04-30 21:01:23 +01:00
|
|
|
if(binding != nullptr)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
switch(index.column())
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
case 0:
|
2018-04-30 21:01:23 +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:
|
2018-04-30 21:01:23 +01:00
|
|
|
return QVariant(binding->GetBindingTypeName());
|
|
|
|
break;
|
2017-05-23 16:08:53 +01:00
|
|
|
case 2:
|
2018-11-19 13:20:46 -05:00
|
|
|
return QVariant(binding->GetDescription(m_inputManager).c_str());
|
2018-04-30 21:01:23 +01:00
|
|
|
break;
|
2017-05-23 16:08:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBindingModel::Setup(CInputBindingManager* inputManager)
|
|
|
|
{
|
|
|
|
m_inputManager = inputManager;
|
|
|
|
}
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
bool CBindingModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(orientation == Qt::Horizontal)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(orientation == Qt::Horizontal)
|
2017-05-23 16:08:53 +01:00
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
2018-04-30 21:01:23 +01:00
|
|
|
if(section < m_h_header.size())
|
2017-05-23 16:08:53 +01:00
|
|
|
return m_h_header.at(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QAbstractTableModel::headerData(section, orientation, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBindingModel::Refresh()
|
|
|
|
{
|
|
|
|
QAbstractTableModel::layoutChanged();
|
|
|
|
}
|