forked from teamnwah/openmw-tes3coop
update preview on reference/referenceable changes
This commit is contained in:
parent
2128d3008c
commit
10ce47938b
4 changed files with 139 additions and 32 deletions
|
@ -4,36 +4,55 @@
|
||||||
#include <OgreSceneManager.h>
|
#include <OgreSceneManager.h>
|
||||||
|
|
||||||
#include "../../model/world/data.hpp"
|
#include "../../model/world/data.hpp"
|
||||||
|
#include "../../model/world/idtable.hpp"
|
||||||
|
|
||||||
void CSVRender::PreviewWidget::setup (const std::string& id)
|
void CSVRender::PreviewWidget::setup()
|
||||||
{
|
{
|
||||||
setNavigation (&mOrbit);
|
setNavigation (&mOrbit);
|
||||||
|
|
||||||
int column = mData.getReferenceables().findColumnIndex (CSMWorld::Columns::ColumnId_Model);
|
|
||||||
|
|
||||||
int row = mData.getReferenceables().getIndex (id);
|
|
||||||
|
|
||||||
QVariant value = mData.getReferenceables().getData (row, column);
|
|
||||||
|
|
||||||
if (!value.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::string model = value.toString().toUtf8().constData();
|
|
||||||
|
|
||||||
if (model.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
mNode = getSceneManager()->getRootSceneNode()->createChildSceneNode();
|
mNode = getSceneManager()->getRootSceneNode()->createChildSceneNode();
|
||||||
mNode->setPosition (Ogre::Vector3 (0, 0, 0));
|
mNode->setPosition (Ogre::Vector3 (0, 0, 0));
|
||||||
|
|
||||||
mObject = NifOgre::Loader::createObjects (mNode, "Meshes\\" + model);
|
setModel();
|
||||||
|
|
||||||
|
QAbstractItemModel *referenceables =
|
||||||
|
mData.getTableModel (CSMWorld::UniversalId::Type_Referenceables);
|
||||||
|
|
||||||
|
connect (referenceables, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
||||||
|
this, SLOT (ReferenceableDataChanged (const QModelIndex&, const QModelIndex&)));
|
||||||
|
connect (referenceables, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||||
|
this, SLOT (ReferenceableAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVRender::PreviewWidget::adjust (const std::string& id)
|
void CSVRender::PreviewWidget::setModel()
|
||||||
{
|
{
|
||||||
if (mNode)
|
if (mNode)
|
||||||
{
|
{
|
||||||
int row = mData.getReferences().getIndex (id);
|
mObject.setNull();
|
||||||
|
|
||||||
|
int column = mData.getReferenceables().findColumnIndex (CSMWorld::Columns::ColumnId_Model);
|
||||||
|
|
||||||
|
int row = mData.getReferenceables().getIndex (mReferenceableId);
|
||||||
|
|
||||||
|
QVariant value = mData.getReferenceables().getData (row, column);
|
||||||
|
|
||||||
|
if (!value.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string model = value.toString().toUtf8().constData();
|
||||||
|
|
||||||
|
if (model.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
mObject = NifOgre::Loader::createObjects (mNode, "Meshes\\" + model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PreviewWidget::adjust()
|
||||||
|
{
|
||||||
|
if (mNode)
|
||||||
|
{
|
||||||
|
int row = mData.getReferences().getIndex (mReferenceId);
|
||||||
|
|
||||||
float scale = mData.getReferences().getData (row, mData.getReferences().
|
float scale = mData.getReferences().getData (row, mData.getReferences().
|
||||||
findColumnIndex (CSMWorld::Columns::ColumnId_Scale)).toFloat();
|
findColumnIndex (CSMWorld::Columns::ColumnId_Scale)).toFloat();
|
||||||
|
@ -56,17 +75,82 @@ void CSVRender::PreviewWidget::adjust (const std::string& id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVRender::PreviewWidget::PreviewWidget (const CSMWorld::Data& data,
|
CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
|
||||||
const std::string& referenceableId, QWidget *parent)
|
const std::string& referenceableId, QWidget *parent)
|
||||||
: SceneWidget (parent), mData (data), mNode (0)
|
: SceneWidget (parent), mData (data), mNode (0), mReferenceableId (referenceableId)
|
||||||
{
|
{
|
||||||
setup (referenceableId);
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVRender::PreviewWidget::PreviewWidget (const CSMWorld::Data& data,
|
CSVRender::PreviewWidget::PreviewWidget (CSMWorld::Data& data,
|
||||||
const std::string& referenceableId, const std::string& referenceId, QWidget *parent)
|
const std::string& referenceableId, const std::string& referenceId, QWidget *parent)
|
||||||
: SceneWidget (parent), mData (data)
|
: SceneWidget (parent), mData (data), mReferenceableId (referenceableId),
|
||||||
|
mReferenceId (referenceId)
|
||||||
{
|
{
|
||||||
setup (referenceableId);
|
setup();
|
||||||
adjust (referenceId);
|
|
||||||
|
adjust();
|
||||||
|
|
||||||
|
QAbstractItemModel *references =
|
||||||
|
mData.getTableModel (CSMWorld::UniversalId::Type_References);
|
||||||
|
|
||||||
|
connect (references, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
||||||
|
this, SLOT (ReferenceDataChanged (const QModelIndex&, const QModelIndex&)));
|
||||||
|
connect (references, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||||
|
this, SLOT (ReferenceAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PreviewWidget::ReferenceableDataChanged (const QModelIndex& topLeft,
|
||||||
|
const QModelIndex& bottomRight)
|
||||||
|
{
|
||||||
|
CSMWorld::IdTable& referenceables = dynamic_cast<CSMWorld::IdTable&> (
|
||||||
|
*mData.getTableModel (CSMWorld::UniversalId::Type_Referenceables));
|
||||||
|
|
||||||
|
QModelIndex index = referenceables.getModelIndex (mReferenceableId, 0);
|
||||||
|
|
||||||
|
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row())
|
||||||
|
{
|
||||||
|
/// \todo possible optimisation; check columns and only update if relevant columns have
|
||||||
|
/// changed
|
||||||
|
setModel();
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PreviewWidget::ReferenceableAboutToBeRemoved (const QModelIndex& parent, int start,
|
||||||
|
int end)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PreviewWidget::ReferenceDataChanged (const QModelIndex& topLeft,
|
||||||
|
const QModelIndex& bottomRight)
|
||||||
|
{
|
||||||
|
CSMWorld::IdTable& references = dynamic_cast<CSMWorld::IdTable&> (
|
||||||
|
*mData.getTableModel (CSMWorld::UniversalId::Type_References));
|
||||||
|
|
||||||
|
int columnIndex = references.findColumnIndex (CSMWorld::Columns::ColumnId_ReferenceableId);
|
||||||
|
|
||||||
|
QModelIndex index = references.getModelIndex (mReferenceId, columnIndex);
|
||||||
|
|
||||||
|
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row())
|
||||||
|
{
|
||||||
|
/// \todo possible optimisation; check columns and only update if relevant columns have
|
||||||
|
/// changed
|
||||||
|
adjust();
|
||||||
|
|
||||||
|
if (index.column()>=topLeft.column() && index.column()<=bottomRight.row())
|
||||||
|
{
|
||||||
|
mReferenceableId = references.data (index).toString().toUtf8().constData();
|
||||||
|
setModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
flagAsModified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVRender::PreviewWidget::ReferenceAboutToBeRemoved (const QModelIndex& parent, int start,
|
||||||
|
int end)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
#include "navigationorbit.hpp"
|
#include "navigationorbit.hpp"
|
||||||
|
|
||||||
|
class QModelIndex;
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class Data;
|
class Data;
|
||||||
|
@ -18,28 +20,42 @@ namespace CSVRender
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
const CSMWorld::Data& mData;
|
CSMWorld::Data& mData;
|
||||||
CSVRender::NavigationOrbit mOrbit;
|
CSVRender::NavigationOrbit mOrbit;
|
||||||
NifOgre::ObjectScenePtr mObject;
|
NifOgre::ObjectScenePtr mObject;
|
||||||
Ogre::SceneNode *mNode;
|
Ogre::SceneNode *mNode;
|
||||||
|
std::string mReferenceId;
|
||||||
|
std::string mReferenceableId;
|
||||||
|
|
||||||
void setup (const std::string& id);
|
void setup();
|
||||||
///< \param id ID of the referenceable to be viewed
|
|
||||||
|
|
||||||
void adjust (const std::string& id);
|
void setModel();
|
||||||
///< \param id ID of the reference to be viewed
|
|
||||||
|
void adjust();
|
||||||
|
///< Adjust referenceable preview according to the reference
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PreviewWidget (const CSMWorld::Data& data, const std::string& referenceableId,
|
PreviewWidget (CSMWorld::Data& data, const std::string& referenceableId,
|
||||||
QWidget *parent = 0);
|
QWidget *parent = 0);
|
||||||
|
|
||||||
PreviewWidget (const CSMWorld::Data& data, const std::string& referenceableId,
|
PreviewWidget (CSMWorld::Data& data, const std::string& referenceableId,
|
||||||
const std::string& referenceId, QWidget *parent = 0);
|
const std::string& referenceId, QWidget *parent = 0);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void ReferenceableDataChanged (const QModelIndex& topLeft,
|
||||||
|
const QModelIndex& bottomRight);
|
||||||
|
|
||||||
|
void ReferenceableAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||||
|
|
||||||
|
void ReferenceDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||||
|
|
||||||
|
void ReferenceAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,11 @@ namespace CSVRender
|
||||||
return mSceneMgr;
|
return mSceneMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneWidget::flagAsModified()
|
||||||
|
{
|
||||||
|
mUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
void SceneWidget::paintEvent(QPaintEvent* e)
|
void SceneWidget::paintEvent(QPaintEvent* e)
|
||||||
{
|
{
|
||||||
if (!mWindow)
|
if (!mWindow)
|
||||||
|
|
|
@ -36,6 +36,8 @@ namespace CSVRender
|
||||||
|
|
||||||
Ogre::SceneManager *getSceneManager();
|
Ogre::SceneManager *getSceneManager();
|
||||||
|
|
||||||
|
void flagAsModified();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent* e);
|
void paintEvent(QPaintEvent* e);
|
||||||
void resizeEvent(QResizeEvent* e);
|
void resizeEvent(QResizeEvent* e);
|
||||||
|
|
Loading…
Reference in a new issue