From c51bd9e2b1d53c45b686c1e51c0b71e5b247934f Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Wed, 11 Apr 2007 00:59:01 +0000 Subject: [PATCH] dhb Removal of PageHash class as requested. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4534 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/bat.pro | 4 -- bacula/src/qt-console/mainwin.cpp | 61 ++++++++++++++------ bacula/src/qt-console/mainwin.h | 11 ++-- bacula/src/qt-console/medialist/medialist.ui | 2 +- bacula/src/qt-console/pagehash.cpp | 54 ----------------- bacula/src/qt-console/pagehash.h | 55 ------------------ 6 files changed, 52 insertions(+), 135 deletions(-) delete mode 100644 bacula/src/qt-console/pagehash.cpp delete mode 100644 bacula/src/qt-console/pagehash.h diff --git a/bacula/src/qt-console/bat.pro b/bacula/src/qt-console/bat.pro index 578da0d92c..df4c673183 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -52,10 +52,6 @@ SOURCES += select/select.cpp HEADERS += pages.h SOURCES += pages.cpp -## PageHash -HEADERS += pagehash.h -SOURCES += pagehash.cpp - ## MediaList HEADERS += medialist/medialist.h SOURCES += medialist/medialist.cpp diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index ac13a49b02..7f5260bad4 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -36,7 +36,6 @@ */ #include "bat.h" -#include "pagehash.h" MainWin::MainWin(QWidget *parent) : QMainWindow(parent) { @@ -85,7 +84,7 @@ void MainWin::createPages() m_console->setTreeItem(item); /* Append to pagelist */ - m_treeindex.insert(item, m_console); + hashInsert(item, m_console); /* Set Color of treeWidgetItem for the console * It will be set to gree in the console class if the connection is made. @@ -104,16 +103,16 @@ void MainWin::createPages() /* brestore */ item=createPage("brestore", topItem); bRestore* brestore=new bRestore(stackedWidget); - m_treeindex.insert(item, brestore); + hashInsert(item, brestore); /* lastly for now, the medialist */ item=createPage("Media", topItem ); MediaList* medialist=new MediaList(stackedWidget, m_console); - m_treeindex.insert(item, medialist); + hashInsert(item, medialist); /* Iterate through and add to the stack */ - foreach(Pages *page, m_treeindex.m_pagehash) + foreach(Pages *page, m_pagehash) page->dockPage(); treeWidget->expandItem(topItem); @@ -214,7 +213,7 @@ void MainWin::closeEvent(QCloseEvent *event) m_console->writeSettings(); m_console->terminate(); event->accept(); - foreach(Pages *page, m_treeindex.m_pagehash){ + foreach(Pages *page, m_pagehash){ if( !page->isDocked() ) page->close(); } @@ -247,8 +246,8 @@ void MainWin::readSettings() void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/) { /* Is this one of the first level pages */ - if( m_treeindex.value(item) ){ - Pages* page = m_treeindex.value(item); + if( getFromHash(item) ){ + Pages* page = getFromHash(item); int stackindex=stackedWidget->indexOf(page); if( stackindex >= 0 ){ @@ -277,8 +276,8 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre if ( previousitem ){ /* Is this one of the first level pages */ - if( m_treeindex.value(previousitem) ){ - Pages* page = m_treeindex.value(previousitem); + if( getFromHash(previousitem) ){ + Pages* page = getFromHash(previousitem); treeWidget->removeAction(actionToggleDock); foreach( QAction* pageaction, page->m_contextActions ){ treeWidget->removeAction(pageaction); @@ -287,8 +286,8 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre } /* Is this one of the first level pages */ - if( m_treeindex.value(currentitem) ){ - Pages* page = m_treeindex.value(currentitem); + if( getFromHash(currentitem) ){ + Pages* page = getFromHash(currentitem); int stackindex = stackedWidget->indexOf(page); /* Is this page currently on the stack */ @@ -392,8 +391,8 @@ void MainWin::toggleDockContextWindow() QTreeWidgetItem *currentitem = treeWidget->currentItem(); /* Is this one of the first level pages */ - if( m_treeindex.value(currentitem) ){ - Pages* page = m_treeindex.value(currentitem); + if( getFromHash(currentitem) ){ + Pages* page = getFromHash(currentitem); page->togglePageDocking(); if ( page->isDocked() ){ stackedWidget->setCurrentWidget(page); @@ -415,8 +414,8 @@ void MainWin::setContextMenuDockText() QTreeWidgetItem *currentitem = treeWidget->currentItem(); /* Is this one of the first level pages */ - if( m_treeindex.value(currentitem) ){ - Pages* page = m_treeindex.value(currentitem); + if( getFromHash(currentitem) ){ + Pages* page = getFromHash(currentitem); setContextMenuDockText(page, currentitem); } } @@ -464,7 +463,7 @@ void MainWin::setTreeWidgetItemDockColor(Pages* page, QTreeWidgetItem* item) */ void MainWin::setTreeWidgetItemDockColor(Pages* page) { - QTreeWidgetItem* item = m_treeindex.value(page); + QTreeWidgetItem* item = getFromHash(page); if( item ){ setTreeWidgetItemDockColor(page, item); } @@ -481,3 +480,31 @@ void MainWin::stackItemChanged(int) /* run the virtual function in case this class overrides it */ page->currentStackItem(); } + +/* + * Function to simplify insertion of QTreeWidgetItem <-> Page association + * into a double direction hash. + */ +void MainWin::hashInsert(QTreeWidgetItem *item, Pages *page) +{ + m_pagehash.insert(item, page); + m_widgethash.insert(page, item); +} + +/* + * Function to retrieve a Page* when the item in the page selector's tree is + * known. + */ +Pages* MainWin::getFromHash(QTreeWidgetItem *item) +{ + return m_pagehash.value(item); +} + +/* + * Function to retrieve the page selectors tree widget item when the page is + * known. + */ +QTreeWidgetItem* MainWin::getFromHash(Pages *page) +{ + return m_widgethash.value(page); +} diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index cbe6634eb7..97747b1c2e 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -45,7 +45,6 @@ #include "run/run.h" #include "restore/restore.h" #include "medialist/medialist.h" -#include "pagehash.h" class Console; @@ -65,6 +64,13 @@ public: void setContextMenuDockText(Pages *, QTreeWidgetItem *); void setTreeWidgetItemDockColor(Pages *, QTreeWidgetItem *); void setTreeWidgetItemDockColor(Pages *); + void hashInsert(QTreeWidgetItem *, Pages *); + Pages* getFromHash(QTreeWidgetItem *); + QTreeWidgetItem* getFromHash(Pages *); + /* This hash is to get the page when the page selector widget is known */ + QHash m_pagehash; + /* This hash is to get the page selector widget when the page is known */ + QHash m_widgethash; public slots: void input_line(); @@ -92,9 +98,6 @@ private: private: Console *m_console; Pages *m_pagespophold; - PageHash m_treeindex; -// QHash m_pagehash; -// QHash m_widgethash; QStringList m_cmd_history; int m_cmd_last; }; diff --git a/bacula/src/qt-console/medialist/medialist.ui b/bacula/src/qt-console/medialist/medialist.ui index f56ce7a960..8a78a43f73 100644 --- a/bacula/src/qt-console/medialist/medialist.ui +++ b/bacula/src/qt-console/medialist/medialist.ui @@ -10,7 +10,7 @@ - Console + Media Tree diff --git a/bacula/src/qt-console/pagehash.cpp b/bacula/src/qt-console/pagehash.cpp deleted file mode 100644 index 69add1f4a7..0000000000 --- a/bacula/src/qt-console/pagehash.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation plus additions - that are listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ -/* - * Version $Id: batstack.cpp 4230 2007-02-21 20:07:37Z kerns $ - * - * Dirk Bartley, March 2007 - */ - -#include "pagehash.h" - -PageHash::PageHash() -{ -} - -void PageHash::insert(QTreeWidgetItem *item, Pages *page) -{ - m_pagehash.insert(item, page); - m_widgethash.insert(page, item); -} - -Pages* PageHash::value(QTreeWidgetItem *item) -{ - return m_pagehash.value(item); -} - -QTreeWidgetItem* PageHash::value(Pages *page) -{ - return m_widgethash.value(page); -} diff --git a/bacula/src/qt-console/pagehash.h b/bacula/src/qt-console/pagehash.h deleted file mode 100644 index e167da6d46..0000000000 --- a/bacula/src/qt-console/pagehash.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _PAGEHASH_H_ -#define _PAGEHASH_H_ -/* - Bacula® - The Network Backup Solution - - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. - - The main author of Bacula is Kern Sibbald, with contributions from - many others, a complete list can be found in the file AUTHORS. - This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public - License as published by the Free Software Foundation plus additions - that are listed in the file LICENSE. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - Bacula® is a registered trademark of John Walker. - The licensor of Bacula is the Free Software Foundation Europe - (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, - Switzerland, email:ftf@fsfeurope.org. -*/ -/* - * Version $Id: batstack.h 4230 2007-02-21 20:07:37Z kerns $ - * - * Dirk Bartley, March 2007 - */ - -#include -#include -#include "pages.h" - -/* - * The Page Hash Class - */ - -class PageHash -{ -public: - PageHash(); - void insert(QTreeWidgetItem *, Pages *); - Pages* value(QTreeWidgetItem *); - QTreeWidgetItem* value(Pages *); - QHash m_pagehash; - QHash m_widgethash; -}; - -#endif /* _PAGEHASH_H_ */ -- 2.39.5