Play-/Source/ui_unix/ControllerConfig/bindingmodel.cpp

91 lines
1.9 KiB
C++
Raw Normal View History

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