graphwidget.cpp
来自「linux下的sourceinsight」· C++ 代码 · 共 1,163 行 · 第 1/3 页
CPP
1,163 行
* This menu is shown after an edge has been right-clicked. * @param pEdge The edge for which to show the menu * @param ptPos The position of the menu */void GraphWidget::showEdgeMenu(GraphEdge* pEdge, const QPoint& ptPos){ // Remember the edge m_pMenuItem = pEdge; // Show the popup menu. m_pEdgePopup->popup(ptPos);}/** * Redraws the widget when new instructions are available. * This slot is connected to the finished() signal emitted by the dot front- * end. */void GraphWidget::slotDotFinished(){ // Delete the temporary file if (m_sDrawFilePath != "") { QFile::remove(m_sDrawFilePath); m_sDrawFilePath = ""; } // Delete the progress dialogue if (m_pProgressDlg) { delete m_pProgressDlg; m_pProgressDlg = NULL; } setUpdatesEnabled(true); canvas()->update();}/** * Adds an entry to the tree, as the child of the active item. * Called by a CscopeFrontend object, when a new entry was received in its * whole from the Cscope back-end process. The entry contains the data of a * function calling the function described by the active item. * @param pToken The first token in the entry */void GraphWidget::slotDataReady(FrontendToken* pToken){ CallData data; QString sFunc; // Get the file name data.m_sFile = pToken->getData(); pToken = pToken->getNext(); // Get the function name sFunc = pToken->getData(); pToken = pToken->getNext(); // Get the line number (do not accept global information on a call tree) data.m_sLine = pToken->getData(); if (data.m_sLine.toUInt() == 0) return; pToken = pToken->getNext(); // Get the line's text data.m_sText = pToken->getData(); // Determine the caller and the callee if (m_bCalled) { data.m_sCaller = m_sQueriedFunc; data.m_sCallee = sFunc; } else { data.m_sCaller = sFunc; data.m_sCallee = m_sQueriedFunc; } // Add the call to the graph addCall(data);}/** * Displays search progress information. * This slot is connected to the progress() signal emitted by a * CscopeFrontend object. * @param nProgress The current progress value * @param nTotal The expected final value */void GraphWidget::slotProgress(int nProgress, int nTotal){ m_progress.setProgress(nProgress, nTotal);}/** * Disables the expandability feature of an item, if no functions calling it * were found. * @param nRecords Number of records reported by the query */void GraphWidget::slotFinished(uint /*nRecords*/){ // Destroy the progress bar m_progress.finished(); // Redraw the graph draw();}/** * Adds a multiple call node when a query results in too many entries. * This slot is attached to the aborted() signal of the Cscope process. */void GraphWidget::slotAborted(){ KMessageBox::information(this, i18n("The query produced too many results.\n" "A multiple-call node will appear in the graph instead.\n" "Hint: The maximum number of in/out edges\n" "can be adjusted by clicking the dialogue's \"Preferences\" button")); addMultiCall(m_sQueriedFunc, m_bCalled); draw();}/** * Shows functions called from the current function node. * This slot is connected to the "Show Called Functions" popup menu * action. */void GraphWidget::slotShowCalled(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; // Run a query for called functions m_sQueriedFunc = pNode->getFunc(); m_bCalled = true; m_pCscope->query(CscopeFrontend::Called, m_sQueriedFunc, true, Config().getGraphMaxNodeDegree());}/** * Shows a list of function calls from the current node. * The list is displayed in a query dialogue. The user can the select which * calls should be displayed in the graph. * This slot is connected to the "List Called Functions" popup menu * action. */void GraphWidget::slotListCalled(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; QueryViewDlg dlg(0, (QWidget*)parent()); // Show the query view dialogue dlg.query(CscopeFrontend::Called, pNode->getFunc()); if (dlg.exec() != QDialog::Accepted) return; // The OK button was clicked, replace current calls with the listed ones pNode->removeOutEdges(); QueryView::Iterator itr; CallData data; data.m_sCaller = pNode->getFunc(); // Add all listed calls for (itr = dlg.getIterator(); !itr.isEOF(); itr.next()) { data.m_sCallee = itr.getFunc(); data.m_sFile = itr.getFile(); data.m_sLine = itr.getLine(); data.m_sText = itr.getText(); addCall(data); } // Clean-up and redraw the graph removeDisconnected(pNode); draw();}/** * Hides functions called from the current function node. * This slot is connected to the "Hide Called Functions" popup menu * action. */void GraphWidget::slotHideCalled(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; // Remove edges and redraw the graph removeEdges(pNode, true); draw();}/** * Shows functions calling tothe current function node. * This slot is connected to the "Show Calling Functions" popup menu * action. */void GraphWidget::slotShowCalling(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; // Run a query for called functions m_sQueriedFunc = pNode->getFunc(); m_bCalled = false; m_pCscope->query(CscopeFrontend::Calling, m_sQueriedFunc, true, Config().getGraphMaxNodeDegree());}/** * Shows a list of function calls to the current node. * The list is displayed in a query dialogue. The user can the select which * calls should be displayed in the graph. * This slot is connected to the "List Calling Functions" popup menu * action. */void GraphWidget::slotListCalling(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; QueryViewDlg dlg(0, (QWidget*)parent()); // Show the query view dialogue dlg.query(CscopeFrontend::Calling, pNode->getFunc()); if (dlg.exec() != QDialog::Accepted) return; // The OK button was clicked, replace current calls with the listed ones pNode->removeInEdges(); QueryView::Iterator itr; CallData data; data.m_sCallee = pNode->getFunc(); // Add all listed calls for (itr = dlg.getIterator(); !itr.isEOF(); itr.next()) { data.m_sCaller = itr.getFunc(); data.m_sFile = itr.getFile(); data.m_sLine = itr.getLine(); data.m_sText = itr.getText(); addCall(data); } // Clean-up and redraw the graph removeDisconnected(pNode); draw();}/** * Hides functions calling to the current function node. * This slot is connected to the "Hide CallingFunctions" popup menu * action. */void GraphWidget::slotHideCalling(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; // Remove edges and redraw the graph removeEdges(pNode, false); draw();}/** * Looks up the definition of the current function node. * This slot is connected to the "Find Definition" popup menu action. */void GraphWidget::slotFindDef(){ GraphNode* pNode; QueryViewDlg* pDlg; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; // Create a query view dialogue pDlg = new QueryViewDlg(QueryViewDlg::DestroyOnSelect, this); // Display a line when it is selected in the dialogue connect(pDlg, SIGNAL(lineRequested(const QString&, uint)), this, SIGNAL(lineRequested(const QString&, uint))); // Start the query pDlg->query(CscopeFrontend::Definition, pNode->getFunc());}/** * Deletes a node from the graph (alogn with all edges connected to this * node). * The node removed is the one over which the context menu was invoked. * This slot is connected to the "Remove" popup menu action. */void GraphWidget::slotRemoveNode(){ GraphNode* pNode; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL) return; // Remove all incoming edges pNode->removeInEdges(); // Remove the node (also deletes the object and its outgoing edges) m_dictNodes.remove(pNode->getFunc()); // Redraw the graph draw();}/** * Shows the list of calls that is represented by a single multi-call node. * This slot handles the "Details..." command of the multi-call node menu. */void GraphWidget::slotMultiCallDetails(){ GraphNode* pNode, * pParent; bool bCalled; // Make sure the menu item is a node pNode = dynamic_cast<GraphNode*>(m_pMenuItem); if (pNode == NULL || !pNode->isMultiCall()) return; // Get the required information from the node pNode->getFirstNeighbour(pParent, bCalled); if (!pParent) return; QueryViewDlg dlg(0, (QWidget*)parent()); dlg.query(bCalled ? CscopeFrontend::Calling : CscopeFrontend::Called, pParent->getFunc()); dlg.exec();}/** * Emits a signal to open an editor at the file and line matching the call * information of the current edge. * This slot is connected to the "Open Call" popup menu action (for edges). */void GraphWidget::slotOpenCall(){ GraphEdge* pEdge; QString sFile, sLine; // Make sure the menu item is an edge pEdge = dynamic_cast<GraphEdge*>(m_pMenuItem); if (pEdge != NULL && pEdge->getFile() != "") emit lineRequested(pEdge->getFile(), pEdge->getLine());}#include "graphwidget.moc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?