mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-24 02:10:39 +00:00
Tablemimedata able to handle vector of objects and return icon.
This commit is contained in:
parent
423b2906be
commit
3439940a8e
2 changed files with 56 additions and 12 deletions
|
@ -1,22 +1,64 @@
|
||||||
#include "tablemimedata.hpp"
|
#include "tablemimedata.hpp"
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
CSMWorld::TableMimeData::TableMimeData (UniversalId id) :
|
CSMWorld::TableMimeData::TableMimeData (UniversalId id)
|
||||||
mUniversalId(id)
|
|
||||||
{
|
{
|
||||||
mSupportedFormats << QString::fromStdString("application/Type_" + id.getTypeName());
|
mUniversalId.push_back(id);
|
||||||
|
mObjectsFormats << QString::fromStdString("application/Type_" + id.getTypeName());
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id)
|
||||||
|
{
|
||||||
|
mUniversalId = id;
|
||||||
|
for (std::vector<UniversalId>::iterator it(mUniversalId.begin()); it != mUniversalId.end(); ++it)
|
||||||
|
{
|
||||||
|
mObjectsFormats << QString::fromStdString("application/Type_" + it->getTypeName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CSMWorld::TableMimeData::formats() const
|
QStringList CSMWorld::TableMimeData::formats() const
|
||||||
{
|
{
|
||||||
return QMimeData::formats();
|
return mObjectsFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::TableMimeData::~TableMimeData()
|
CSMWorld::TableMimeData::~TableMimeData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::UniversalId& CSMWorld::TableMimeData::getId()
|
CSMWorld::UniversalId CSMWorld::TableMimeData::getId(unsigned int index) const
|
||||||
{
|
{
|
||||||
return mUniversalId;
|
if (mUniversalId.empty())
|
||||||
|
{
|
||||||
|
throw("TableMimeData holds no UniversalId");
|
||||||
|
}
|
||||||
|
return mUniversalId[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CSMWorld::TableMimeData::getIcon() const
|
||||||
|
{
|
||||||
|
if (mUniversalId.empty())
|
||||||
|
{
|
||||||
|
throw("TableMimeData holds no UniversalId");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string tmpIcon;
|
||||||
|
bool firstIteration = true;
|
||||||
|
for (unsigned i = 0; i < mUniversalId.size(); ++i)
|
||||||
|
{
|
||||||
|
if (firstIteration)
|
||||||
|
{
|
||||||
|
firstIteration = false;
|
||||||
|
tmpIcon = mUniversalId[i].getIcon();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmpIcon != mUniversalId[i].getIcon())
|
||||||
|
{
|
||||||
|
return ""; //should return multiple types icon, but at the moment we don't have one
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpIcon = mUniversalId[i].getIcon();
|
||||||
|
}
|
||||||
|
return mUniversalId.begin()->getIcon(); //All objects are of the same type;
|
||||||
}
|
}
|
|
@ -4,27 +4,29 @@
|
||||||
#ifndef TABLEMIMEDATA_H
|
#ifndef TABLEMIMEDATA_H
|
||||||
#define TABLEMIMEDATA_H
|
#define TABLEMIMEDATA_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <qt4/QtCore/QMimeData>
|
#include <qt4/QtCore/QMimeData>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
class QStringList;
|
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class UniversalId;
|
|
||||||
class TableMimeData : public QMimeData
|
class TableMimeData : public QMimeData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TableMimeData(UniversalId id);
|
TableMimeData(UniversalId id);
|
||||||
|
TableMimeData(std::vector<UniversalId>& id);
|
||||||
~TableMimeData();
|
~TableMimeData();
|
||||||
virtual QStringList formats() const;
|
virtual QStringList formats() const;
|
||||||
UniversalId& getId();
|
UniversalId getId(unsigned int index) const;
|
||||||
|
std::string getIcon() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList mSupportedFormats;
|
std::vector<UniversalId> mUniversalId;
|
||||||
UniversalId mUniversalId;
|
QStringList mObjectsFormats;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // TABLEMIMEDATA_H
|
#endif // TABLEMIMEDATA_H
|
||||||
|
|
Loading…
Reference in a new issue