fixed #597
This commit is contained in:
+2
-10
@@ -327,11 +327,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
||||
|
||||
item->set_footage(f);
|
||||
|
||||
if (folder == 0) {
|
||||
olive::project_model.appendChild(nullptr, item);
|
||||
} else {
|
||||
find_loaded_folder_by_id(folder)->appendChild(item);
|
||||
}
|
||||
olive::project_model.appendChild(find_loaded_folder_by_id(folder), item);
|
||||
|
||||
// analyze media to see if it's the same
|
||||
loaded_media_items.append(item);
|
||||
@@ -623,11 +619,7 @@ void LoadThread::run() {
|
||||
for (int i=0;i<loaded_folders.size();i++) {
|
||||
Media* folder = loaded_folders.at(i);
|
||||
int parent = folder->temp_id2;
|
||||
if (folder->temp_id2 == 0) {
|
||||
olive::project_model.appendChild(nullptr, folder);
|
||||
} else {
|
||||
find_loaded_folder_by_id(parent)->appendChild(folder);
|
||||
}
|
||||
olive::project_model.appendChild(find_loaded_folder_by_id(parent), folder);
|
||||
}
|
||||
|
||||
cont = load_worker(file, stream, MEDIA_TYPE_FOOTAGE);
|
||||
|
||||
+3
-5
@@ -441,11 +441,9 @@ Media* Project::create_sequence_internal(ComboAction *ca, SequencePtr s, bool op
|
||||
ca->append(new NewSequenceCommand(item, parent));
|
||||
if (open) ca->append(new ChangeSequenceAction(s));
|
||||
} else {
|
||||
if (parent == olive::project_model.get_root()) {
|
||||
olive::project_model.appendChild(parent, item);
|
||||
} else {
|
||||
parent->appendChild(item);
|
||||
}
|
||||
|
||||
olive::project_model.appendChild(parent, item);
|
||||
|
||||
if (open) {
|
||||
olive::Global->set_sequence(s);
|
||||
}
|
||||
|
||||
+3
-2
@@ -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;
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user