mirror of
https://github.com/riuson/lcd-image-converter.git
synced 2026-03-06 08:14:54 +01:00
97 lines
2.8 KiB
C++
97 lines
2.8 KiB
C++
#include "historykeeper.h"
|
|
|
|
#include <QStringList>
|
|
#include <QStringListIterator>
|
|
#include "historyrecord.h"
|
|
//-----------------------------------------------------------------------------
|
|
HistoryKeeper::HistoryKeeper(QObject *parent) :
|
|
QObject(parent)
|
|
{
|
|
this->mHistory = new QList<HistoryRecord *>();
|
|
this->mCurrentIndex = 0;
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
HistoryKeeper::~HistoryKeeper()
|
|
{
|
|
qDeleteAll(*this->mHistory);
|
|
this->mHistory->clear();
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
void HistoryKeeper::store(
|
|
const QMap<QString, QImage *> *images,
|
|
const QMap<QString, QVariant> *info)
|
|
{
|
|
this->removeAfter(this->mCurrentIndex);
|
|
|
|
HistoryRecord *record = new HistoryRecord(images, info, this);
|
|
this->mHistory->append(record);
|
|
this->mCurrentIndex++;
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
void HistoryKeeper::restorePrevious(
|
|
QMap<QString, QImage *> *images,
|
|
QMap<QString, QVariant> *info)
|
|
{
|
|
if (this->mCurrentIndex > 0)
|
|
{
|
|
this->mCurrentIndex--;
|
|
this->restoreAt(this->mCurrentIndex, images, info);
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
void HistoryKeeper::restoreNext(
|
|
QMap<QString, QImage *> *images,
|
|
QMap<QString, QVariant> *info)
|
|
{
|
|
if (this->mCurrentIndex > 0)
|
|
{
|
|
this->mCurrentIndex--;
|
|
this->restoreAt(this->mCurrentIndex, images, info);
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
void HistoryKeeper::removeAfter(int index)
|
|
{
|
|
for (int i = this->mHistory->length() - 1; i > index; i--)
|
|
{
|
|
HistoryRecord *record = this->mHistory->at(i);
|
|
this->mHistory->removeAt(i);
|
|
delete record;
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
void HistoryKeeper::restoreAt(
|
|
int index,
|
|
QMap<QString, QImage *> *images,
|
|
QMap<QString, QVariant> *info)
|
|
{
|
|
HistoryRecord *record = this->mHistory->at(index);
|
|
|
|
qDeleteAll(*images);
|
|
images->clear();
|
|
info->clear();
|
|
|
|
QStringList keys = record->images()->keys();
|
|
QStringListIterator iterator(keys);
|
|
while (iterator.hasNext())
|
|
{
|
|
QString key = iterator.next();
|
|
|
|
QImage *newImage = new QImage(*record->images()->value(key));
|
|
|
|
images->insert(key, newImage);
|
|
}
|
|
|
|
keys = record->info()->keys();
|
|
iterator = QStringListIterator(keys);
|
|
while (iterator.hasNext())
|
|
{
|
|
QString key = iterator.next();
|
|
|
|
QVariant value = record->info()->value(key);
|
|
|
|
info->insert(key, value);
|
|
}
|
|
}
|
|
//-----------------------------------------------------------------------------
|