天天看點

Qt Creator plugin動手實踐(1)學習基本構成

Qt Creator plugin

如果把D:\Qt\Qt5.9.8\Tools\QtCreator\lib\qtcreator\plugins\路徑下的檔案全部删除(隻保留Core4.dll檔案),然後再啟動,那麼Qt Creator就變成這樣了,簡直就是個空殼子:

Qt Creator plugin動手實踐(1)學習基本構成
Qt Creator plugin動手實踐(1)學習基本構成
Qt Creator plugin動手實踐(1)學習基本構成
Qt Creator plugin動手實踐(1)學習基本構成

可見Qt Creator這個龐然大物是由各類插件構成的!把插件拿掉,它就隻是一張皮了。

官網下載下傳:

http://download.qt.io/official_releases/qtcreator/ https://github.com/qt https://github.com/qt-creator/qt-creator https://github.com/qt-creator/qt-creator/tree/master/src/plugins/helloworld 官網文檔: https://doc.qt.io/qtcreator/index.html https://doc-snapshots.qt.io/qtcreator-extending/first-plugin.html 網絡教程: https://www.devbean.net/2012/03/qtcreator-plugin-develop-catalog/ Qt Creator 插件開發,翻譯自<Writing-Qt-Creator-Plugins.pdf> https://www.devbean.net/category/qt-creator-%E6%BA%90%E7%A0%81%E5%AD%A6%E4%B9%A0/

Qt Creator 源碼學習

開源項目參考:

https://github.com/lexxmark/QtCreator-JsExtensions-Plugin https://github.com/pasccom/QtcDevPlugin https://github.com/MichaelSp/QtCreator-Jenkins-Plugin https://github.com/Eaknyt/QtCreator-ColorPickerPlugin

Qt5:

qtdesigner的源碼在Qt Creator源碼裡面,以插件形式出現

https://github.com/qt-creator/qt-creator/tree/master/src/plugins/designer

Qt4:

Qt Creator源碼裡面是沒有設計器的實際的代碼的,它使用的是QtDesigner.dll。

qtdesigner的源碼在qtsdk中。

以qt4.8源碼為例:qtdesigner.dll的源碼路徑為\tools\designer\src

https://github.com/qt/qt/tree/4.8/tools/designer 個人筆記:2019/4/19,摘錄于Qt Creator源碼

projectexplorericons.cpp //ico檔案定義
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\projectexplorer\projectexplorer.cpp
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
 
// run icon
const QIcon runSideBarIcon = Utils::Icon::sideBarIcon(Icons::RUN, Icons::RUN_FLAT);
    const QIcon runIcon = Utils::Icon::combinedIcon({Utils::Icons::RUN_SMALL.icon(),
                                                     runSideBarIcon});
 
    runMenu->menu()->setIcon(runIcon);
    runMenu->menu()->setTitle(tr("Run"));
    msubProjectContextMenu->addMenu(runMenu, ProjectExplorer::Constants::G_PROJECT_RUN);
 
// run action
    dd->m_runAction = new QAction(runIcon, tr("Run"), this);
    cmd = ActionManager::registerAction(dd->m_runAction, Constants::RUN);
    cmd->setAttribute(Command::CA_UpdateText);
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R")));
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
    ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN);
 
// build session action
    const QIcon sideBarIcon = Utils::Icon::sideBarIcon(Icons::BUILD, Icons::BUILD_FLAT);
    const QIcon buildIcon = Utils::Icon::combinedIcon({Icons::BUILD_SMALL.icon(), sideBarIcon});
    dd->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
 
// build action
    dd->m_buildAction = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
                                                     Utils::ParameterAction::AlwaysEnabled, this);
    dd->m_buildAction->setIcon(buildIcon);
    cmd = ActionManager::registerAction(dd->m_buildAction, Constants::BUILD);
    cmd->setAttribute(Command::CA_UpdateText);
    cmd->setDescription(dd->m_buildAction->text());
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
    mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
 
// Run without deployment action
    dd->m_runWithoutDeployAction = new QAction(tr("Run Without Deployment"), this);
    cmd = ActionManager::registerAction(dd->m_runWithoutDeployAction, Constants::RUNWITHOUTDEPLOY);
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
 
 dd->m_runActionContextMenu = new QAction(runIcon, tr("Run"), this);
    cmd = ActionManager::registerAction(dd->m_runActionContextMenu, Constants::RUNCONTEXTMENU, projecTreeContext);
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_RUN);
    msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_RUN);
 
//左邊欄按鈕
ModeManager::addAction(dd->m_modeBarBuildAction, Constants::P_ACTION_BUILDPROJECT); //Build
ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN); //Run
ModeManager::addAction(&m_visibleStartAction, Constants::P_ACTION_DEBUG); //Debug
 
connect(dd->m_runAction, &QAction::triggered,
            dd, []() { m_instance->runStartupProject(Constants::NORMAL_RUN_MODE); });
connect(dd->m_runWithoutDeployAction, &QAction::triggered,
            dd, []() { m_instance->runStartupProject(Constants::NORMAL_RUN_MODE, true); });
 
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\debugger\debuggerplugin.cpp
connect(&m_debugWithoutDeployAction, &QAction::triggered, this, [] {
        ProjectExplorerPlugin::runStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, true);
    });
 
void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu()
{
    m_runWithoutDeployAction->setVisible(m_projectExplorerSettings.deployBeforeRun);
}
 
connect(this, &ProjectExplorerPlugin::updateRunActions,
            dd, &ProjectExplorerPluginPrivate::slotUpdateRunActions);
void ProjectExplorerPluginPrivate::slotUpdateRunActions()
{
    QString whyNot;
    const bool state = ProjectExplorerPlugin::canRunStartupProject(Constants::NORMAL_RUN_MODE, &whyNot);
    m_runAction->setEnabled(state);
    m_runAction->setToolTip(whyNot);
    m_runWithoutDeployAction->setEnabled(state);
}
 
void DebuggerPluginPrivate::updateDebugWithoutDeployMenu()
{
    const bool state = ProjectExplorerPlugin::projectExplorerSettings().deployBeforeRun;
    m_debugWithoutDeployAction.setVisible(state);
}
 
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
            this, &DebuggerPluginPrivate::updatePresetState);
void DebuggerPluginPrivate::updatePresetState()
{
    if (m_shuttingDown)
        return;
 
    Project *startupProject = SessionManager::startupProject();
    RunConfiguration *startupRunConfig = RunConfiguration::startupRunConfiguration();
    DebuggerEngine *currentEngine = EngineManager::currentEngine();
 
    QString whyNot;
    const bool canRun =
            ProjectExplorerPlugin::canRunStartupProject(ProjectExplorer::Constants::DEBUG_RUN_MODE, &whyNot);
 
    m_debugWithoutDeployAction.setEnabled(canRun);
}
 
 
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\debugger\images\[email protected]
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\debugger\images\[email protected]
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\welcome\images\[email protected]
 
 
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\projectexplorer\images\run.png
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\projectexplorer\images\desktopdevice.png
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\projectexplorer\images\BuildSettings.png
D:\temp\qt-creator-opensource-src-4.8.2\src\plugins\projectexplorer\images\[email protected]
 
 

      

繼續閱讀