Commit b7280455 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppEditor: Move InsertVirtualMethods to its own file



It contains many components, doesn't make sense to have it with all
other quickfixes.

Change-Id: Idede14c90ba9b612ae9e9048f5795d674811acfe
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent f84074b8
......@@ -29,7 +29,8 @@ HEADERS += \
cppsnippetprovider.h \
cpptypehierarchy.h \
cppvirtualfunctionassistprovider.h \
cppvirtualfunctionproposalitem.h
cppvirtualfunctionproposalitem.h \
cppinsertvirtualmethods.h
SOURCES += \
cppautocompleter.cpp \
......@@ -56,7 +57,8 @@ SOURCES += \
cppsnippetprovider.cpp \
cpptypehierarchy.cpp \
cppvirtualfunctionassistprovider.cpp \
cppvirtualfunctionproposalitem.cpp
cppvirtualfunctionproposalitem.cpp \
cppinsertvirtualmethods.cpp
FORMS += \
cpppreprocessordialog.ui \
......@@ -68,13 +70,12 @@ RESOURCES += \
equals(TEST, 1) {
HEADERS += \
cppeditortestcase.h \
cppquickfix_test_utils.h
cppquickfix_test.h
SOURCES += \
cppdoxygen_test.cpp \
cppeditortestcase.cpp \
cppincludehierarchy_test.cpp \
cppquickfix_test.cpp \
cppquickfix_test_utils.cpp \
fileandtokenactions_test.cpp \
followsymbol_switchmethoddecldef_test.cpp
DEFINES += SRCDIR=\\\"$$PWD\\\"
......
This diff is collapsed.
......@@ -27,22 +27,32 @@
**
****************************************************************************/
#ifndef INSERTVIRTUALMETHODS_H
#define INSERTVIRTUALMETHODS_H
#ifndef CPPQUICKFIX_TEST_UTILS_H
#define CPPQUICKFIX_TEST_UTILS_H
#include "cppquickfix.h"
#include "cppquickfixes.h"
namespace CppEditor {
namespace Internal {
/// Fake dialog of InsertVirtualMethodsDialog that does not pop up anything.
class InsertVirtualMethodsDialogTest : public CppEditor::Internal::InsertVirtualMethodsDialog
class InsertVirtualMethodsDialog;
class InsertVirtualMethods : public CppQuickFixFactory
{
Q_OBJECT
public:
InsertVirtualMethodsDialogTest(ImplementationMode mode, bool insertVirtualKeyword,
QWidget *parent = 0);
InsertVirtualMethods(InsertVirtualMethodsDialog *dialog = 0);
~InsertVirtualMethods();
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result);
#ifdef WITH_TESTS
static InsertVirtualMethods *createTestFactory();
#endif
bool gather();
ImplementationMode implementationMode() const;
bool insertKeywordVirtual() const;
private:
InsertVirtualMethodsDialog *m_dialog;
};
#endif // CPPQUICKFIX_TEST_UTILS_H
} // namespace Internal
} // namespace CppEditor
#endif // INSERTVIRTUALMETHODS_H
This diff is collapsed.
......@@ -27,32 +27,75 @@
**
****************************************************************************/
#include "cppquickfix_test_utils.h"
#include "cppeditortestcase.h"
#include "cppquickfixes.h"
#include <QByteArray>
#include <QList>
#include <QSharedPointer>
#include <QStringList>
using namespace CppEditor::Internal;
typedef QByteArray _;
InsertVirtualMethodsDialogTest::InsertVirtualMethodsDialogTest(ImplementationMode mode,
bool insertVirtualKeyword,
QWidget *parent)
: InsertVirtualMethodsDialog(parent)
{
setImplementationsMode(mode);
setInsertKeywordVirtual(insertVirtualKeyword);
}
namespace CppTools { class CppCodeStylePreferences; }
namespace TextEditor { class QuickFixOperation; }
InsertVirtualMethodsDialog::ImplementationMode InsertVirtualMethodsDialogTest::implementationMode() const
{
return m_implementationMode;
}
namespace CppEditor {
namespace Internal {
namespace Tests {
bool InsertVirtualMethodsDialogTest::insertKeywordVirtual() const
/**
* Represents a test document before and after applying the quick fix.
*
* A TestDocument's source may contain an '@' character to denote
* the cursor position. This marker is removed before the Editor reads
* the document.
*/
class QuickFixTestDocument : public TestDocument
{
return m_insertKeywordVirtual;
}
public:
typedef QSharedPointer<QuickFixTestDocument> Ptr;
QuickFixTestDocument(const QByteArray &fileName, const QByteArray &source,
const QByteArray &expectedSource);
bool InsertVirtualMethodsDialogTest::gather()
static Ptr create(const QByteArray &fileName, const QByteArray &source,
const QByteArray &expectedSource);
public:
QByteArray m_expectedSource;
};
/**
* Encapsulates the whole process of setting up an editor, getting the
* quick-fix, applying it, and checking the result.
*/
class QuickFixTestCase : public TestCase
{
return true;
}
public:
QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> theTestFiles,
CppQuickFixFactory *factory,
const QStringList &includePaths = QStringList(),
int resultIndex = 0);
~QuickFixTestCase();
private:
QSharedPointer<TextEditor::QuickFixOperation> getFix(CppQuickFixFactory *factory,
CPPEditorWidget *editorWidget,
int resultIndex = 0);
private:
QList<QuickFixTestDocument::Ptr> m_testFiles;
CppTools::CppCodeStylePreferences *m_cppCodeStylePreferences;
QByteArray m_cppCodeStylePreferencesOriginalDelegateId;
QStringList m_includePathsToRestore;
bool m_restoreIncludePaths;
};
QList<QuickFixTestDocument::Ptr> singleDocument(const QByteArray &original,
const QByteArray &expected);
} // namespace Tests
} // namespace Internal
} // namespace CppEditor
This diff is collapsed.
......@@ -40,14 +40,6 @@
QT_BEGIN_NAMESPACE
class QByteArray;
class QCheckBox;
class QComboBox;
class QDialogButtonBox;
class QStandardItem;
class QSortFilterProxyModel;
class QStandardItemModel;
class QString;
class QTreeView;
template <class> class QList;
QT_END_NAMESPACE
......@@ -522,81 +514,6 @@ public:
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result);
};
/*!
Insert (pure) virtual functions of a base class.
Exposed for tests.
*/
class InsertVirtualMethodsDialog : public QDialog
{
Q_OBJECT
public:
enum CustomItemRoles {
ClassOrFunction = Qt::UserRole + 1,
Reimplemented = Qt::UserRole + 2,
PureVirtual = Qt::UserRole + 3,
AccessSpec = Qt::UserRole + 4
};
enum ImplementationMode {
ModeOnlyDeclarations = 0x00000001,
ModeInsideClass = 0x00000002,
ModeOutsideClass = 0x00000004,
ModeImplementationFile = 0x00000008
};
InsertVirtualMethodsDialog(QWidget *parent = 0);
void initGui();
void initData();
virtual ImplementationMode implementationMode() const;
void setImplementationsMode(ImplementationMode mode);
virtual bool insertKeywordVirtual() const;
void setInsertKeywordVirtual(bool insert);
void setHasImplementationFile(bool file);
void setHasReimplementedFunctions(bool functions);
bool hideReimplementedFunctions() const;
virtual bool gather();
public slots:
void updateCheckBoxes(QStandardItem *item);
private slots:
void setHideReimplementedFunctions(bool hide);
private:
QTreeView *m_view;
QCheckBox *m_hideReimplementedFunctions;
QComboBox *m_insertMode;
QCheckBox *m_virtualKeyword;
QDialogButtonBox *m_buttons;
QList<bool> m_expansionStateNormal;
QList<bool> m_expansionStateReimp;
bool m_hasImplementationFile;
bool m_hasReimplementedFunctions;
void saveExpansionState();
void restoreExpansionState();
protected:
ImplementationMode m_implementationMode;
bool m_insertKeywordVirtual;
public:
QStandardItemModel *classFunctionModel;
QSortFilterProxyModel *classFunctionFilterModel;
};
class InsertVirtualMethods: public CppQuickFixFactory
{
Q_OBJECT
public:
InsertVirtualMethods(InsertVirtualMethodsDialog *dialog = new InsertVirtualMethodsDialog);
~InsertVirtualMethods();
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result);
private:
InsertVirtualMethodsDialog *m_dialog;
};
/*!
Optimizes a for loop to avoid permanent condition check and forces to use preincrement
or predecrement operators in the expression of the for loop.
......
......@@ -31,9 +31,9 @@
#include "cppeditorplugin.h"
#include "cppeditortestcase.h"
#include "cppquickfix.h"
#include "cppquickfix_test_utils.h"
#include "cppquickfixassistant.h"
#include "cppquickfixes.h"
#include "cppinsertvirtualmethods.h"
#include <coreplugin/editormanager/editormanager.h>
#include <cpptools/cppmodelmanagerinterface.h>
......@@ -474,10 +474,7 @@ void RunAllQuickFixesTokenAction::run(CPPEditorWidget *editorWidget)
// Where possible, use a guiless version of the factory.
if (qobject_cast<InsertVirtualMethods *>(quickFixFactory)) {
QScopedPointer<CppQuickFixFactory> factoryProducingGuiLessOperations;
factoryProducingGuiLessOperations.reset(
new InsertVirtualMethods(
new InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeOutsideClass, true)));
factoryProducingGuiLessOperations.reset(InsertVirtualMethods::createTestFactory());
factoryProducingGuiLessOperations->match(qfi, operations);
} else {
quickFixFactory->match(qfi, operations);
......
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