diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2014-01-27 22:15:48 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2014-02-04 11:30:26 +0100 |
commit | d89d26ab4ddf43f0f0d8625820b607099f6c9642 (patch) | |
tree | 206de77210f10d773819a74cc5a9f8b7d499bcf9 /src/plugins/cppeditor/cppinsertvirtualmethods.cpp | |
parent | 524c37112fd6bb67f5b07272d98b5c89ef6f2190 (diff) |
CppEditor: Enable choosing any override in Insert Virtual Methods
Change-Id: I839cfeb2650f991bcf9660e5ccbfa52452917eb8
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cppeditor/cppinsertvirtualmethods.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppinsertvirtualmethods.cpp | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/src/plugins/cppeditor/cppinsertvirtualmethods.cpp b/src/plugins/cppeditor/cppinsertvirtualmethods.cpp index a5f0e02037..5b354e3ad5 100644 --- a/src/plugins/cppeditor/cppinsertvirtualmethods.cpp +++ b/src/plugins/cppeditor/cppinsertvirtualmethods.cpp @@ -180,6 +180,7 @@ public: bool reimplemented; bool alreadyFound; bool checked; + FunctionItem *nextOverride; private: QString name; @@ -201,7 +202,7 @@ ClassItem::~ClassItem() Qt::ItemFlags ClassItem::flags() const { foreach (FunctionItem *func, functions) { - if (!func->alreadyFound && !func->reimplemented) + if (!func->alreadyFound) return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; } @@ -226,7 +227,8 @@ FunctionItem::FunctionItem(const Function *func, const QString &functionName, Cl function(func), reimplemented(false), alreadyFound(false), - checked(false) + checked(false), + nextOverride(this) { name = functionName; } @@ -239,7 +241,7 @@ QString FunctionItem::description() const Qt::ItemFlags FunctionItem::flags() const { Qt::ItemFlags res = Qt::NoItemFlags; - if (!reimplemented && !alreadyFound) + if (!alreadyFound) res |= Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled; return res; } @@ -356,17 +358,23 @@ public: case Qt::CheckStateRole: { bool checked = value.toInt() == Qt::Checked; if (item->parent()) { - static_cast<FunctionItem *>(item)->checked = checked; - const QModelIndex parentIndex = parent(index); - emit dataChanged(parentIndex, parentIndex); + FunctionItem *funcItem = static_cast<FunctionItem *>(item); + while (funcItem->checked != checked) { + funcItem->checked = checked; + const QModelIndex funcIndex = createIndex(funcItem->row, 0, funcItem); + emit dataChanged(funcIndex, funcIndex); + const QModelIndex parentIndex = + createIndex(funcItem->parent()->row, 0, funcItem->parent()); + emit dataChanged(parentIndex, parentIndex); + funcItem = funcItem->nextOverride; + } } else { ClassItem *classItem = static_cast<ClassItem *>(item); foreach (FunctionItem *funcItem, classItem->functions) { - if (!funcItem->reimplemented && funcItem->checked != checked) { - funcItem->checked = checked; - QModelIndex funcIndex = createIndex(funcItem->row, 0, funcItem); - emit dataChanged(funcIndex, funcIndex); - } + if (funcItem->alreadyFound || funcItem->checked == checked) + continue; + QModelIndex funcIndex = createIndex(funcItem->row, 0, funcItem); + setData(funcIndex, value, role); } } return true; @@ -529,9 +537,17 @@ public: if (isReimplemented) { factory->setHasReimplementedFunctions(true); funcItem->reimplemented = true; + funcItem->alreadyFound = funcExistsInClass; if (FunctionItem *first = virtualFunctions[firstVirtual]) { - if (!first->reimplemented) - first->checked = isPureVirtual; + if (!first->alreadyFound) { + while (first->checked != isPureVirtual) { + first->checked = isPureVirtual; + first = first->nextOverride; + } + } + funcItem->checked = first->checked; + funcItem->nextOverride = first->nextOverride; + first->nextOverride = funcItem; } } else { if (!funcExistsInClass) { @@ -641,18 +657,21 @@ public: if (classItem->checkState() == Qt::Unchecked) continue; - // Add comment - const QString comment = QLatin1String("\n// ") + - printer.prettyName(classItem->klass->name()) + - QLatin1String(" interface\n"); - headerChangeSet.insert(m_insertPosDecl, comment); - // Insert Declarations (+ definitions) QString lastAccessSpecString; + bool first = true; foreach (FunctionItem *funcItem, classItem->functions) { if (funcItem->reimplemented || funcItem->alreadyFound || !funcItem->checked) continue; + if (first) { + // Add comment + const QString comment = QLatin1String("\n// ") + + printer.prettyName(classItem->klass->name()) + + QLatin1String(" interface\n"); + headerChangeSet.insert(m_insertPosDecl, comment); + first = false; + } // Construct declaration // setup rewriting to get minimally qualified names SubstitutionEnvironment env; |