qtcreator源文件提取函数和类

4 篇文章 0 订阅
2 篇文章 0 订阅

下载qtcreator的源代码编译cplusplus、utils、languageUtils这三个项目,使用cplusplus中的OverviewModel类和src\plugins\cppeditor下的OverviewTreeView类,使用这两类来组合显示出来c++头文件中所有的类和函数声明以及相关信息。我写的测试代码如下:

#include "OverviewView.h"
#include "cplusplus/OverviewModel.h"

#include <QTreeView>
#include <QComboBox>
#include <QMouseEvent>

class OverviewTreeView : public QTreeView
{
public:
    OverviewTreeView(QWidget *parent = 0)
        : QTreeView(parent)
    {
        // TODO: Disable the root for all items (with a custom delegate?)
        setRootIsDecorated(false);
    }

    void sync()
    {
        expandAll();
    }

    void adjustWidth()
    {
        //const int w = Core::ICore::mainWindow()->geometry().width();
        setMaximumWidth(1243);
        setMinimumWidth(qMin(qMax(sizeHintForColumn(0), minimumSizeHint().width()), 1000));
    }
};

class OverviewCombo : public QComboBox
{
public:
    OverviewCombo(QWidget *parent = 0) : QComboBox(parent), m_skipNextHide(false)
    {}

    bool eventFilter(QObject* object, QEvent* event)
    {
        if (event->type() == QEvent::MouseButtonPress && object == view()->viewport()) {
            QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
            QModelIndex index = view()->indexAt(mouseEvent->pos());
            if (!view()->visualRect(index).contains(mouseEvent->pos()))
                m_skipNextHide = true;
        }
        return false;
    }

    void showPopup()
    {
        static_cast<OverviewTreeView *>(view())->adjustWidth();
        QComboBox::showPopup();
    }

    virtual void hidePopup()
    {
        if (m_skipNextHide)
            m_skipNextHide = false;
        else
            QComboBox::hidePopup();
    }

private:
    bool m_skipNextHide;
};

OverviewView::OverviewView(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	//QTableView *tv = ui.tableView;
	OverviewTreeView *tv = new OverviewTreeView;
	CPlusPlus::OverviewModel *m_outlineModel = new CPlusPlus::OverviewModel;
	
	//qsettings1.h
	QString docFile = "G:\\map\\CocosMapEditor\\qsettings1.h";
	QFile file(docFile);
	file.open(QFile::ReadOnly);
	QByteArray ba = file.readAll();
	QString fileContent (ba);

	CPlusPlus::Document::Ptr cdPtr = CPlusPlus::Document::create("");
	cdPtr->setUtf8Source(ba);
	cdPtr->parse();
	cdPtr->check();
	//m_outlineModel->rebuild(cdPtr);
	//tv->setModel(m_outlineModel);

	//--------------------------------------------------
	//OverviewCombo *oc = new OverviewCombo(this);
	//oc->setView(tv);

	//tv->setModel(NULL);
	//m_outlineModel->rebuild(cdPtr);
	//tv->setModel(m_outlineModel);
	//tv->expandAll();
	//tv->show();

	OverviewCombo *oc = new OverviewCombo(this);
	oc->setView(tv);
	//oc->show();

	tv->setModel(NULL);
	m_outlineModel->rebuild(cdPtr);
	oc->setModel(m_outlineModel);

	tv->expandAll();

	oc->show();
}

OverviewView::~OverviewView()
{

}


核心代码如下:

	CPlusPlus::Document::Ptr cdPtr = CPlusPlus::Document::create("");
	cdPtr->setUtf8Source(ba);
	cdPtr->parse();
	cdPtr->check();



qtcreator下载地址:

http://sourceforge.jp/projects/sfnet_qtcreator.mirror/releases/



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值