project: implemented modified and created date columns
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QFontMetrics>
|
||||
#include <QFrame>
|
||||
#include <QMessageBox>
|
||||
@@ -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);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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<QString>& inputs() const
|
||||
|
||||
@@ -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_) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
|
||||
#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<ColumnType>(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<ColumnType>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ColumnType> columns_;
|
||||
|
||||
private slots:
|
||||
void FolderBeginInsertItem(Node *n, int insert_index);
|
||||
|
||||
|
||||
@@ -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_);
|
||||
|
||||
Reference in New Issue
Block a user