forked from teamnwah/openmw-tes3coop
Merge remote-tracking branch 'smbas/feature-dialogue-edit-id'
commit
ea1ddb5c9f
@ -0,0 +1,49 @@
|
||||
#include "tableeditidaction.hpp"
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
#include "../../model/world/tablemimedata.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, "");
|
||||
}
|
||||
|
||||
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);
|
||||
return CSMWorld::ColumnBase::isId(data.first) &&
|
||||
idType != CSMWorld::UniversalId::Type_None &&
|
||||
!data.second.isEmpty();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef CSVWORLD_TABLEEDITIDACTION_HPP
|
||||
#define CSVWORLD_TABLEEDITIDACTION_HPP
|
||||
|
||||
#include <QAction>
|
||||
|
||||
#include "../../model/world/columnbase.hpp"
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
class QTableView;
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class TableEditIdAction : public QAction
|
||||
{
|
||||
const QTableView &mTable;
|
||||
CSMWorld::UniversalId mCurrentId;
|
||||
|
||||
typedef std::pair<CSMWorld::ColumnBase::Display, QString> CellData;
|
||||
CellData getCellData(int row, int column) const;
|
||||
|
||||
public:
|
||||
TableEditIdAction(const QTableView &table, QWidget *parent = 0);
|
||||
|
||||
void setCell(int row, int column);
|
||||
|
||||
CSMWorld::UniversalId getCurrentId() const;
|
||||
bool isValidIdCell(int row, int column) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue