From c004aa01759615f43452459e9654c89fa029bc13 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 27 Jul 2021 16:48:39 -0700 Subject: [PATCH] project: implemented modified and created date columns --- app/common/qtutils.cpp | 14 ++++++ app/common/qtutils.h | 6 +++ app/node/node.h | 3 ++ app/node/project/footage/footage.cpp | 23 ++++++++++ app/node/project/footage/footage.h | 3 ++ app/node/project/projectviewmodel.cpp | 46 +++++++++++++++---- app/node/project/projectviewmodel.h | 15 ++++-- .../projectexplorer/projectexplorer.cpp | 1 + 8 files changed, 99 insertions(+), 12 deletions(-) diff --git a/app/common/qtutils.cpp b/app/common/qtutils.cpp index 515a2bf67..757ca2617 100644 --- a/app/common/qtutils.cpp +++ b/app/common/qtutils.cpp @@ -58,4 +58,18 @@ int QtUtils::MessageBox(QWidget *parent, QMessageBox::Icon icon, const QString & return b.exec(); } +QDateTime QtUtils::GetCreationDate(const QFileInfo &info) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + return info.created(); +#else + return info.birthTime(); +#endif +} + +QString QtUtils::GetFormattedDateTime(const QDateTime &dt) +{ + return dt.toString(Qt::TextDate); +} + } diff --git a/app/common/qtutils.h b/app/common/qtutils.h index b4c511167..2247f89d8 100644 --- a/app/common/qtutils.h +++ b/app/common/qtutils.h @@ -27,6 +27,8 @@ * */ +#include +#include #include #include #include @@ -54,6 +56,10 @@ public: static int MessageBox(QWidget *parent, QMessageBox::Icon icon, const QString& title, const QString& message, QMessageBox::StandardButtons buttons = QMessageBox::Ok); + static QDateTime GetCreationDate(const QFileInfo &info); + + static QString GetFormattedDateTime(const QDateTime &dt); + }; } diff --git a/app/node/node.h b/app/node/node.h index 31c144d8f..5bce23c06 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -183,6 +183,9 @@ public: 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();} const QVector& inputs() const diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index addfa110c..3448bbdee 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -27,6 +27,7 @@ #include "codec/decoder.h" #include "common/clamp.h" #include "common/filefunctions.h" +#include "common/qtutils.h" #include "common/xmlutils.h" #include "config/config.h" #include "core.h" @@ -483,6 +484,28 @@ rational Footage::AdjustTimeByLoopMode(rational time, Footage::LoopMode loop_mod return time; } +qint64 Footage::creation_time() const +{ + QFileInfo info(filename()); + + if (info.exists()) { + return QtUtils::GetCreationDate(info).toSecsSinceEpoch(); + } + + return 0; +} + +qint64 Footage::mod_time() const +{ + QFileInfo info(filename()); + + if (info.exists()) { + return info.lastModified().toSecsSinceEpoch(); + } + + return 0; +} + void Footage::UpdateTooltip() { if (valid_) { diff --git a/app/node/project/footage/footage.h b/app/node/project/footage/footage.h index 4b29118c5..9f6b45c72 100644 --- a/app/node/project/footage/footage.h +++ b/app/node/project/footage/footage.h @@ -193,6 +193,9 @@ public: static rational AdjustTimeByLoopMode(rational time, LoopMode loop_mode, const rational& length, VideoParams::Type type, const rational &timebase); + virtual qint64 creation_time() const; + virtual qint64 mod_time() const; + static const QString kFilenameInput; static const QString kLoopModeInput; diff --git a/app/node/project/projectviewmodel.cpp b/app/node/project/projectviewmodel.cpp index ecc08b5dd..92b958460 100644 --- a/app/node/project/projectviewmodel.cpp +++ b/app/node/project/projectviewmodel.cpp @@ -24,6 +24,7 @@ #include #include +#include "common/qtutils.h" #include "core.h" #include "widget/nodeview/nodeviewundo.h" #include "widget/nodeparamview/nodeparamviewundo.h" @@ -34,10 +35,6 @@ ProjectViewModel::ProjectViewModel(QObject *parent) : QAbstractItemModel(parent), project_(nullptr) { - // FIXME: make this configurable - columns_.append(kName); - columns_.append(kDuration); - columns_.append(kRate); } Project *ProjectViewModel::project() const @@ -124,17 +121,18 @@ int ProjectViewModel::columnCount(const QModelIndex &parent) const return 0; } - return columns_.size(); + return kColumnCount; } QVariant ProjectViewModel::data(const QModelIndex &index, int role) const { Node* internal_item = GetItemObjectFromIndex(index); - ColumnType column_type = columns_.at(index.column()); + ColumnType column_type = static_cast(index.column()); switch (role) { case Qt::DisplayRole: + case kInnerTextRole: { // Standard text role @@ -145,6 +143,30 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const return internal_item->duration(); case kRate: return internal_item->rate(); + case kLastModified: + case kCreatedTime: + { + qint64 using_time = (column_type == kLastModified) ? internal_item->mod_time() : internal_item->creation_time(); + + if (using_time == 0) { + // 0 is the null value, return nothing + break; + } + + QVariant ret; + + if (role == kInnerTextRole) { + // Use time value directly for correct sorting + ret = using_time; + } else { + // Display role, format to a human readable string + ret = QtUtils::GetFormattedDateTime(QDateTime::fromSecsSinceEpoch(using_time)); + } + + return ret; + } + case kColumnCount: + break; } } break; @@ -166,7 +188,7 @@ QVariant ProjectViewModel::headerData(int section, Qt::Orientation orientation, // Check if we need text data (DisplayRole) and orientation is horizontal // FIXME I'm not 100% sure what happens if the orientation is vertical/if that check is necessary if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - ColumnType column_type = columns_.at(section); + ColumnType column_type = static_cast(section); // Return the name based on the column's current type switch (column_type) { @@ -176,6 +198,12 @@ QVariant ProjectViewModel::headerData(int section, Qt::Orientation orientation, return tr("Duration"); case kRate: return tr("Rate"); + case kLastModified: + return tr("Modified"); + case kCreatedTime: + return tr("Created"); + case kColumnCount: + break; } } @@ -194,7 +222,7 @@ bool ProjectViewModel::hasChildren(const QModelIndex &parent) const bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value, int role) { // The name is editable - if (index.isValid() && columns_.at(index.column()) == kName && role == Qt::EditRole) { + if (index.isValid() && index.column() == kName && role == Qt::EditRole) { Node* item = GetItemObjectFromIndex(index); QString new_name = value.toString(); @@ -233,7 +261,7 @@ Qt::ItemFlags ProjectViewModel::flags(const QModelIndex &index) const } // If the column is the kName column, that means it's editable - if (columns_.at(index.column()) == kName) { + if (index.column() == kName) { f |= Qt::ItemIsEditable; } diff --git a/app/node/project/projectviewmodel.h b/app/node/project/projectviewmodel.h index 6ffe36f2e..9528439f0 100644 --- a/app/node/project/projectviewmodel.h +++ b/app/node/project/projectviewmodel.h @@ -49,9 +49,20 @@ public: kDuration, /// Media rate (frame rate for video, sample rate for audio) - kRate + kRate, + + /// Last modified time (for footage/files) + kLastModified, + + /// Creation time (for footage/files) + kCreatedTime, + + /// Count + kColumnCount }; + static const int kInnerTextRole = Qt::UserRole + 1; + /** * @brief ProjectViewModel Constructor * @@ -137,8 +148,6 @@ private: Project* project_; - QVector columns_; - private slots: void FolderBeginInsertItem(Node *n, int insert_index); diff --git a/app/widget/projectexplorer/projectexplorer.cpp b/app/widget/projectexplorer/projectexplorer.cpp index d229cf112..fdd74e977 100644 --- a/app/widget/projectexplorer/projectexplorer.cpp +++ b/app/widget/projectexplorer/projectexplorer.cpp @@ -65,6 +65,7 @@ ProjectExplorer::ProjectExplorer(QWidget *parent) : // Set up sort filter proxy model sort_model_.setSourceModel(&model_); + sort_model_.setSortRole(ProjectViewModel::kInnerTextRole); // Add tree view to stacked widget tree_view_ = new ProjectExplorerTreeView(stacked_widget_);