File: previewwidget.cpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (131 lines) | stat: -rw-r--r-- 4,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "previewwidget.hpp"

#include <apps/opencs/model/world/columns.hpp>
#include <apps/opencs/model/world/record.hpp>
#include <apps/opencs/model/world/universalid.hpp>
#include <apps/opencs/view/render/object.hpp>
#include <apps/opencs/view/render/scenewidget.hpp>

#include "../../model/world/data.hpp"
#include "../../model/world/idtable.hpp"

class QWidget;

CSVRender::PreviewWidget::PreviewWidget(
    CSMWorld::Data& worldData, const std::string& id, bool referenceable, QWidget* parent)
    : SceneWidget(worldData.getResourceSystem(), parent)
    , mData(worldData)
    , mObject(worldData, mRootNode, id, referenceable)
{
    selectNavigationMode("orbit");

    QAbstractItemModel* referenceables = mData.getTableModel(CSMWorld::UniversalId::Type_Referenceables);

    connect(referenceables, &QAbstractItemModel::dataChanged, this, &PreviewWidget::referenceableDataChanged);
    connect(
        referenceables, &QAbstractItemModel::rowsAboutToBeRemoved, this, &PreviewWidget::referenceableAboutToBeRemoved);

    connect(&mData, &CSMWorld::Data::assetTablesChanged, this, &PreviewWidget::assetTablesChanged);

    setExterior(false);

    if (!referenceable)
    {
        QAbstractItemModel* references = mData.getTableModel(CSMWorld::UniversalId::Type_References);

        connect(references, &QAbstractItemModel::dataChanged, this, &PreviewWidget::referenceDataChanged);
        connect(references, &QAbstractItemModel::rowsAboutToBeRemoved, this, &PreviewWidget::referenceAboutToBeRemoved);
    }
}

void CSVRender::PreviewWidget::referenceableDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
    if (mObject.referenceableDataChanged(topLeft, bottomRight))
        flagAsModified();

    if (mObject.getReferenceId().empty())
    {
        CSMWorld::IdTable& referenceables
            = dynamic_cast<CSMWorld::IdTable&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Referenceables));

        QModelIndex index = referenceables.getModelIndex(
            mObject.getReferenceableId(), referenceables.findColumnIndex(CSMWorld::Columns::ColumnId_Modification));

        if (referenceables.data(index).toInt() == CSMWorld::RecordBase::State_Deleted)
            emit closeRequest();
    }
}

void CSVRender::PreviewWidget::referenceableAboutToBeRemoved(const QModelIndex& parent, int start, int end)
{
    if (mObject.referenceableAboutToBeRemoved(parent, start, end))
        flagAsModified();

    if (mObject.getReferenceableId().empty())
        return;

    CSMWorld::IdTable& referenceables
        = dynamic_cast<CSMWorld::IdTable&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Referenceables));

    QModelIndex index = referenceables.getModelIndex(mObject.getReferenceableId(), 0);

    if (index.row() >= start && index.row() <= end)
    {
        if (mObject.getReferenceId().empty())
        {
            // this is a preview for a referenceble
            emit closeRequest();
        }
    }
}

void CSVRender::PreviewWidget::referenceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
    if (mObject.referenceDataChanged(topLeft, bottomRight))
        flagAsModified();

    if (mObject.getReferenceId().empty())
        return;

    CSMWorld::IdTable& references
        = dynamic_cast<CSMWorld::IdTable&>(*mData.getTableModel(CSMWorld::UniversalId::Type_References));

    // check for deleted state
    {
        QModelIndex index = references.getModelIndex(
            mObject.getReferenceId(), references.findColumnIndex(CSMWorld::Columns::ColumnId_Modification));

        if (references.data(index).toInt() == CSMWorld::RecordBase::State_Deleted)
        {
            emit closeRequest();
            return;
        }
    }

    int columnIndex = references.findColumnIndex(CSMWorld::Columns::ColumnId_ReferenceableId);

    QModelIndex index = references.getModelIndex(mObject.getReferenceId(), columnIndex);

    if (index.row() >= topLeft.row() && index.row() <= bottomRight.row())
        if (index.column() >= topLeft.column() && index.column() <= bottomRight.row())
            emit referenceableIdChanged(mObject.getReferenceableId());
}

void CSVRender::PreviewWidget::referenceAboutToBeRemoved(const QModelIndex& parent, int start, int end)
{
    if (mObject.getReferenceId().empty())
        return;

    CSMWorld::IdTable& references
        = dynamic_cast<CSMWorld::IdTable&>(*mData.getTableModel(CSMWorld::UniversalId::Type_References));

    QModelIndex index = references.getModelIndex(mObject.getReferenceId(), 0);

    if (index.row() >= start && index.row() <= end)
        emit closeRequest();
}

void CSVRender::PreviewWidget::assetTablesChanged()
{
    mObject.reloadAssets();
}