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

#include <recorder_export_preprocessor.h>

Classes

struct  Private
 

Public Member Functions

void doPreprocessing ()
 Checks if there are no holes in the frames, and shifts the files to fill them.
 
 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 50 of file recorder_export_preprocessor.cpp.

51 : d(new Private(directory, format))
52{
53}

◆ ~RecorderExportPreprocessor()

RecorderExportPreprocessor::~RecorderExportPreprocessor ( )

Definition at line 55 of file recorder_export_preprocessor.cpp.

56{
57}

Member Function Documentation

◆ doPreprocessing()

void RecorderExportPreprocessor::doPreprocessing ( )

Checks if there are no holes in the frames, and shifts the files to fill them.

Definition at line 66 of file recorder_export_preprocessor.cpp.

67{
68 if (!d->directory.exists()) {
69 return;
70 }
71
72 d->getTail();
73
74 QStringList fileNames = d->directory.entryList({"*." % RecorderFormatInfo::fileExtension(d->format)});
75
76 QRegularExpression fileRegex = RecorderConst::snapshotFilePatternFor(RecorderFormatInfo::fileExtension(d->format));
77 QHash<int, QString> files;
78 QVector<int> indecies;
79
80 Q_FOREACH (QString file, fileNames) {
81 QRegularExpressionMatch match = fileRegex.match(file);
82
83 if (match.hasMatch()) {
84 int index = match.captured(1).toInt();
85 files.insert(index, file);
86 indecies.push_back(index);
87 }
88 }
89
90 // It should be sorted, but just in case
91 std::sort(indecies.begin(), indecies.end());
92
93 QHash<int, int> holes;
94 int prevIndex = 0;
95
96 for (auto it = indecies.begin(); it != indecies.end(); ++it) {
97 int curIndex = *it;
98 int diff = curIndex - prevIndex;
99
100 if (diff > 1) {
101 holes.insert(curIndex, diff - 1);
102 }
103
104 prevIndex = curIndex;
105 }
106
107 // No holes, so we don't need to do anything
108 if (holes.isEmpty()) {
109 return;
110 }
111
112 int offset = 0;
113 QStringList new_tails = d->tails;
114
115 for (auto it = indecies.begin(); it != indecies.end(); ++it) {
116 int ind = *it;
117
118 if (holes.contains(ind)) {
119 offset += holes[ind];
120 }
121
122 if (offset == 0) {
123 continue;
124 }
125
126 QString oldName = files[ind];
127 QString newName = QString("%2.%3").arg(QString("%1").arg(ind - offset, 7, 10, QLatin1Char('0')),
129
130 int tailIndex = d->tails.indexOf(oldName);
131 if (tailIndex != -1) {
132 new_tails[tailIndex] = newName;
133 }
134
135 // Hopefully nothing should go wrong
136 d->directory.rename(oldName, newName);
137 }
138
139 if (d->tails != new_tails) {
140 d->tails = new_tails;
141 d->saveTail();
142 }
143}
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 59 of file recorder_export_preprocessor.cpp.

60{
61 d->directory = directory;
62 d->format = format;
63}

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: