querywidget.cpp
来自「This a source insight software in Linux.」· C++ 代码 · 共 620 行 · 第 1/2 页
CPP
620 行
}/** * Selects the next query result record in the current query page. */void QueryWidget::slotPrevResult(){ QueryPage* pPage; // Select the next record in the current page pPage = dynamic_cast<QueryPage*>(currentPage()); if (pPage != NULL) pPage->selectPrev();}/** * Closes the current query page. */void QueryWidget::slotCloseCurrent(){ QWidget* pPage; // Close the current page pPage = currentPage(); if (pPage != NULL) slotClosePage(pPage);}/** * Closes all query pages. */void QueryWidget::slotCloseAll(){ int nPageCount, i; QueryPage* pPage; // Close all pages nPageCount = m_pQueryTabs->count(); for (i = 0; i < nPageCount; i++) { pPage = (QueryPage*)m_pQueryTabs->page(0); m_pQueryTabs->removePage(pPage); delete pPage; } m_pHistPage = NULL;}/** * Creates a new history page. */void QueryWidget::slotAddHistoryPage(){ QString sTitle; // Create the page m_pHistPage = new HistoryPage(this); // Add the page, and set it as the current one m_pQueryTabs->insertTab(m_pHistPage, GET_PIXMAP(TabUnlocked), ""); setPageCaption(m_pHistPage); // Emit the lineRequested() signal when a query record is selected on // this page connect(m_pHistPage, SIGNAL(lineRequested(const QString&, uint)), this, SLOT(slotRequestLine(const QString&, uint)));}/** * Handles the "Go->Back" menu command. * Moves to the previous position in the position history. */void QueryWidget::slotHistoryPrev(){ if (m_pHistPage != NULL) { m_bHistEnabled = false; m_pHistPage->selectPrev(); m_bHistEnabled = true; }}/** * Handles the "Go->Forward" menu command. * Moves to the next position in the position history. */void QueryWidget::slotHistoryNext(){ if (m_pHistPage != NULL) { m_bHistEnabled = false; m_pHistPage->selectNext(); m_bHistEnabled = true; }}/** * Sets the active history page, if any, as the current page. */void QueryWidget::selectActiveHistory(){ if (m_pHistPage) setCurrentPage(m_pHistPage);}/** * Attaches the page operations menu to this widget. * The page menu is a popup menu that handles such operations as opening a * new page, closing a page, locking a page, etc. * @param pMenu Pointer to the popup menu * @param pAction Pointer to the "Lock/Unlock" toggle action */void QueryWidget::setPageMenu(QPopupMenu* pMenu, KToggleAction* pAction){ m_pPageMenu = pMenu; m_pLockAction = pAction;}/** * Emits a signal indicating a certain source file and line number are * requested. * This slot is connected to the recordSelected() signal emitted by any of * the query pages. The signal emitted by this slot is used to display an * editor page at the requested line. * @param pItem The list item selected by the user */void QueryWidget::slotRequestLine(const QString& sFileName, uint nLine){ // Disable history if the request came from the active history page if (currentPage() == m_pHistPage) m_bHistEnabled = false; // Emit the signal emit lineRequested(sFileName, nLine); // Re-enable history if (currentPage() == m_pHistPage) m_bHistEnabled = true;}/** * Update the lock button when the current query page changes. * @param pWidget The new current page */void QueryWidget::slotCurrentChanged(QWidget* pWidget){ QueryPage* pPage; pPage = (QueryPage*)pWidget; m_pLockAction->setChecked(pPage->isLocked());}/** * Removes the given page from the tab widget. * This slot is connected to the closeRequest() signal of the KTabBar object. * @param pPage The page to close */void QueryWidget::slotClosePage(QWidget* pPage){ // Prompt the user before closing a locked query if (((QueryPage*)pPage)->isLocked()) { if (KMessageBox::questionYesNo(NULL, i18n("You about about to close" " a locked page.\nAre you sure?")) == KMessageBox::No) { return; } } // Check if the closed page is the active history page if (pPage == m_pHistPage) m_pHistPage = NULL; // Update the number of open history pages else if (dynamic_cast<HistoryPage*>(pPage) == NULL) m_nQueryPages--; // Remove the page and delete the object m_pQueryTabs->removePage(pPage); delete pPage;}/** * Displays a context menu for page operations. * This slot is connected to the contextMenu() signal, emitted by * m_pQueryTabs. * NOTE: We assume that the first item in the menu is "New". * @param pt The point over which the mouse was clicked in request for the * context menu */void QueryWidget::slotContextMenu(const QPoint& pt){ uint i; // Disable everything but the "new" action (clicked outside any widget) for (i = 1; i < m_pPageMenu->count(); i++) m_pPageMenu->setItemEnabled(m_pPageMenu->idAt(i), false); // Show the menu m_pPageMenu->popup(pt);}/** * Displays a context menu for page operations. * This slot is connected to the contextMenu() signal, emitted by * m_pQueryTabs. * @param pWidget The page under the mouse * @param pt The point over which the mouse was clicked in request for * the context menu */void QueryWidget::slotContextMenu(QWidget* pWidget, const QPoint& pt){ uint i; // Operations are on the current page, so we must ensure the clicked // tab becomes the current one setCurrentPage(pWidget); // Enable all operations for (i = 1; i < m_pPageMenu->count(); i++) m_pPageMenu->setItemEnabled(m_pPageMenu->idAt(i), true); // Show the menu m_pPageMenu->popup(pt);}/** * Locks/unlocks the give page. * @param pPage The page to lock or unlock * @param bLock true to lock the page, false to unlock it */void QueryWidget::setPageLocked(QueryPageBase* pPage, bool bLock){ // Set the locking state of the current page pPage->setLocked(bLock); m_pQueryTabs->setTabIconSet(pPage, bLock ? GET_PIXMAP(TabLocked) : GET_PIXMAP(TabUnlocked)); // There can only be one unlocked history page. Check if a non-active // query page is being unlocked if (isHistoryPage(pPage) && (pPage != m_pHistPage) && !bLock) { // Lock the active history page (may be NULL) if (m_pHistPage != NULL) setPageLocked(m_pHistPage, true); // Set the unlock page as the new active history page m_pHistPage = (HistoryPage*)pPage; }}/** * Ensures the current page is a query page that is ready to accept new * queries. * The function first checks the current page. If it is an unlocked query * page, then nothing needs to be done. Otherwise, it checks for the first * unlocked query page by iterating over all pages in the tab widget. If this * fails as well, a new query page is created. */void QueryWidget::findQueryPage(){ QueryPage* pPage; int nPages, i; // First check if the current page is an unlocked query page pPage = dynamic_cast<QueryPage*>(currentPage()); if (pPage != NULL) { if (!pPage->isLocked() && !pPage->isRunning()) return; } // Look for the first unlocked query page nPages = m_pQueryTabs->count(); for (i = 0; i < nPages; i++) { pPage = dynamic_cast<QueryPage*>(m_pQueryTabs->page(i)); if (pPage != NULL) { if (!pPage->isLocked() && !pPage->isRunning()) { setCurrentPage(pPage); return; } } } // Couldn't find an unlocked query page, create a new one addQueryPage();}/** * Ensures an active history page exists. * The active history page is the only unlocked history page. If one does not * exist, it is created. */void QueryWidget::findHistoryPage(){ HistoryPage* pPage; int nPages, i; // First check if the active history page is unlocked if (m_pHistPage != NULL && !m_pHistPage->isLocked()) return; // Look for the first unlocked history page nPages = m_pQueryTabs->count(); for (i = 0; i < nPages; i++) { pPage = dynamic_cast<HistoryPage*>(m_pQueryTabs->page(i)); if (pPage != NULL && !pPage->isLocked()) { m_pHistPage = pPage; return; } } // Couldn't find an unlocked query page, create a new one slotAddHistoryPage();}#include "querywidget.moc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?