querywidget.cpp

来自「This a source insight software in Linux.」· C++ 代码 · 共 620 行 · 第 1/2 页

CPP
620
字号
/*************************************************************************** * * Copyright (C) 2005 Elad Lahav (elad_lahav@users.sourceforge.net) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. *  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ***************************************************************************/#include <qtoolbutton.h>#include <qtooltip.h>#include <klocale.h>#include <kmessagebox.h>#include "querywidget.h"#include "kscopepixmaps.h"#include "kscopeconfig.h"/** * Class constructor. * @param	pParent	The parent widget * @param	szName	The widget's name */QueryWidget::QueryWidget(QWidget* pParent, const char* szName) :	QueryWidgetLayout(pParent, szName),	m_pPageMenu(NULL),	m_pLockAction(NULL),	m_pHistPage(NULL),	m_bHistEnabled(true),	m_nQueryPages(0){	// Pages can be closed by clicking their tabs	m_pQueryTabs->setHoverCloseButton(true);		// Change the lock action state according to the current page	connect(m_pQueryTabs, SIGNAL(currentChanged(QWidget*)), this,		SLOT(slotCurrentChanged(QWidget*)));		// Close a query when its tab button is clicked	connect(m_pQueryTabs, SIGNAL(closeRequest(QWidget*)), this,		SLOT(slotClosePage(QWidget*)));	// Show the menu when requested	connect(m_pQueryTabs, SIGNAL(contextMenu(const QPoint&)), this,		SLOT(slotContextMenu(const QPoint&)));	connect(m_pQueryTabs, SIGNAL(contextMenu(QWidget*, const QPoint&)), this,		SLOT(slotContextMenu(QWidget*, const QPoint&)));}/** * Class destructor. */QueryWidget::~QueryWidget(){}/** * Runs a query in a query page. * A query page is first selected, with a new one created if required. The * method then creates a Cscope process and runs the query. * @param	nType	The query's numeric type code * @param	sText	The query's text, as entered by the user */void QueryWidget::initQuery(uint nType, const QString& sText){	QueryPage* pPage;		// Make sure we have a query page	findQueryPage();	pPage = (QueryPage*)currentPage();				// Use the current page, or a new page if the current one is locked	if (pPage->isLocked()) {		addQueryPage();		pPage = (QueryPage*)currentPage();	}	// Reset the page's results list	pPage->clear();	pPage->query(nType, sText);		// Set the page's tab text according to the new query	setPageCaption(pPage);}/** * Applies the user's colour and font preferences to all pages. */void QueryWidget::applyPrefs(){	QueryPage* pPage;	int nPages, i;	// Iterate query pages	nPages = m_pQueryTabs->count();	for (i = 0; i < nPages; i++) {		pPage = (QueryPage*)m_pQueryTabs->page(i);		pPage->applyPrefs();		setPageCaption(pPage);	}}/** * Loads all queries that were locked when the project was closed. * @param	sProjPath		The full path of the project directory * @param	slQueryFiles	The list of query file names to load */void QueryWidget::loadLockedQueries(const QString& sProjPath,	const QStringList& slQueryFiles){	QStringList::ConstIterator itr;	QueryPageBase* pPage;	QString sName;		// Iterate through query files	for (itr = slQueryFiles.begin(); itr != slQueryFiles.end(); ++itr) {		// Set the target page, based on the file type (query or history)		if ((*itr).startsWith("History")) {			findHistoryPage();			pPage = m_pHistPage;		}		else {			findQueryPage();			pPage = (QueryPage*)currentPage();		}		// Load a query file to this page, and lock the page		if (pPage->load(sProjPath, *itr)) {			setPageCaption(pPage);			setPageLocked(pPage, true);		}	}}/** * Saves all locked queries into files in the project directory. * @param	sProjPath		The full path of the project directory * @param	slQueryFiles	Holds a list of query file names, upon return */void QueryWidget::saveLockedQueries(const QString& sProjPath, 	QStringList& slQueryFiles){	int nPageCount, i;	QueryPage* pPage;	QString sFileName;		// Iterate pages	nPageCount = m_pQueryTabs->count();	for (i = 0; i < nPageCount; i++) {		pPage = (QueryPage*)m_pQueryTabs->page(i);		if (pPage->isLocked()) {			// Store this query page			sFileName = pPage->store(sProjPath);						// A successful store operation returns a non-empty file name			if (!sFileName.isEmpty())				slQueryFiles.append(sFileName);		}	}}/** * Adds a new position record to the active history page. * @param	sFile	The file path * @param	nLine	The line number * @param	sText	The contents of the line pointed to by the file path and * 					line number */void QueryWidget::addHistoryRecord(const QString& sFile, uint nLine, 	const QString& sText){	// Validate file name and line number	if (sFile.isEmpty() || nLine == 0)		return;		// Do nothing if history logging is disabled	if (!m_bHistEnabled)		return;	// Make sure there is an active history page		findHistoryPage();				// Add the position entry to the active page	m_pHistPage->addRecord(sFile, nLine, sText);}/** * Sets the tab caption and tool-tip for the given page. * @param	pPage	The page whose tab needs to be changed */void QueryWidget::setPageCaption(QueryPageBase* pPage){	m_pQueryTabs->changeTab(pPage, 		pPage->getCaption(Config().getUseBriefQueryCaptions()));	m_pQueryTabs->setTabToolTip(pPage, pPage->getCaption());}/** * Creates a new query page, and adds it to the tab widget. * The new page is set as the current one. */void QueryWidget::addQueryPage(){	QueryPage* pPage;	QString sTitle;	// Create the page	pPage = new QueryPage(this);	// Add the page, and set it as the current one	m_pQueryTabs->insertTab(pPage, GET_PIXMAP(TabUnlocked), "Query",		m_nQueryPages++);	setCurrentPage(pPage);		// Emit the lineRequested() signal when a query record is selected on 	// this page	connect(pPage, SIGNAL(lineRequested(const QString&, uint)), this, 		SLOT(slotRequestLine(const QString&, uint)));}/** * Creates a new query page, and emits signal about it. */void QueryWidget::slotNewQueryPage(){	addQueryPage();	emit newQuery();}/** * Locks or unlocks a query. * This slot is connected to the toggled() signal of the lock query button. * @param	bOn	true if the new state of the button is "on", false if it is *				"off" */void QueryWidget::slotLockCurrent(bool bOn){	QueryPageBase* pPage;		pPage = currentPage();		if (pPage != NULL)		setPageLocked(currentPage(), bOn);}/** * Locks or unlocks a query, by toggling the current state. */void QueryWidget::slotLockCurrent(){	QueryPageBase* pPage;		pPage = currentPage();	if (pPage != NULL)		setPageLocked(pPage, !pPage->isLocked());}/** * Reruns the query whose results are displayed in the current page. */void QueryWidget::slotRefreshCurrent(){	QueryPage* pPage;	uint nType;	QString sText;		// Make sure the current page is a valid, non-empty one	pPage = dynamic_cast<QueryPage*>(currentPage());	if ((pPage == NULL) ||		(pPage->getQueryType() == CscopeFrontend::None)) {		return;	}	// Get the current page parameters (before they are deleted by clear())	nType = pPage->getQueryType();	sText = pPage->getQueryText();		// Clear the current page contents	pPage->clear();	pPage->query(nType, sText);}/** * Selects the next query result record in the current query page. */void QueryWidget::slotNextResult(){	QueryPage* pPage;	// Select the next record in the current page	pPage = dynamic_cast<QueryPage*>(currentPage());	if (pPage != NULL)		pPage->selectNext();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?