Commit 938612c3 authored by Christian Kandeler's avatar Christian Kandeler Committed by hjk

Do not use QAbstractItemModel::reset().

Change-Id: Ie49bdf576a6d3543aef6df133b27c8827775c935
Rationale:
    a) It is conceptually cleaner to do the changes to the model
       in between calls to beginResetModel() and endResetModel,
       respectively.
    b) The function is deprecated in Qt 5, for exactly that reason.
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 1b3d637c
......@@ -239,6 +239,7 @@ Symbol *OverviewModel::symbolFromIndex(const QModelIndex &index) const
void OverviewModel::rebuild(Document::Ptr doc)
{
beginResetModel();
_cppDocument = doc;
reset();
endResetModel();
}
......@@ -139,8 +139,9 @@ bool HistoryCompleterPrivate::removeRows(int row, int count, const QModelIndex &
void HistoryCompleterPrivate::clearHistory()
{
beginResetModel();
list.clear();
reset();
endResetModel();
}
void HistoryCompleterPrivate::saveEntry(const QString &str)
......
......@@ -148,8 +148,9 @@ PermissionsModel::PermissionsModel(QObject *parent)
void PermissionsModel::setPermissions(const QStringList &permissions)
{
beginResetModel();
m_permissions = permissions;
reset();
endResetModel();
}
const QStringList &PermissionsModel::permissions()
......
......@@ -51,8 +51,9 @@ namespace Internal {
void AvdModel::setAvdList(const QVector<AndroidDeviceInfo> &list)
{
beginResetModel();
m_list = list;
reset();
endResetModel();
}
QString AvdModel::avdName(const QModelIndex &index)
......
......@@ -137,6 +137,8 @@ QVariant CategoryModel::data(const QModelIndex &index, int role) const
void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
const QList<IOptionsPageProvider *> &providers)
{
beginResetModel();
// Clear any previous categories
qDeleteAll(m_categories);
m_categories.clear();
......@@ -176,7 +178,7 @@ void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
category->providers.append(provider);
}
reset();
endResetModel();
}
Category *CategoryModel::findCategoryById(const QString &id)
......
......@@ -1163,18 +1163,20 @@ void BreakHandler::saveSessionData()
void BreakHandler::loadSessionData()
{
beginResetModel();
m_storage.clear();
reset();
endResetModel();
loadBreakpoints();
}
void BreakHandler::removeSessionData()
{
beginResetModel();
Iterator it = m_storage.begin(), et = m_storage.end();
for ( ; it != et; ++it)
it->destroyMarker();
m_storage.clear();
reset();
endResetModel();
}
void BreakHandler::breakByFunction(const QString &functionName)
......
......@@ -195,15 +195,17 @@ QVariant ModulesModel::data(const QModelIndex &index, int role) const
void ModulesModel::setModules(const Modules &m)
{
beginResetModel();
m_modules = m;
reset();
endResetModel();
}
void ModulesModel::clearModel()
{
if (!m_modules.isEmpty()) {
beginResetModel();
m_modules.clear();
reset();
endResetModel();
}
}
......
......@@ -182,7 +182,6 @@ QtMessageLogHandler::~QtMessageLogHandler()
void QtMessageLogHandler::clear()
{
beginResetModel();
reset();
delete m_rootItem;
m_rootItem = new QtMessageLogItem(0);
endResetModel();
......
......@@ -480,8 +480,9 @@ Qt::ItemFlags RegisterHandler::flags(const QModelIndex &idx) const
void RegisterHandler::removeAll()
{
beginResetModel();
m_registers.clear();
reset();
endResetModel();
}
bool RegisterHandler::isEmpty() const
......@@ -503,12 +504,13 @@ static inline bool compareRegisterSet(const Registers &r1, const Registers &r2)
void RegisterHandler::setRegisters(const Registers &registers)
{
beginResetModel();
m_registers = registers;
const int size = m_registers.size();
for (int r = 0; r < size; r++)
m_registers[r].changed = false;
calculateWidth();
reset();
endResetModel();
}
void RegisterHandler::setAndMarkRegisters(const Registers &registers)
......@@ -544,9 +546,10 @@ void RegisterHandler::calculateWidth()
void RegisterHandler::setNumberBase(int base)
{
if (m_base != base) {
beginResetModel();
m_base = base;
calculateWidth();
emit reset();
endResetModel();
}
}
......
......@@ -214,10 +214,11 @@ Qt::ItemFlags SnapshotHandler::flags(const QModelIndex &index) const
void SnapshotHandler::activateSnapshot(int index)
{
beginResetModel();
m_currentIndex = index;
//qDebug() << "ACTIVATING INDEX: " << m_currentIndex << " OF " << size();
debuggerCore()->displayDebugger(at(index), true);
reset();
endResetModel();
}
void SnapshotHandler::createSnapshot(int index)
......@@ -240,28 +241,31 @@ void SnapshotHandler::removeSnapshot(int index)
//QString fileName = engine->startParameters().coreFile;
//if (!fileName.isEmpty())
// QFile::remove(fileName);
beginResetModel();
m_snapshots.removeAt(index);
if (index == m_currentIndex)
m_currentIndex = -1;
else if (index < m_currentIndex)
--m_currentIndex;
//engine->quitDebugger();
reset();
endResetModel();
}
void SnapshotHandler::removeAll()
{
beginResetModel();
m_snapshots.clear();
m_currentIndex = -1;
reset();
endResetModel();
}
void SnapshotHandler::appendSnapshot(DebuggerEngine *engine)
{
beginResetModel();
m_snapshots.append(engine);
m_currentIndex = size() - 1;
reset();
endResetModel();
}
void SnapshotHandler::removeSnapshot(DebuggerEngine *engine)
......@@ -274,8 +278,9 @@ void SnapshotHandler::removeSnapshot(DebuggerEngine *engine)
void SnapshotHandler::setCurrentIndex(int index)
{
beginResetModel();
m_currentIndex = index;
reset();
endResetModel();
}
DebuggerEngine *SnapshotHandler::at(int i) const
......
......@@ -76,7 +76,7 @@ private:
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
Q_SLOT void resetModel() { reset(); }
Q_SLOT void resetModel() { beginResetModel(); endResetModel(); }
int m_currentIndex;
QList< QPointer<DebuggerEngine> > m_snapshots;
......
......@@ -49,9 +49,10 @@ void SourceFilesHandler::clearModel()
{
if (m_shortNames.isEmpty())
return;
beginResetModel();
m_shortNames.clear();
m_fullNames.clear();
reset();
endResetModel();
}
QVariant SourceFilesHandler::headerData(int section,
......@@ -101,6 +102,7 @@ QVariant SourceFilesHandler::data(const QModelIndex &index, int role) const
void SourceFilesHandler::setSourceFiles(const QMap<QString, QString> &sourceFiles)
{
beginResetModel();
m_shortNames.clear();
m_fullNames.clear();
QMap<QString, QString>::ConstIterator it = sourceFiles.begin();
......@@ -109,7 +111,7 @@ void SourceFilesHandler::setSourceFiles(const QMap<QString, QString> &sourceFile
m_shortNames.append(it.key());
m_fullNames.append(it.value());
}
reset();
endResetModel();
}
void SourceFilesHandler::removeAll()
......
......@@ -56,7 +56,6 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const;
void clearModel();
void update() { reset(); }
void setSourceFiles(const QMap<QString, QString> &sourceFiles);
void removeAll();
......
......@@ -184,13 +184,15 @@ void StackHandler::setCurrentIndex(int level)
void StackHandler::removeAll()
{
beginResetModel();
m_stackFrames.clear();
setCurrentIndex(-1);
reset();
endResetModel();
}
void StackHandler::setFrames(const StackFrames &frames, bool canExpand)
{
beginResetModel();
m_resetLocationScheduled = false;
m_contentsValid = true;
m_canExpand = canExpand;
......@@ -199,7 +201,7 @@ void StackHandler::setFrames(const StackFrames &frames, bool canExpand)
setCurrentIndex(0);
else
m_currentIndex = -1;
reset();
endResetModel();
emit stackChanged();
}
......@@ -217,8 +219,9 @@ void StackHandler::scheduleResetLocation()
void StackHandler::resetLocation()
{
if (m_resetLocationScheduled) {
beginResetModel();
m_resetLocationScheduled = false;
reset();
endResetModel();
}
}
......
......@@ -94,7 +94,7 @@ private:
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
Q_SLOT void resetModel() { reset(); }
Q_SLOT void resetModel() { beginResetModel(); endResetModel(); }
StackFrames m_stackFrames;
int m_currentIndex;
......
......@@ -249,12 +249,13 @@ int ThreadsHandler::indexOf(quint64 threadId) const
void ThreadsHandler::setThreads(const Threads &threads)
{
beginResetModel();
m_threads = threads;
if (m_currentIndex >= m_threads.size())
m_currentIndex = -1;
m_resetLocationScheduled = false;
m_contentsValid = true;
reset();
endResetModel();
updateThreadBox();
}
......@@ -273,9 +274,10 @@ Threads ThreadsHandler::threads() const
void ThreadsHandler::removeAll()
{
beginResetModel();
m_threads.clear();
m_currentIndex = 0;
reset();
endResetModel();
}
void ThreadsHandler::notifyRunning()
......@@ -334,8 +336,9 @@ void ThreadsHandler::scheduleResetLocation()
void ThreadsHandler::resetLocation()
{
if (m_resetLocationScheduled) {
beginResetModel();
m_resetLocationScheduled = false;
reset();
endResetModel();
}
}
......
......@@ -411,10 +411,11 @@ QList<QModelIndex> SearchResultTreeModel::addResults(const QList<SearchResultIte
void SearchResultTreeModel::clear()
{
beginResetModel();
m_currentParent = NULL;
m_rootItem->clearChildren();
m_editorFontIsUsed = false;
reset();
endResetModel();
}
QModelIndex SearchResultTreeModel::nextIndex(const QModelIndex &idx, bool *wrapped) const
......
......@@ -205,8 +205,9 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
void LocatorModel::setEntries(const QList<FilterEntry> &entries)
{
beginResetModel();
mEntries = entries;
reset();
endResetModel();
}
// =========== CompletionList ===========
......
......@@ -82,9 +82,10 @@ DependenciesModel::~DependenciesModel()
void DependenciesModel::resetModel()
{
beginResetModel();
m_projects = m_session->projects();
m_projects.removeAll(m_project);
reset();
endResetModel();
}
int DependenciesModel::rowCount(const QModelIndex &index) const
......
......@@ -452,8 +452,9 @@ void FlatModel::setStartupProject(ProjectNode *projectNode)
void FlatModel::reset()
{
beginResetModel();
m_childNodes.clear();
QAbstractItemModel::reset();
endResetModel();
}
QModelIndex FlatModel::indexForNode(const Node *node_)
......
......@@ -111,7 +111,8 @@ bool SessionModel::isDefaultVirgin() const
void SessionModel::resetSessions()
{
reset();
beginResetModel();
endResetModel();
}
void SessionModel::cloneSession(const QString &session)
......@@ -124,8 +125,9 @@ void SessionModel::cloneSession(const QString &session)
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_manager->sessions().contains(newSession))
return;
beginResetModel();
m_manager->cloneSession(session, newSession);
reset();
endResetModel();
if (newSessionInputDialog.isSwitchToRequested()) {
m_manager->loadSession(newSession);
......@@ -135,8 +137,9 @@ void SessionModel::cloneSession(const QString &session)
void SessionModel::deleteSession(const QString &session)
{
beginResetModel();
m_manager->deleteSession(session);
reset();
endResetModel();
}
void SessionModel::renameSession(const QString &session)
......@@ -149,8 +152,9 @@ void SessionModel::renameSession(const QString &session)
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_manager->sessions().contains(newSession))
return;
beginResetModel();
m_manager->renameSession(session, newSession);
reset();
endResetModel();
if (newSessionInputDialog.isSwitchToRequested()) {
m_manager->loadSession(newSession);
......@@ -194,7 +198,8 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
void ProjectModel::resetProjects()
{
reset();
beginResetModel();
endResetModel();
}
///////////////////
......
......@@ -1092,10 +1092,11 @@ QModelIndex ResourceModel::deleteItem(const QModelIndex &idx)
bool ResourceModel::reload()
{
beginResetModel();
const bool result = m_resource_file.load();
if (result)
setDirty(false);
reset();
endResetModel();
return result;
}
......
......@@ -62,8 +62,9 @@ public:
void setFormatDescriptions(const FormatDescriptions *descriptions)
{
beginResetModel();
m_descriptions = descriptions;
reset();
endResetModel();
}
void setBaseFont(const QFont &font)
......
......@@ -101,8 +101,9 @@ public:
void setColorSchemes(const QList<ColorSchemeEntry> &colorSchemes)
{
beginResetModel();
m_colorSchemes = colorSchemes;
reset();
endResetModel();
}
const ColorSchemeEntry &colorSchemeAt(int index) const
......
......@@ -165,8 +165,9 @@ QVariant SnippetsTableModel::headerData(int section, Qt::Orientation orientation
void SnippetsTableModel::load(const QString &groupId)
{
beginResetModel();
m_activeGroupId = groupId;
reset();
endResetModel();
}
QList<QString> SnippetsTableModel::groupIds() const
......@@ -219,14 +220,16 @@ void SnippetsTableModel::revertBuitInSnippet(const QModelIndex &modelIndex)
void SnippetsTableModel::restoreRemovedBuiltInSnippets()
{
beginResetModel();
m_collection->restoreRemovedSnippets(m_activeGroupId);
reset();
endResetModel();
}
void SnippetsTableModel::resetSnippets()
{
beginResetModel();
m_collection->reset(m_activeGroupId);
reset();
endResetModel();
}
void SnippetsTableModel::replaceSnippet(const Snippet &snippet, const QModelIndex &modelIndex)
......
......@@ -221,8 +221,9 @@ void StackModel::setError(const Error &error)
{
if (d->error == error)
return;
beginResetModel();
d->error = error;
reset();
endResetModel();
}
void StackModel::clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment