summaryrefslogtreecommitdiff
path: root/src/plugins/qmldesigner/components/textureeditor/textureeditortransaction.cpp
blob: 391d22536e7c475729b5c3414dcb058fa34ba98d (plain)
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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "textureeditortransaction.h"

#include <QTimerEvent>

namespace QmlDesigner {

TextureEditorTransaction::TextureEditorTransaction(TextureEditorView *textureEditor)
    : QObject(textureEditor),
      m_textureEditor(textureEditor)
{
}

void TextureEditorTransaction::start()
{
    if (!m_textureEditor->model())
        return;
    if (m_rewriterTransaction.isValid())
        m_rewriterTransaction.commit();
    m_rewriterTransaction = m_textureEditor->beginRewriterTransaction(QByteArrayLiteral("MaterialEditorTransaction::start"));
    m_timerId = startTimer(10000);
}

void TextureEditorTransaction::end()
{
    if (m_rewriterTransaction.isValid() &&  m_textureEditor->model()) {
        killTimer(m_timerId);
        m_rewriterTransaction.commit();
    }
}

bool TextureEditorTransaction::active() const
{
    return m_rewriterTransaction.isValid();
}

void TextureEditorTransaction::timerEvent(QTimerEvent *timerEvent)
{
    if (timerEvent->timerId() != m_timerId)
        return;
    killTimer(timerEvent->timerId());
    if (m_rewriterTransaction.isValid())
        m_rewriterTransaction.commit();
}

} // namespace QmlDesigner