Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions src/qml/qmlwaveformrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ QmlWaveformRendererFactory::Renderer QmlWaveformRendererMark::create(
// The initialisation is closely inspired from WaveformMarkSet::setup
int priority = 0;
for (const auto* pMark : std::as_const(m_marks)) {
pRenderer->addMark(WaveformMarkPointer(new WaveformMark(
auto pMarker = WaveformMarkPointer(new WaveformMark(
waveformWidget->getGroup(),
pMark->control(),
pMark->visibilityControl(),
Expand All @@ -327,7 +327,13 @@ QmlWaveformRendererFactory::Renderer QmlWaveformRendererMark::create(
pMark->endPixmap().toLocalFile(),
pMark->endIcon().toLocalFile(),
pMark->disabledOpacity(),
pMark->enabledOpacity())));
pMark->enabledOpacity()));
auto error = pMarker->validate();
if (!error.isEmpty()) {
qmlEngine(this)->throwError(tr("Invalid marker: %1").arg(error));
continue;
}
pRenderer->addMark(pMarker);
priority--;
}
const auto* pMark = defaultMark();
Expand All @@ -336,26 +342,7 @@ QmlWaveformRendererFactory::Renderer QmlWaveformRendererMark::create(
const QString endPixmap = pMark->endPixmap().toLocalFile();
const QString icon = pMark->icon().toLocalFile();
const QString endIcon = pMark->endIcon().toLocalFile();
// FIXME: the following checks should be done on the WaveformMarker
// setter (depends of #14515)
if (!pixmap.isEmpty() && !QFileInfo::exists(pixmap)) {
qmlEngine(this)->throwError(tr("Cannot find the marker pixmap") + " \"" + pixmap + '"');
}

if (!endPixmap.isEmpty() && !QFileInfo::exists(endPixmap)) {
qmlEngine(this)->throwError(tr("Cannot find the marker endPixmap") +
" \"" + endPixmap + '"');
}

if (!icon.isEmpty() && !QFileInfo::exists(icon)) {
qmlEngine(this)->throwError(tr("Cannot find the marker icon") + " \"" + icon + '"');
}

if (!endIcon.isEmpty() && !QFileInfo::exists(endIcon)) {
qmlEngine(this)->throwError(tr("Cannot find the marker endIcon") +
" \"" + endIcon + '"');
}
pRenderer->setDefaultMark(
QString error = pRenderer->setDefaultMark(
waveformWidget->getGroup(),
WaveformMarkSet::DefaultMarkerStyle{
pMark->control(),
Expand All @@ -371,6 +358,9 @@ QmlWaveformRendererFactory::Renderer QmlWaveformRendererMark::create(
pMark->enabledOpacity(),
pMark->disabledOpacity(),
});
if (!error.isEmpty()) {
qmlEngine(this)->throwError(tr("Invalid default marker: %1").arg(error));
}
}
return QmlWaveformRendererFactory::Renderer{pRenderer.get(), std::move(pRenderer)};
}
Expand Down
38 changes: 38 additions & 0 deletions src/waveform/renderers/waveformmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include <QOpenGLTexture>
#include <QPainterPath>
#include <QRegExp>
#include <QStringLiteral>
#include <QSvgRenderer>
#include <QtDebug>
#include <algorithm>

#include "skin/legacy/skincontext.h"
#include "waveform/renderers/waveformsignalcolors.h"
Expand Down Expand Up @@ -594,6 +596,42 @@
return image;
}

QString WaveformMark::validate() const {
auto checkPath = [](const auto& path) {
return !path.isEmpty() && !QFileInfo(path).exists();
};

auto addPaths = [](QStringList* pathList, const QString& pathTemplate) {
auto argCount = pathTemplate.count(QRegularExpression("%\\d+"));

Check failure on line 605 in src/waveform/renderers/waveformmark.cpp

View workflow job for this annotation

GitHub Actions / checks / clazy

Don't create temporary QRegularExpression objects. Use a static QRegularExpression object instead [-Wclazy-use-static-qregularexpression]
switch (argCount) {
case 0:
pathList->append(pathTemplate);
break;
case 1:
pathList->append(pathTemplate.arg(QStringLiteral("forward")));
pathList->append(pathTemplate.arg(QStringLiteral("backward")));
break;
default:
return false;
}
return true;
};

QStringList pathList;
pathList.append(m_pixmapPath);
pathList.append(m_endPixmapPath);
pathList.append(m_iconPath);
if (!addPaths(&pathList, m_endIconPath)) {
return QStringLiteral("Invalid number or arguments in endIconPath: %1").arg(m_endIconPath);
}

auto first_missing_path = std::find_if(pathList.constBegin(), pathList.constEnd(), checkPath);
if (first_missing_path != pathList.constEnd()) {
return QStringLiteral("path for icon or pixmap is not found: %1").arg(*first_missing_path);
}
return QStringLiteral("");

Check failure on line 632 in src/waveform/renderers/waveformmark.cpp

View workflow job for this annotation

GitHub Actions / checks / clazy

Use QLatin1String("") or QString() instead of an empty QStringLiteral [-Wclazy-empty-qstringliteral]
}

QImage WaveformMark::generateImage(float devicePixelRatio) {
DEBUG_ASSERT(needsImageUpdate());

Expand Down
4 changes: 4 additions & 0 deletions src/waveform/renderers/waveformmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ class WaveformMark {

WaveformMarkLabel m_label;

// Check whether or not there is issues with this marker definition. Empty
// string means no issue.
QString validate() const;

private:
QImage performImageGeneration(float devicePixelRatio,
const QString& pixmapPath,
Expand Down
11 changes: 10 additions & 1 deletion src/waveform/renderers/waveformmarkset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}
}

void WaveformMarkSet::setDefault(const QString& group,
QString WaveformMarkSet::setDefault(const QString& group,
const DefaultMarkerStyle& model,
const WaveformSignalColors& signalColors) {
m_pDefaultMark = WaveformMarkPointer::create(
Expand All @@ -81,6 +81,10 @@
0,
Cue::kNoHotCue,
signalColors);
auto error = m_pDefaultMark->validate();
if (!error.isEmpty()) {
return error;
}
for (int i = 0; i < kMaxNumberOfHotcues; ++i) {
if (m_hotCueMarks.value(i).isNull()) {
auto pMark = WaveformMarkPointer::create(
Expand All @@ -100,10 +104,15 @@
model.endIconPath,
model.enabledOpacity,
model.disabledOpacity);
auto error = pMark->validate();
if (!error.isEmpty()) {
return error;
}
m_marks.push_front(pMark);
m_hotCueMarks.insert(pMark->getHotCue(), pMark);
}
}
return QStringLiteral("");

Check failure on line 115 in src/waveform/renderers/waveformmarkset.cpp

View workflow job for this annotation

GitHub Actions / checks / clazy

Use QLatin1String("") or QString() instead of an empty QStringLiteral [-Wclazy-empty-qstringliteral]
}

WaveformMarkPointer WaveformMarkSet::getHotCueMark(int hotCue) const {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformmarkset.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class WaveformMarkSet {
m_marks.push_back(pMark);
}

void setDefault(const QString& group,
QString setDefault(const QString& group,
const DefaultMarkerStyle& model,
const WaveformSignalColors& signalColors = {});

Expand Down
4 changes: 2 additions & 2 deletions src/waveform/renderers/waveformrendermarkbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class WaveformRenderMarkBase : public QObject, public WaveformRendererAbstract {
m_marks.clear();
}

void setDefaultMark(const QString& group, const WaveformMarkSet::DefaultMarkerStyle& model) {
m_marks.setDefault(group, model);
QString setDefaultMark(const QString& group, const WaveformMarkSet::DefaultMarkerStyle& model) {
return m_marks.setDefault(group, model);
}

void addMark(WaveformMarkPointer pMark) {
Expand Down
Loading