This commit is contained in:
itsmattkc
2019-03-05 20:35:58 -08:00
parent 95977143d0
commit d287963c10
5 changed files with 62 additions and 46 deletions
+3 -2
View File
@@ -86,7 +86,6 @@ void Media::set_footage(FootagePtr f) {
}
void Media::set_sequence(SequencePtr s) {
// ensure icon setting occurs in a separate thread
set_icon(":/icons/sequence.svg");
type = MEDIA_TYPE_SEQUENCE;
object = VoidPtr(s);
@@ -94,7 +93,9 @@ void Media::set_sequence(SequencePtr s) {
}
void Media::set_folder() {
if (folder_name.isEmpty()) folder_name = QCoreApplication::translate("Media", "New Folder");
if (folder_name.isEmpty()) {
folder_name = QCoreApplication::translate("Media", "New Folder");
}
set_icon(":/icons/folder.svg");
type = MEDIA_TYPE_FOLDER;
object = nullptr;
+25 -2
View File
@@ -115,7 +115,30 @@ QModelIndex ProjectModel::parent(const QModelIndex &index) const {
if (parentItem == root_item)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
return createIndex(parentItem->row(), 0, parentItem);
}
bool ProjectModel::canFetchMore(const QModelIndex &parent) const
{
// Mostly implementing this because QSortFilterProxyModel will actually *ignore* a "true" result from hasChildren()
// and then query this value for a "true" result. So we need to override both this and hasChildren() to show a
// persistent childIndicator for folder items.
if (parent.isValid()
&& static_cast<Media*>(parent.internalPointer())->get_type() == MEDIA_TYPE_FOLDER) {
return true;
}
return QAbstractItemModel::canFetchMore(parent);
}
bool ProjectModel::hasChildren(const QModelIndex &parent) const
{
if (parent.isValid()
&& static_cast<Media*>(parent.internalPointer())->get_type() == MEDIA_TYPE_FOLDER) {
return true;
}
return QAbstractItemModel::hasChildren(parent);
}
bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int role) {
@@ -132,7 +155,7 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int
}
int ProjectModel::rowCount(const QModelIndex &parent) const {
Media *parentItem;
Media *parentItem;
if (parent.column() > 0)
return 0;
+29 -27
View File
@@ -27,41 +27,43 @@
class ProjectModel : public QAbstractItemModel
{
Q_OBJECT
Q_OBJECT
public:
ProjectModel(QObject* parent = nullptr);
~ProjectModel() override;
ProjectModel(QObject* parent = nullptr);
~ProjectModel() override;
void make_root();
void destroy_root();
void clear();
Media* get_root();
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex create_index(int arow, int acolumn, void *adata);
QModelIndex parent(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Media* getItem(const QModelIndex &index) const;
void make_root();
void destroy_root();
void clear();
Media* get_root();
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override;
QModelIndex create_index(int arow, int acolumn, void *adata);
QModelIndex parent(const QModelIndex &index) const override;
bool canFetchMore(const QModelIndex &parent) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Media* getItem(const QModelIndex &index) const;
void appendChild(Media* parent, Media* child);
void moveChild(Media* child, Media* to);
void removeChild(Media* parent, Media* m);
Media* child(int i, Media* parent = nullptr);
int childCount(Media* parent = nullptr);
void set_icon(Media* m, const QIcon &ico);
void appendChild(Media* parent, Media* child);
void moveChild(Media* child, Media* to);
void removeChild(Media* parent, Media* m);
Media* child(int i, Media* parent = nullptr);
int childCount(Media* parent = nullptr);
void set_icon(Media* m, const QIcon &ico);
private:
Media* root_item;
Media* root_item;
};
namespace olive {
extern ProjectModel project_model;
extern ProjectModel project_model;
}
#endif // PROJECTMODEL_H