Commit 223b43e9 authored by Christian Stenger's avatar Christian Stenger
Browse files

Enable and disable parser on demand



The new approach enables the parser as soon the Tests navigation
widget or the Tests results pane is visible.
If none is displayed parsing will be disabled.

This additionally fixes an issue of not parsing a project
when having a project opened already before triggering the
first Tests navigation widget to become visible.

Change-Id: I7163268d405e07e85814097d65ff34790a98a3d1
Reviewed-by: default avatarAndre Poenitz <andre.poenitz@theqtcompany.com>
parent 213a687f
......@@ -69,6 +69,15 @@ TestCodeParser::~TestCodeParser()
clearMaps();
}
void TestCodeParser::setState(State state)
{
m_parserState = state;
if (m_parserState == Disabled) {
m_pendingUpdate = m_fullUpdatePostPoned = m_partialUpdatePostPoned = false;
m_postPonedFiles.clear();
}
}
void TestCodeParser::emitUpdateTestTree()
{
QTimer::singleShot(1000, this, SLOT(updateTestTree()));
......@@ -527,6 +536,9 @@ bool TestCodeParser::postponed(const QStringList &fileList)
m_partialUpdatePostPoned = true;
}
return true;
case Disabled:
qWarning("Checking for postponing but being disabled...");
return false;
}
QTC_ASSERT(false, return false); // should not happen at all
}
......@@ -565,7 +577,8 @@ void TestCodeParser::scanForTests(const QStringList &fileList)
m_parserState = Idle;
emit parsingFinished();
break;
case Idle:
default:
qWarning("I should not be here...");
break;
}
}
......
......@@ -46,11 +46,13 @@ public:
enum State {
Idle,
PartialParse,
FullParse
FullParse,
Disabled
};
explicit TestCodeParser(TestTreeModel *parent = 0);
virtual ~TestCodeParser();
void setState(State state);
#ifdef WITH_TESTS
int autoTestsCount() const;
......
......@@ -26,12 +26,8 @@
#include "testtreeitem.h"
#include <coreplugin/find/itemviewfind.h>
#include <projectexplorer/session.h>
#include <cpptools/cppmodelmanager.h>
#include <qmljstools/qmljsmodelmanager.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <projectexplorer/project.h>
#include <texteditor/texteditor.h>
#include <QToolButton>
......@@ -58,26 +54,14 @@ TestNavigationWidget::TestNavigationWidget(QWidget *parent) :
layout->addWidget(Core::ItemViewFind::createSearchableWrapper(m_view));
setLayout(layout);
TestCodeParser *parser = m_model->parser();
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
parser, &TestCodeParser::emitUpdateTestTree);
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
connect(cppMM, &CppTools::CppModelManager::documentUpdated,
parser, &TestCodeParser::onCppDocumentUpdated, Qt::QueuedConnection);
connect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles,
parser, &TestCodeParser::removeFiles, Qt::QueuedConnection);
QmlJS::ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance();
connect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated,
parser, &TestCodeParser::onQmlDocumentUpdated, Qt::QueuedConnection);
connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
parser, &TestCodeParser::removeFiles, Qt::QueuedConnection);
connect(m_view, &TestTreeView::activated, this, &TestNavigationWidget::onItemActivated);
}
TestNavigationWidget::~TestNavigationWidget()
{
m_model->disableParsing();
}
void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
{
const bool enabled = !TestRunner::instance()->isTestRunning();
......@@ -223,6 +207,7 @@ Core::NavigationView TestNavigationWidgetFactory::createWidget()
Core::NavigationView view;
view.widget = treeViewWidget;
view.dockToolBarWidgets = treeViewWidget->createToolButtons();
TestTreeModel::instance()->enableParsing();
return view;
}
......
......@@ -46,6 +46,7 @@ class TestNavigationWidget : public QWidget
public:
explicit TestNavigationWidget(QWidget *parent = 0);
~TestNavigationWidget();
void contextMenuEvent(QContextMenuEvent *event);
QList<QToolButton *> createToolButtons();
......
......@@ -42,7 +42,8 @@ namespace Internal {
TestResultsPane::TestResultsPane(QObject *parent) :
Core::IOutputPane(parent),
m_context(new Core::IContext(this))
m_context(new Core::IContext(this)),
m_wasVisibleBefore(false)
{
m_outputWidget = new QWidget;
QVBoxLayout *outputLayout = new QVBoxLayout;
......@@ -87,8 +88,6 @@ TestResultsPane::TestResultsPane(QObject *parent) :
this, &TestResultsPane::onTestRunStarted);
connect(TestRunner::instance(), &TestRunner::testRunFinished,
this, &TestResultsPane::onTestRunFinished);
connect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged,
this, &TestResultsPane::onTestTreeModelChanged);
}
void TestResultsPane::createToolButtons()
......@@ -178,8 +177,23 @@ void TestResultsPane::clearContents()
m_summaryWidget->setVisible(false);
}
void TestResultsPane::visibilityChanged(bool)
void TestResultsPane::visibilityChanged(bool visible)
{
if (visible) {
if (m_wasVisibleBefore)
return;
connect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged,
this, &TestResultsPane::onTestTreeModelChanged);
m_wasVisibleBefore = true;
TestTreeModel::instance()->enableParsing();
} else {
if (!m_wasVisibleBefore)
return;
disconnect(TestTreeModel::instance(), &TestTreeModel::testTreeModelChanged,
this, &TestResultsPane::onTestTreeModelChanged);
m_wasVisibleBefore = false;
TestTreeModel::instance()->disableParsing();
}
}
void TestResultsPane::setFocus()
......
......@@ -58,7 +58,7 @@ public:
QString displayName() const;
int priorityInStatusBar() const;
void clearContents();
void visibilityChanged(bool);
void visibilityChanged(bool visible);
void setFocus();
bool hasFocus() const;
bool canFocus() const;
......@@ -102,6 +102,7 @@ private:
QToolButton *m_stopTestRun;
QToolButton *m_filterButton;
QMenu *m_filterMenu;
bool m_wasVisibleBefore;
};
} // namespace Internal
......
......@@ -31,6 +31,8 @@
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <texteditor/texteditor.h>
#include <utils/fileutils.h>
......@@ -46,7 +48,9 @@ TestTreeModel::TestTreeModel(QObject *parent) :
m_rootItem(new TestTreeItem(QString(), QString(), TestTreeItem::ROOT)),
m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::ROOT, m_rootItem)),
m_quickTestRootItem(new TestTreeItem(tr("Qt Quick Tests"), QString(), TestTreeItem::ROOT, m_rootItem)),
m_parser(new TestCodeParser(this))
m_parser(new TestCodeParser(this)),
m_connectionsInitialized(false),
m_initializationCounter(0)
{
m_rootItem->appendChild(m_autoTestRootItem);
m_rootItem->appendChild(m_quickTestRootItem);
......@@ -90,6 +94,62 @@ TestTreeModel::~TestTreeModel()
m_instance = 0;
}
void TestTreeModel::enableParsing()
{
++m_initializationCounter;
if (m_connectionsInitialized)
return;
m_parser->setState(TestCodeParser::Idle);
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
m_parser, &TestCodeParser::emitUpdateTestTree);
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
connect(cppMM, &CppTools::CppModelManager::documentUpdated,
m_parser, &TestCodeParser::onCppDocumentUpdated, Qt::QueuedConnection);
connect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles, Qt::QueuedConnection);
QmlJS::ModelManagerInterface *qmlJsMM = QmlJS::ModelManagerInterface::instance();
connect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated,
m_parser, &TestCodeParser::onQmlDocumentUpdated, Qt::QueuedConnection);
connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles, Qt::QueuedConnection);
m_connectionsInitialized = true;
m_parser->updateTestTree();
}
void TestTreeModel::disableParsing()
{
if (!m_connectionsInitialized)
return;
if (--m_initializationCounter != 0)
return;
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
disconnect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
m_parser, &TestCodeParser::emitUpdateTestTree);
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
disconnect(cppMM, &CppTools::CppModelManager::documentUpdated,
m_parser, &TestCodeParser::onCppDocumentUpdated);
disconnect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles);
QmlJS::ModelManagerInterface *qmlJsMM = QmlJS::ModelManagerInterface::instance();
disconnect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated,
m_parser, &TestCodeParser::onQmlDocumentUpdated);
disconnect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
m_parser, &TestCodeParser::removeFiles);
m_parser->setState(TestCodeParser::Disabled);
m_connectionsInitialized = false;
}
QModelIndex TestTreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
......
......@@ -53,6 +53,8 @@ public:
static TestTreeModel* instance();
~TestTreeModel();
void enableParsing();
void disableParsing();
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
......@@ -109,6 +111,8 @@ private:
TestTreeItem *m_autoTestRootItem;
TestTreeItem *m_quickTestRootItem;
TestCodeParser *m_parser;
bool m_connectionsInitialized;
int m_initializationCounter;
};
......
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