1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 22:53:53 +00:00
openmw/apps/opencs/view/world/tableeditidaction.cpp

56 lines
1.8 KiB
C++
Raw Normal View History

#include "tableeditidaction.hpp"
#include <QTableView>
2022-10-19 17:02:00 +00:00
#include <memory>
#include <type_traits>
#include "../../model/world/tablemimedata.hpp"
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/world/columnbase.hpp>
#include <apps/opencs/model/world/universalid.hpp>
CSVWorld::TableEditIdAction::CellData CSVWorld::TableEditIdAction::getCellData(int row, int column) const
{
QModelIndex index = mTable.model()->index(row, column);
if (index.isValid())
{
QVariant display = mTable.model()->data(index, CSMWorld::ColumnBase::Role_Display);
QString value = mTable.model()->data(index).toString();
return std::make_pair(static_cast<CSMWorld::ColumnBase::Display>(display.toInt()), value);
}
return std::make_pair(CSMWorld::ColumnBase::Display_None, "");
}
2022-09-22 18:26:05 +00:00
CSVWorld::TableEditIdAction::TableEditIdAction(const QTableView& table, QWidget* parent)
: QAction(parent)
, mTable(table)
, mCurrentId(CSMWorld::UniversalId::Type_None)
{
}
void CSVWorld::TableEditIdAction::setCell(int row, int column)
{
CellData data = getCellData(row, column);
CSMWorld::UniversalId::Type idType = CSMWorld::TableMimeData::convertEnums(data.first);
if (idType != CSMWorld::UniversalId::Type_None)
{
mCurrentId = CSMWorld::UniversalId(idType, data.second.toUtf8().constData());
setText("Edit '" + data.second + "'");
}
}
CSMWorld::UniversalId CSVWorld::TableEditIdAction::getCurrentId() const
{
return mCurrentId;
}
bool CSVWorld::TableEditIdAction::isValidIdCell(int row, int column) const
{
CellData data = getCellData(row, column);
CSMWorld::UniversalId::Type idType = CSMWorld::TableMimeData::convertEnums(data.first);
2022-09-22 18:26:05 +00:00
return CSMWorld::ColumnBase::isId(data.first) && idType != CSMWorld::UniversalId::Type_None
&& !data.second.isEmpty();
}