CollectionModel: Reset model before deletion
This commit is contained in:
parent
f9acfbc224
commit
4c1a5168f0
|
@ -142,7 +142,9 @@ CollectionModel::~CollectionModel() {
|
||||||
|
|
||||||
qLog(Debug) << "Collection model" << this << "for" << Song::TextForSource(backend_->source()) << "deleted";
|
qLog(Debug) << "Collection model" << this << "for" << Song::TextForSource(backend_->source()) << "deleted";
|
||||||
|
|
||||||
delete root_;
|
beginResetModel();
|
||||||
|
Clear();
|
||||||
|
endResetModel();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +201,8 @@ void CollectionModel::ReloadSettings() {
|
||||||
|
|
||||||
void CollectionModel::Init(const bool async) {
|
void CollectionModel::Init(const bool async) {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
if (async) {
|
if (async) {
|
||||||
// Show a loading indicator in the model.
|
// Show a loading indicator in the model.
|
||||||
CollectionItem *loading = new CollectionItem(CollectionItem::Type_LoadingIndicator, root_);
|
CollectionItem *loading = new CollectionItem(CollectionItem::Type_LoadingIndicator, root_);
|
||||||
|
@ -222,6 +226,8 @@ void CollectionModel::Init(const bool async) {
|
||||||
|
|
||||||
void CollectionModel::SongsDiscovered(const SongList &songs) {
|
void CollectionModel::SongsDiscovered(const SongList &songs) {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
for (const Song &song : songs) {
|
for (const Song &song : songs) {
|
||||||
|
|
||||||
// Sanity check to make sure we don't add songs that are outside the user's filter
|
// Sanity check to make sure we don't add songs that are outside the user's filter
|
||||||
|
@ -519,6 +525,8 @@ QString CollectionModel::DividerDisplayText(const GroupBy group_by, const QStrin
|
||||||
|
|
||||||
void CollectionModel::SongsDeleted(const SongList &songs) {
|
void CollectionModel::SongsDeleted(const SongList &songs) {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
// Delete the actual song nodes first, keeping track of each parent so we might check to see if they're empty later.
|
// Delete the actual song nodes first, keeping track of each parent so we might check to see if they're empty later.
|
||||||
QSet<CollectionItem*> parents;
|
QSet<CollectionItem*> parents;
|
||||||
for (const Song &song : songs) {
|
for (const Song &song : songs) {
|
||||||
|
@ -923,6 +931,8 @@ CollectionModel::QueryResult CollectionModel::RunQuery(const CollectionFilterOpt
|
||||||
|
|
||||||
void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::QueryResult &result, const bool signal) {
|
void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::QueryResult &result, const bool signal) {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
// Information about what we want the children to be
|
// Information about what we want the children to be
|
||||||
int child_level = parent == root_ ? 0 : parent->container_level + 1;
|
int child_level = parent == root_ ? 0 : parent->container_level + 1;
|
||||||
GroupBy child_group_by = child_level >= 3 ? GroupBy::None : group_by_[child_level];
|
GroupBy child_group_by = child_level >= 3 ? GroupBy::None : group_by_[child_level];
|
||||||
|
@ -949,6 +959,8 @@ void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::Q
|
||||||
|
|
||||||
void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
|
void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
if (parent->lazy_loaded) return;
|
if (parent->lazy_loaded) return;
|
||||||
parent->lazy_loaded = true;
|
parent->lazy_loaded = true;
|
||||||
|
|
||||||
|
@ -960,6 +972,8 @@ void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
|
||||||
|
|
||||||
void CollectionModel::ResetAsync() {
|
void CollectionModel::ResetAsync() {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
CollectionQueryOptions query_options = PrepareQuery(root_);
|
CollectionQueryOptions query_options = PrepareQuery(root_);
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
@ -975,6 +989,8 @@ void CollectionModel::ResetAsync() {
|
||||||
|
|
||||||
void CollectionModel::ResetAsyncQueryFinished() {
|
void CollectionModel::ResetAsyncQueryFinished() {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
QFutureWatcher<CollectionModel::QueryResult> *watcher = static_cast<QFutureWatcher<CollectionModel::QueryResult>*>(sender());
|
QFutureWatcher<CollectionModel::QueryResult> *watcher = static_cast<QFutureWatcher<CollectionModel::QueryResult>*>(sender());
|
||||||
const struct QueryResult result = watcher->result();
|
const struct QueryResult result = watcher->result();
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
|
@ -995,10 +1011,12 @@ void CollectionModel::ResetAsyncQueryFinished() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionModel::BeginReset() {
|
void CollectionModel::Clear() {
|
||||||
|
|
||||||
beginResetModel();
|
if (root_) {
|
||||||
delete root_;
|
delete root_;
|
||||||
|
root_ = nullptr;
|
||||||
|
}
|
||||||
song_nodes_.clear();
|
song_nodes_.clear();
|
||||||
container_nodes_[0].clear();
|
container_nodes_[0].clear();
|
||||||
container_nodes_[1].clear();
|
container_nodes_[1].clear();
|
||||||
|
@ -1007,6 +1025,13 @@ void CollectionModel::BeginReset() {
|
||||||
pending_art_.clear();
|
pending_art_.clear();
|
||||||
pending_cache_keys_.clear();
|
pending_cache_keys_.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollectionModel::BeginReset() {
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
Clear();
|
||||||
|
|
||||||
root_ = new CollectionItem(this);
|
root_ = new CollectionItem(this);
|
||||||
root_->compilation_artist_node_ = nullptr;
|
root_->compilation_artist_node_ = nullptr;
|
||||||
root_->lazy_loaded = false;
|
root_->lazy_loaded = false;
|
||||||
|
@ -1641,6 +1666,8 @@ CollectionItem *CollectionModel::ItemFromSong(const GroupBy group_by, const bool
|
||||||
|
|
||||||
void CollectionModel::FinishItem(const GroupBy group_by, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item) {
|
void CollectionModel::FinishItem(const GroupBy group_by, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item) {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
if (group_by == GroupBy::None) item->lazy_loaded = true;
|
if (group_by == GroupBy::None) item->lazy_loaded = true;
|
||||||
|
|
||||||
if (signal) {
|
if (signal) {
|
||||||
|
@ -1982,6 +2009,8 @@ void CollectionModel::ClearDiskCache() {
|
||||||
|
|
||||||
void CollectionModel::ExpandAll(CollectionItem *item) const {
|
void CollectionModel::ExpandAll(CollectionItem *item) const {
|
||||||
|
|
||||||
|
if (!root_) return;
|
||||||
|
|
||||||
if (!item) item = root_;
|
if (!item) item = root_;
|
||||||
const_cast<CollectionModel*>(this)->LazyPopulate(const_cast<CollectionItem*>(item), false);
|
const_cast<CollectionModel*>(this)->LazyPopulate(const_cast<CollectionItem*>(item), false);
|
||||||
for (CollectionItem *child : item->children) {
|
for (CollectionItem *child : item->children) {
|
||||||
|
|
|
@ -245,6 +245,7 @@ class CollectionModel : public SimpleTreeModel<CollectionItem> {
|
||||||
|
|
||||||
bool HasCompilations(const QSqlDatabase &db, const CollectionFilterOptions &filter_options, const CollectionQueryOptions &query_options);
|
bool HasCompilations(const QSqlDatabase &db, const CollectionFilterOptions &filter_options, const CollectionQueryOptions &query_options);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
void BeginReset();
|
void BeginReset();
|
||||||
|
|
||||||
// Functions for working with queries and creating items.
|
// Functions for working with queries and creating items.
|
||||||
|
|
Loading…
Reference in New Issue