Krita Source Code Documentation
Loading...
Searching...
No Matches
RecorderExportPreprocessor Class Reference

#include <recorder_export_preprocessor.h>

Classes

struct  Private
 

Public Member Functions

void doPreprocessing ()
 
 RecorderExportPreprocessor (QDir directory, RecorderFormat format)
 
void updateSettings (QDir directory, RecorderFormat format)
 
 ~RecorderExportPreprocessor ()
 

Private Attributes

QScopedPointer< Private > d
 

Detailed Description

Definition at line 14 of file recorder_export_preprocessor.h.

Constructor & Destructor Documentation

◆ RecorderExportPreprocessor()

RecorderExportPreprocessor::RecorderExportPreprocessor ( QDir directory,
RecorderFormat format )

Definition at line 28 of file recorder_export_preprocessor.cpp.

29 : d(new Private(directory, format))
30{
31}

◆ ~RecorderExportPreprocessor()

RecorderExportPreprocessor::~RecorderExportPreprocessor ( )

Definition at line 33 of file recorder_export_preprocessor.cpp.

34{
35}

Member Function Documentation

◆ doPreprocessing()

void RecorderExportPreprocessor::doPreprocessing ( )

Definition at line 44 of file recorder_export_preprocessor.cpp.

45{
46 if (!d->directory.exists()) {
47 return;
48 }
49
50 QStringList fileNames = d->directory.entryList({"*." % RecorderFormatInfo::fileExtension(d->format)});
51
52 QRegularExpression fileRegex = RecorderConst::snapshotFilePatternFor(RecorderFormatInfo::fileExtension(d->format));
53 QHash<int, QString> files;
54 QVector<int> indecies;
55
56 Q_FOREACH (QString file, fileNames) {
57 QRegularExpressionMatch match = fileRegex.match(file);
58
59 if (match.hasMatch()) {
60 int index = match.captured(1).toInt();
61 files.insert(index, file);
62 indecies.push_back(index);
63 }
64 }
65
66 // It should be sorted, but just in case
67 std::sort(indecies.begin(), indecies.end());
68
69 QHash<int, int> holes;
70 int prevIndex = 0;
71
72 for (auto it = indecies.begin(); it != indecies.end(); ++it) {
73 int curIndex = *it;
74 int diff = curIndex - prevIndex;
75
76 if (diff > 1) {
77 holes.insert(curIndex, diff - 1);
78 }
79
80 prevIndex = curIndex;
81 }
82
83 // No holes, so we don't need to do anything
84 if (holes.isEmpty()) {
85 return;
86 }
87
88 int offset = 0;
89 for (auto it = indecies.begin(); it != indecies.end(); ++it) {
90 int ind = *it;
91
92 if (holes.contains(ind)) {
93 offset += holes[ind];
94 }
95
96 if (offset == 0) {
97 continue;
98 }
99
100 QString oldName = files[ind];
101 QString newName = QString("%2.%3").arg(QString("%1").arg(ind - offset, 7, 10, QLatin1Char('0')),
103
104 // Hopefully nothing should go wrong
105 d->directory.rename(oldName, newName);
106 }
107}
QRegularExpression snapshotFilePatternFor(const QString &extension)
QLatin1String fileExtension(RecorderFormat format)

References d, RecorderFormatInfo::fileExtension(), and RecorderConst::snapshotFilePatternFor().

◆ updateSettings()

void RecorderExportPreprocessor::updateSettings ( QDir directory,
RecorderFormat format )

Definition at line 37 of file recorder_export_preprocessor.cpp.

38{
39 d->directory = directory;
40 d->format = format;
41}

References d.

Member Data Documentation

◆ d

QScopedPointer<Private> RecorderExportPreprocessor::d
private

Definition at line 26 of file recorder_export_preprocessor.h.


The documentation for this class was generated from the following files: