Add frozen TikZRefinery demo baseline and build pipeline
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#include "editing/tkrEditHistory.h"
|
||||
#include <utility>
|
||||
|
||||
namespace TikzRefinery {
|
||||
namespace { constexpr qsizetype nEntryStep = 1; }
|
||||
bool tkrEditHistory::canUndo() const { return m_nCursor > 0; }
|
||||
bool tkrEditHistory::canRedo() const { return m_nCursor < m_vecEntries.size(); }
|
||||
QString tkrEditHistory::undoDescription() const
|
||||
{ return canUndo() ? m_vecEntries.at(m_nCursor - nEntryStep).strDescription : QString(); }
|
||||
QString tkrEditHistory::redoDescription() const
|
||||
{ return canRedo() ? m_vecEntries.at(m_nCursor).strDescription : QString(); }
|
||||
void tkrEditHistory::record(const QByteArray &baBefore, const QByteArray &baAfter,
|
||||
const QString &strDescription)
|
||||
{
|
||||
// Prepare detached storage first. Allocation failure cannot discard the redo branch.
|
||||
QVector<Entry> vecPrepared = m_vecEntries;
|
||||
vecPrepared.resize(m_nCursor);
|
||||
vecPrepared.append({baBefore, baAfter, strDescription});
|
||||
m_vecEntries.swap(vecPrepared);
|
||||
m_nCursor = m_vecEntries.size();
|
||||
}
|
||||
void tkrEditHistory::clear() { QVector<Entry>().swap(m_vecEntries); m_nCursor = 0; }
|
||||
QByteArray tkrEditHistory::restorationSource(bool bRedo) const
|
||||
{
|
||||
return bRedo ? m_vecEntries.at(m_nCursor).baAfter
|
||||
: m_vecEntries.at(m_nCursor - nEntryStep).baBefore;
|
||||
}
|
||||
void tkrEditHistory::advance(bool bRedo) { m_nCursor += bRedo ? nEntryStep : -nEntryStep; }
|
||||
void tkrEditHistory::swap(tkrEditHistory &historyOther) noexcept
|
||||
{
|
||||
m_vecEntries.swap(historyOther.m_vecEntries);
|
||||
std::swap(m_nCursor, historyOther.m_nCursor);
|
||||
}
|
||||
} // namespace TikzRefinery
|
||||
Reference in New Issue
Block a user