From 2c4347e9a6ad36e10715e393c70eed54411648de Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sun, 19 Feb 2023 21:16:05 -0800 Subject: [PATCH] node: merge various metadata functions into one --- .../footagerelink/footagerelinkdialog.cpp | 4 +- app/node/node.cpp | 10 +- app/node/node.h | 16 ++-- app/node/output/viewer/viewer.cpp | 91 ++++++++++--------- app/node/output/viewer/viewer.h | 3 +- app/node/project/folder/folder.cpp | 8 +- app/node/project/folder/folder.h | 2 +- app/node/project/footage/footage.cpp | 77 ++++++++-------- app/node/project/footage/footage.h | 5 +- app/node/project/sequence/sequence.cpp | 8 +- app/node/project/sequence/sequence.h | 2 +- .../projectexplorer/projectviewmodel.cpp | 8 +- 12 files changed, 127 insertions(+), 107 deletions(-) diff --git a/app/dialog/footagerelink/footagerelinkdialog.cpp b/app/dialog/footagerelink/footagerelinkdialog.cpp index 066c163e6..a608a049c 100644 --- a/app/dialog/footagerelink/footagerelinkdialog.cpp +++ b/app/dialog/footagerelink/footagerelinkdialog.cpp @@ -64,7 +64,7 @@ FootageRelinkDialog::FootageRelinkDialog(const QVector &footage, QWid connect(item_browse_btn, &QPushButton::clicked, this, &FootageRelinkDialog::BrowseForFootage); item_actions_layout->addWidget(item_browse_btn); - item->setIcon(0, f->icon()); + item->setIcon(0, f->data(Node::ICON).value()); item->setText(0, f->GetLabel()); item->setText(1, f->filename()); @@ -89,7 +89,7 @@ void FootageRelinkDialog::UpdateFootageItem(int index) { Footage* f = footage_.at(index); QTreeWidgetItem* item = table_->topLevelItem(index); - item->setIcon(0, f->icon()); + item->setIcon(0, f->data(Node::ICON).value()); item->setText(1, f->filename()); } diff --git a/app/node/node.cpp b/app/node/node.cpp index 89d3fe145..94af73f63 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -103,10 +103,14 @@ void Node::Retranslate() SetInputName(kEnabledInput, tr("Enabled")); } -QIcon Node::icon() const +QVariant Node::data(const DataType &d) const { - // Just a meaningless default icon to be used where necessary - return icon::New; + if (d == ICON) { + // Just a meaningless default icon to be used where necessary + return icon::New; + } + + return QVariant(); } bool Node::SetNodePositionInContext(Node *node, const QPointF &pos) diff --git a/app/node/node.h b/app/node/node.h index 05ec9f725..01be83327 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -194,14 +194,16 @@ public: */ virtual void Retranslate(); - virtual QIcon icon() const; + enum DataType + { + ICON, + DURATION, + CREATED_TIME, + MODIFIED_TIME, + FREQUENCY_RATE + }; - virtual QString duration() const {return QString();} - - virtual qint64 creation_time() const {return 0;} - virtual qint64 mod_time() const {return 0;} - - virtual QString rate() const {return QString();} + virtual QVariant data(const DataType &d) const; const QVector& inputs() const { diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index 5f2437889..f93583a66 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -87,56 +87,61 @@ QString ViewerOutput::Description() const return tr("Interface between a Viewer panel and the node system."); } -QString ViewerOutput::duration() const +QVariant ViewerOutput::data(const DataType &d) const { - rational using_timebase; - Timecode::Display using_display = Core::instance()->GetTimecodeDisplay(); + switch (d) { + case DURATION: + { + rational using_timebase; + Timecode::Display using_display = Core::instance()->GetTimecodeDisplay(); - // Get first enabled streams - VideoParams video = GetFirstEnabledVideoStream(); - AudioParams audio = GetFirstEnabledAudioStream(); - SubtitleParams sub = GetFirstEnabledSubtitleStream(); + // Get first enabled streams + VideoParams video = GetFirstEnabledVideoStream(); + AudioParams audio = GetFirstEnabledAudioStream(); + SubtitleParams sub = GetFirstEnabledSubtitleStream(); - if (video.is_valid() && video.video_type() != VideoParams::kVideoTypeStill) { - // Prioritize video - using_timebase = video.frame_rate_as_time_base(); - } else if (audio.is_valid()) { - // Use audio as a backup - // If we're showing in a timecode, we prefer showing audio in seconds instead - if (using_display == Timecode::kTimecodeDropFrame - || using_display == Timecode::kTimecodeNonDropFrame) { - using_display = Timecode::kTimecodeSeconds; + if (video.is_valid() && video.video_type() != VideoParams::kVideoTypeStill) { + // Prioritize video + using_timebase = video.frame_rate_as_time_base(); + } else if (audio.is_valid()) { + // Use audio as a backup + // If we're showing in a timecode, we prefer showing audio in seconds instead + if (using_display == Timecode::kTimecodeDropFrame + || using_display == Timecode::kTimecodeNonDropFrame) { + using_display = Timecode::kTimecodeSeconds; + } + + using_timebase = audio.sample_rate_as_time_base(); + } else if (sub.is_valid()) { + using_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value(); } - using_timebase = audio.sample_rate_as_time_base(); - } else if (sub.is_valid()) { - using_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value(); + if (!using_timebase.isNull()) { + // Return time transformed to timecode + return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display)); + } + break; + } + case FREQUENCY_RATE: + { + VideoParams video_stream; + + if (HasEnabledVideoStreams() + && (video_stream = GetFirstEnabledVideoStream()).video_type() != VideoParams::kVideoTypeStill) { + // This is a video editor, prioritize video streams + return tr("%1 FPS").arg(video_stream.frame_rate().toDouble()); + } else if (HasEnabledAudioStreams()) { + // No video streams, return audio + AudioParams audio_stream = GetFirstEnabledAudioStream(); + return tr("%1 Hz").arg(audio_stream.sample_rate()); + } + break; + } + default: + break; } - if (using_timebase.isNull()) { - // No timebase, return null - return QString(); - } else { - // Return time transformed to timecode - return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display)); - } -} - -QString ViewerOutput::rate() const -{ - VideoParams video_stream; - - if (HasEnabledVideoStreams() - && (video_stream = GetFirstEnabledVideoStream()).video_type() != VideoParams::kVideoTypeStill) { - // This is a video editor, prioritize video streams - return tr("%1 FPS").arg(video_stream.frame_rate().toDouble()); - } else if (HasEnabledAudioStreams()) { - // No video streams, return audio - AudioParams audio_stream = GetFirstEnabledAudioStream(); - return tr("%1 Hz").arg(audio_stream.sample_rate()); - } - - return QString(); + return super::data(d); } bool ViewerOutput::HasEnabledVideoStreams() const diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index 70d40dd2a..053d76e67 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -53,8 +53,7 @@ public: virtual QVector Category() const override; virtual QString Description() const override; - virtual QString duration() const override; - virtual QString rate() const override; + virtual QVariant data(const DataType &d) const override; void set_default_parameters(); diff --git a/app/node/project/folder/folder.cpp b/app/node/project/folder/folder.cpp index 9df90a03f..3a3918aba 100644 --- a/app/node/project/folder/folder.cpp +++ b/app/node/project/folder/folder.cpp @@ -37,9 +37,13 @@ Folder::Folder() AddInput(kChildInput, NodeValue::kNone, InputFlags(kInputFlagArray | kInputFlagNotKeyframable)); } -QIcon Folder::icon() const +QVariant Folder::data(const DataType &d) const { - return icon::Folder; + if (d == ICON) { + return icon::Folder; + } + + return super::data(d); } void Folder::Retranslate() diff --git a/app/node/project/folder/folder.h b/app/node/project/folder/folder.h index 2afb0ac1c..ceb224e06 100644 --- a/app/node/project/folder/folder.h +++ b/app/node/project/folder/folder.h @@ -59,7 +59,7 @@ public: return tr("Organize several items into a single collection."); } - virtual QIcon icon() const override; + virtual QVariant data(const DataType &d) const override; virtual void Retranslate() override; diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index 4a316c751..630964939 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -203,26 +203,6 @@ const QString &Footage::decoder() const return decoder_; } -QIcon Footage::icon() const -{ - if (valid_ && GetTotalStreamCount()) { - // Prioritize video > audio > image - VideoParams s = GetFirstEnabledVideoStream(); - - if (s.is_valid() && s.video_type() != VideoParams::kVideoTypeStill) { - return icon::Video; - } else if (HasEnabledAudioStreams()) { - return icon::Audio; - } else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) { - return icon::Image; - } else if (HasEnabledSubtitleStreams()) { - return icon::Subtitles; - } - } - - return icon::Error; -} - QString Footage::DescribeVideoStream(const VideoParams ¶ms) { if (params.video_type() == VideoParams::kVideoTypeStill) { @@ -375,26 +355,51 @@ void Footage::LoadFinishedEvent() } } -qint64 Footage::creation_time() const +QVariant Footage::data(const DataType &d) const { - QFileInfo info(filename()); + switch (d) { + case CREATED_TIME: + { + QFileInfo info(filename()); - if (info.exists()) { - return QtUtils::GetCreationDate(info).toSecsSinceEpoch(); + if (info.exists()) { + return QtUtils::GetCreationDate(info).toSecsSinceEpoch(); + } + break; + } + case MODIFIED_TIME: + { + QFileInfo info(filename()); + + if (info.exists()) { + return info.lastModified().toSecsSinceEpoch(); + } + break; + } + case ICON: + { + if (valid_ && GetTotalStreamCount()) { + // Prioritize video > audio > image + VideoParams s = GetFirstEnabledVideoStream(); + + if (s.is_valid() && s.video_type() != VideoParams::kVideoTypeStill) { + return icon::Video; + } else if (HasEnabledAudioStreams()) { + return icon::Audio; + } else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) { + return icon::Image; + } else if (HasEnabledSubtitleStreams()) { + return icon::Subtitles; + } + } + + return icon::Error; + } + default: + break; } - return 0; -} - -qint64 Footage::mod_time() const -{ - QFileInfo info(filename()); - - if (info.exists()) { - return info.lastModified().toSecsSinceEpoch(); - } - - return 0; + return super::data(d); } void Footage::UpdateTooltip() diff --git a/app/node/project/footage/footage.h b/app/node/project/footage/footage.h index 794e5062d..516dda563 100644 --- a/app/node/project/footage/footage.h +++ b/app/node/project/footage/footage.h @@ -153,8 +153,6 @@ public: */ const QString& decoder() const; - virtual QIcon icon() const override; - virtual bool IsItem() const override { return true; @@ -176,8 +174,7 @@ public: virtual void LoadFinishedEvent() override; - virtual qint64 creation_time() const override; - virtual qint64 mod_time() const override; + virtual QVariant data(const DataType &d) const override; virtual int GetTotalStreamCount() const override { return total_stream_count_; } diff --git a/app/node/project/sequence/sequence.cpp b/app/node/project/sequence/sequence.cpp index df0a970fd..54b19e0cd 100644 --- a/app/node/project/sequence/sequence.cpp +++ b/app/node/project/sequence/sequence.cpp @@ -71,9 +71,13 @@ void Sequence::add_default_nodes(MultiUndoCommand* command) } } -QIcon Sequence::icon() const +QVariant Sequence::data(const DataType &d) const { - return icon::Sequence; + if (d == ICON) { + return icon::Sequence; + } + + return super::data(d); } QVector Sequence::GetUnlockedTracks() const diff --git a/app/node/project/sequence/sequence.h b/app/node/project/sequence/sequence.h index 4f8b62d04..60cbf4579 100644 --- a/app/node/project/sequence/sequence.h +++ b/app/node/project/sequence/sequence.h @@ -59,7 +59,7 @@ public: void add_default_nodes(MultiUndoCommand *command = nullptr); - virtual QIcon icon() const override; + virtual QVariant data(const DataType &d) const override; const QVector &GetTracks() const { diff --git a/app/widget/projectexplorer/projectviewmodel.cpp b/app/widget/projectexplorer/projectviewmodel.cpp index c7e558249..550d3f972 100644 --- a/app/widget/projectexplorer/projectviewmodel.cpp +++ b/app/widget/projectexplorer/projectviewmodel.cpp @@ -140,13 +140,13 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const case kName: return internal_item->GetLabel(); case kDuration: - return internal_item->duration(); + return internal_item->data(Node::DURATION); case kRate: - return internal_item->rate(); + return internal_item->data(Node::FREQUENCY_RATE); case kLastModified: case kCreatedTime: { - qint64 using_time = (column_type == kLastModified) ? internal_item->mod_time() : internal_item->creation_time(); + qint64 using_time = (column_type == kLastModified) ? internal_item->data(Node::MODIFIED_TIME).toLongLong() : internal_item->data(Node::CREATED_TIME).toLongLong(); if (using_time == 0) { // 0 is the null value, return nothing @@ -178,7 +178,7 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const case Qt::DecorationRole: // If this is the first column, return the Item's icon if (column_type == kName) { - return internal_item->icon(); + return internal_item->data(Node::ICON); } break; case Qt::ToolTipRole: