mirror of https://github.com/mgba-emu/mgba.git
switch away from APIs removed / compatibility-broken by upstream
This commit is contained in:
parent
578709254f
commit
130319494a
|
@ -192,7 +192,7 @@ void LibraryController::refresh() {
|
|||
|
||||
setDisabled(true);
|
||||
|
||||
QSet<QString> removedEntries = QSet<QString>::fromList(m_knownGames.keys());
|
||||
QSet<QString> removedEntries(m_knownGames.keyBegin(), m_knownGames.keyEnd());
|
||||
QList<LibraryEntry> updatedEntries;
|
||||
QList<LibraryEntry> newEntries;
|
||||
|
||||
|
@ -217,7 +217,7 @@ void LibraryController::refresh() {
|
|||
m_knownGames.remove(path);
|
||||
}
|
||||
|
||||
m_libraryModel->removeEntries(removedEntries.toList());
|
||||
m_libraryModel->removeEntries(QList<QString>(removedEntries.begin(), removedEntries.end()));
|
||||
m_libraryModel->updateEntries(updatedEntries);
|
||||
m_libraryModel->addEntries(newEntries);
|
||||
|
||||
|
|
|
@ -102,11 +102,11 @@ void LibraryModel::addEntries(const QList<LibraryEntry>& items) {
|
|||
|
||||
void LibraryModel::addEntryInternal(const LibraryEntry& item) {
|
||||
m_gameIndex[item.fullpath] = m_games.size();
|
||||
m_games << item;
|
||||
m_games.emplace_back(new LibraryEntry(item));
|
||||
if (!m_pathIndex.contains(item.base)) {
|
||||
m_pathOrder << item.base;
|
||||
}
|
||||
m_pathIndex[item.base] << &m_games.back();
|
||||
m_pathIndex[item.base] << m_games.back().get();
|
||||
}
|
||||
|
||||
void LibraryModel::addEntriesList(const QList<LibraryEntry>& items) {
|
||||
|
@ -158,7 +158,7 @@ void LibraryModel::updateEntries(const QList<LibraryEntry>& items) {
|
|||
Q_ASSERT(idx.isValid());
|
||||
int pos = m_gameIndex.value(item.fullpath, -1);
|
||||
Q_ASSERT(pos >= 0);
|
||||
m_games[pos] = item;
|
||||
*m_games[pos] = item;
|
||||
updatedSpans[idx.parent()].add(pos);
|
||||
}
|
||||
for (auto iter = updatedSpans.begin(); iter != updatedSpans.end(); iter++) {
|
||||
|
@ -183,11 +183,13 @@ void LibraryModel::removeEntries(const QList<QString>& items) {
|
|||
if (pos < firstModifiedIndex) {
|
||||
firstModifiedIndex = pos;
|
||||
}
|
||||
LibraryEntry* entry = &m_games[pos];
|
||||
LibraryEntry* entry = m_games[pos].get();
|
||||
QModelIndex parent = indexForPath(entry->base);
|
||||
Q_ASSERT(!m_treeMode || parent.isValid());
|
||||
QList<const LibraryEntry*>& pathItems = m_pathIndex[entry->base];
|
||||
removedTreeSpans[entry->base].add(pathItems.indexOf(entry));
|
||||
int pathPos = pathItems.indexOf(entry);
|
||||
Q_ASSERT(pathPos >= 0);
|
||||
removedTreeSpans[entry->base].add(pathPos);
|
||||
if (!m_treeMode) {
|
||||
removedRootSpans.add(pos);
|
||||
}
|
||||
|
@ -214,9 +216,6 @@ void LibraryModel::removeEntries(const QList<QString>& items) {
|
|||
for (const SpanSet::Span& span : spanSet.spans) {
|
||||
if (m_treeMode) {
|
||||
beginRemoveRows(parent, span.left, span.right);
|
||||
for (int i = span.left; i <= span.right; i++) {
|
||||
|
||||
}
|
||||
}
|
||||
pathIndex.erase(pathIndex.begin() + span.left, pathIndex.begin() + span.right + 1);
|
||||
if (m_treeMode) {
|
||||
|
@ -238,8 +237,8 @@ void LibraryModel::removeEntries(const QList<QString>& items) {
|
|||
}
|
||||
endRemoveRows();
|
||||
}
|
||||
for (int i = m_games.count() - 1; i >= firstModifiedIndex; i--) {
|
||||
m_gameIndex[m_games[i].fullpath] = i;
|
||||
for (int i = m_games.size() - 1; i >= firstModifiedIndex; i--) {
|
||||
m_gameIndex[m_games[i]->fullpath] = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,7 +248,7 @@ QModelIndex LibraryModel::index(const QString& game) const {
|
|||
return QModelIndex();
|
||||
}
|
||||
if (m_treeMode) {
|
||||
const LibraryEntry& entry = m_games[pos];
|
||||
const LibraryEntry& entry = *m_games[pos];
|
||||
return createIndex(m_pathIndex[entry.base].indexOf(&entry), 0, m_pathOrder.indexOf(entry.base));
|
||||
}
|
||||
return createIndex(pos, 0);
|
||||
|
@ -339,8 +338,8 @@ QVariant LibraryModel::data(const QModelIndex& index, int role) const {
|
|||
}
|
||||
QString path = m_pathOrder[index.parent().row()];
|
||||
entry = m_pathIndex[path][index.row()];
|
||||
} else if (!index.parent().isValid() && index.row() < m_games.size()) {
|
||||
entry = &m_games[index.row()];
|
||||
} else if (!index.parent().isValid() && index.row() < (int)m_games.size()) {
|
||||
entry = m_games[index.row()].get();
|
||||
}
|
||||
if (entry) {
|
||||
if (role == FullPathRole) {
|
||||
|
@ -414,5 +413,5 @@ LibraryEntry LibraryModel::entry(const QString& game) const {
|
|||
if (pos < 0) {
|
||||
return {};
|
||||
}
|
||||
return m_games[pos];
|
||||
return *m_games[pos];
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
#include <mgba/core/library.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "LibraryEntry.h"
|
||||
|
||||
class QTreeView;
|
||||
|
@ -71,7 +74,7 @@ private:
|
|||
bool m_treeMode;
|
||||
bool m_showFilename;
|
||||
|
||||
QList<LibraryEntry> m_games;
|
||||
std::vector<std::unique_ptr<LibraryEntry>> m_games;
|
||||
QStringList m_pathOrder;
|
||||
QHash<QString, QList<const LibraryEntry*>> m_pathIndex;
|
||||
QHash<QString, int> m_gameIndex;
|
||||
|
|
Loading…
Reference in New Issue