Commit abcb9358 authored by Abhishek Patil's avatar Abhishek Patil Committed by con

Qt Creator Plugin HOWTO documentation first and second cut

Signed-off-by: default avatarAbhishek Patil <abhishek.patil@vcreatelogic.com>

Merge-request: 145
Reviewed-by: default avatarcon <qtc-committer@nokia.com>
parent cdbe9328
<plugin name="DirModelPlugin" version="0.0.1">
<vendor>FooCompany</vendor>
<copyright>(C) 2009-2010 FooCompanyInc Pvt. Ltd.</copyright>
<license>GPL</license>
<description>Dir Model</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>
#include "dirmodelpluginplugin.h"
#include <QtPlugin>
#include <QStringList>
#include "DirNavigationFactory.h"
DirModelPluginPlugin::DirModelPluginPlugin()
{
// Do nothing
}
DirModelPluginPlugin::~DirModelPluginPlugin()
{
// Do notning
}
void DirModelPluginPlugin::extensionsInitialized()
{
// Do nothing
}
bool DirModelPluginPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject(new DirNavigationFactory);
return true;
}
void DirModelPluginPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(DirModelPluginPlugin)
#ifndef DIRMODELPLUGIN_PLUGIN_H
#define DIRMODELPLUGIN_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DirModelPluginPlugin : public ExtensionSystem::IPlugin
{
public:
DirModelPluginPlugin();
~DirModelPluginPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // DIRMODELPLUGIN_PLUGIN_H
# Uncomment the lines below and set the path
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DirModelPlugin
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = dirmodelpluginplugin.h \
dirnavigationfactory.h \
filesystemmodel.h
SOURCES = dirmodelpluginplugin.cpp \
dirnavigationfactory.cpp \
filesystemmodel.cpp
OTHER_FILES = DirModelPlugin.pluginspec
#include "dirnavigationfactory.h"
#include "filesystemmodel.h"
#include <QTreeView>
#include <QDir>
#include <coreplugin/navigationwidget.h>
/**
\todo
*/
Core::NavigationView DirNavigationFactory::createWidget()
{
Core::NavigationView view;
// Create FileSystemModel and set the defauls path as home path
FileSystemModel* model = new FileSystemModel;
model->setRootPath(QDir::homePath());
// Create TreeView and set model
QTreeView* tree = new QTreeView;
tree->setModel(model);
view.widget = tree;
return view;
}
/**
\todo
*/
QString DirNavigationFactory::displayName()
{
return "Dir View";
}
#ifndef DIRNAVIGATIONFACTORY_H
#define DIRNAVIGATIONFACTORY_H
#include <coreplugin/inavigationwidgetfactory.h>
class DirNavigationFactory : public Core::INavigationWidgetFactory
{
public:
DirNavigationFactory(){ }
~DirNavigationFactory() { }
Core::NavigationView createWidget();
QString displayName();
};
#endif // DIRNAVIGATIONFACTORY_H
#include "filesystemmodel.h"
FileSystemModel::FileSystemModel(QObject* parent)
:QFileSystemModel(parent)
{
}
FileSystemModel::~FileSystemModel()
{
}
int FileSystemModel::columnCount(const QModelIndex &parent ) const
{
Q_UNUSED(parent)
return 1;
}
#ifndef FILESYSTEMMODEL_H
#define FILESYSTEMMODEL_H
#include <QFileSystemModel>
/**
This FileSystemModel is subcalss of QFileSystemModel which just returns only 1 column.
*/
class FileSystemModel : public QFileSystemModel
{
public:
FileSystemModel(QObject* parent=0);
~FileSystemModel();
int columnCount(const QModelIndex &parent = QModelIndex()) const;
};
#endif // FILESYSTEMMODEL_H
<plugin name="DoNothing" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright>FooCompanyInc</copyright>
<license></license>
<description>DO NOTHING</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>
#include "donothingplugin.h"
#include <QtPlugin>
#include <QStringList>
DoNothingPlugin::DoNothingPlugin()
{
// Do nothing
}
DoNothingPlugin::~DoNothingPlugin()
{
// Do notning
}
void DoNothingPlugin::extensionsInitialized()
{
// Do nothing
}
bool DoNothingPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
return true;
}
void DoNothingPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(DoNothingPlugin)
#ifndef DONOTHING_PLUGIN_H
#define DONOTHING_PLUGIN_H
#include <extensionsystem/iplugin.h>
class DoNothingPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
DoNothingPlugin();
~DoNothingPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // DONOTHING_PLUGIN_H
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
TEMPLATE = lib
TARGET = DoNothing
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = donothingplugin.h
SOURCES = donothingplugin.cpp
OTHER_FILES = DoNothing.pluginspec
<plugin name="HeaderFilter" version="0.0.1">
<vendor>FooCompanyInc</vendor>
<copyright></copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.foocompany.com</url>
<dependencyList>
<dependency name="Core"/>
<dependency name="Find"/>
</dependencyList>
</plugin>
#include "headerfilter.h"
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/iprojectmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/session.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/filesearch.h>
#include<QFutureWatcher>
#include<QLabel>
#include <find/searchresultwindow.h>
#include <texteditor/basetexteditor.h>
using namespace Core;
using namespace Utils;
struct HeaderFilterData
{
HeaderFilterData() : m_projectPlugin(0), m_searchResultWindow(0){}
QFutureWatcher<FileSearchResult> watcher;
ProjectExplorer::ProjectExplorerPlugin* projectExplorer()
{
if(m_projectPlugin)
return m_projectPlugin;
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
m_projectPlugin = pm->getObject<ProjectExplorer::ProjectExplorerPlugin>();
return m_projectPlugin;
}
// Method to search and return the search window
Find::SearchResultWindow* searchResultWindow()
{
if(m_searchResultWindow)
return m_searchResultWindow;
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
m_searchResultWindow = pm->getObject<Find::SearchResultWindow>();
return m_searchResultWindow;
}
private:
ProjectExplorer::ProjectExplorerPlugin* m_projectPlugin;
Find::SearchResultWindow *m_searchResultWindow;
};
HeaderFilter::HeaderFilter()
{
d = new HeaderFilterData;
d->watcher.setPendingResultsLimit(1);
// displayResult(int) is called when every a new
// search result is generated
connect(&d->watcher, SIGNAL(resultReadyAt(int)),this, SLOT(displayResult(int)));
}
HeaderFilter::~HeaderFilter()
{
delete d;
}
QString HeaderFilter::id() const
{
return "HeaderFilter";
}
QString HeaderFilter::name() const
{
return tr("Header Filter");
}
bool HeaderFilter::isEnabled() const
{
QList<ProjectExplorer::Project*> projects = d->projectExplorer()->session()->projects();
if(projects.count())
return true;
return false;
}
QKeySequence HeaderFilter::defaultShortcut() const
{
return QKeySequence();
}
QWidget *HeaderFilter::createConfigWidget()
{
return (new QLabel("This is a header filter"));
}
void HeaderFilter::findAll(const QString &text,QTextDocument::FindFlags findFlags)
{
// Fetch a list of all open projects
QList<ProjectExplorer::Project*> projects = d->projectExplorer()->session()->projects();
// Make a list of files in each project
QStringList files;
Q_FOREACH(ProjectExplorer::Project* project, projects)
files += project->files(ProjectExplorer::Project::AllFiles);
// Remove duplicates
files.removeDuplicates();
//------------------------------------------------------------
// Begin searching
QString includeline = "#include <" + text + ">";
Find::SearchResult *result = d->searchResultWindow()->startNewSearch();
d->watcher.setFuture(QFuture<FileSearchResult>());
//When result gets activated it invokes the openEditor function
connect(result, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
d->searchResultWindow()->popup(true);
// Let the watcher monitor the search results
d->watcher.setFuture(Utils::findInFiles(includeline, files, findFlags));
}
void HeaderFilter::displayResult(int index)
{
FileSearchResult result = d->watcher.future().resultAt(index);
d->searchResultWindow()->addResult(result.fileName,
result.lineNumber,
result.matchingLine,
result.matchStart,
result.matchLength);
}
void HeaderFilter::openEditor(const Find::SearchResultItem &item)
{
TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.index);
}
#ifndef HEADERFILTER_H
#define HEADERFILTER_H
#include <find/ifindfilter.h>
#include <utils/filesearch.h>
namespace Find {
class SearchResultWindow;
struct SearchResultItem;
}
class QKeySequence;
class QWidget;
struct HeaderFilterData;
class HeaderFilter : public Find::IFindFilter
{
Q_OBJECT
public:
HeaderFilter();
~HeaderFilter();
QString id() const;
QString name() const;
bool isEnabled() const;
QKeySequence defaultShortcut() const;
void findAll(const QString &txt,QTextDocument::FindFlags findFlags);
QWidget *createConfigWidget();
protected slots:
void displayResult(int index);
void openEditor(const Find::SearchResultItem &item);
private:
HeaderFilterData *d;
};
#endif // HEADERFILTER_H
#include "headerfilterplugin.h"
#include "headerfilter.h"
#include <QtPlugin>
#include <QStringList>
HeaderFilterPlugin::HeaderFilterPlugin()
{
// Do nothing
}
HeaderFilterPlugin::~HeaderFilterPlugin()
{
// Do notning
}
void HeaderFilterPlugin::extensionsInitialized()
{
// Do nothing
}
bool HeaderFilterPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
addAutoReleasedObject( new HeaderFilter);
return true;
}
void HeaderFilterPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(HeaderFilterPlugin)
#ifndef HEADERFILTER_PLUGIN_H
#define HEADERFILTER_PLUGIN_H
#include <extensionsystem/iplugin.h>
class HeaderFilterPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
HeaderFilterPlugin();
~HeaderFilterPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
};
#endif // HEADERFILTER_PLUGIN_H
QTC_SOURCE = C:/Work/QtCreator
QTC_BUILD = C:/Work/QtCreator/build
DEFINES += FIND_LIBRARY
TEMPLATE = lib
TARGET = HeaderFilter
IDE_SOURCE_TREE = $$QTC_SOURCE
IDE_BUILD_TREE = $$QTC_BUILD
PROVIDER = FooCompanyInc
include($$QTC_SOURCE/src/libs/extensionsystem/extensionsystem.pri)
include($$QTC_SOURCE/src/qtcreatorplugin.pri)
include($$QTC_SOURCE/src/plugins/coreplugin/coreplugin.pri)
include($$QTC_SOURCE/src/libs/utils/utils.pri)
include($$QTC_SOURCE/src/plugins/projectexplorer/projectexplorer.pri)
include($$QTC_SOURCE/src/plugins/find/find.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
HEADERS = headerfilterplugin.h \
headerfilter.h
SOURCES = headerfilterplugin.cpp \
headerfilter.cpp
OTHER_FILES = HeaderFilter.pluginspec
<plugin name="HTMLEditor" version="0.0.1">
<vendor>FooCompanyInc Pvt. Ltd</vendor>
<copyright>(C) 2009-2010 FooCompanyInc Pvt. Ltd.</copyright>
<license></license>
<description>{{PLUGIN_DESCRIPTION}}</description>
<url>http://www.FooCompanyInc.com</url>
<dependencyList>
<dependency name="Core"/>
</dependencyList>
</plugin>