From 67a2d77443d470e9d001cb09e3b64e8bdcabe6de Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Mon, 9 Apr 2007 02:48:46 +0000 Subject: [PATCH] dhb Create a class to be a two way hash. This way it is easy to insert a QTreeWidget* and Pages* combination and then get the item associated with any item easily. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4529 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/bat.pro | 4 +++ bacula/src/qt-console/mainwin.cpp | 55 +++++++++++++++++++----------- bacula/src/qt-console/mainwin.h | 7 ++-- bacula/src/qt-console/pagehash.cpp | 54 +++++++++++++++++++++++++++++ bacula/src/qt-console/pagehash.h | 55 ++++++++++++++++++++++++++++++ bacula/src/qt-console/pages.cpp | 9 ++--- 6 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 bacula/src/qt-console/pagehash.cpp create 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 df4c673183..578da0d92c 100644 --- a/bacula/src/qt-console/bat.pro +++ b/bacula/src/qt-console/bat.pro @@ -52,6 +52,10 @@ 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 c3b569000d..ac13a49b02 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -36,6 +36,7 @@ */ #include "bat.h" +#include "pagehash.h" MainWin::MainWin(QWidget *parent) : QMainWindow(parent) { @@ -84,8 +85,7 @@ void MainWin::createPages() m_console->setTreeItem(item); /* Append to pagelist */ - m_pagehash.insert(item, m_console); - m_widgethash.insert(m_console, item); + m_treeindex.insert(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,18 +104,16 @@ void MainWin::createPages() /* brestore */ item=createPage("brestore", topItem); bRestore* brestore=new bRestore(stackedWidget); - m_pagehash.insert(item, brestore); - m_widgethash.insert(brestore, item); + m_treeindex.insert(item, brestore); /* lastly for now, the medialist */ item=createPage("Media", topItem ); MediaList* medialist=new MediaList(stackedWidget, m_console); - m_pagehash.insert(item, medialist); - m_widgethash.insert(medialist, item); + m_treeindex.insert(item, medialist); /* Iterate through and add to the stack */ - foreach(Pages *page, m_pagehash) + foreach(Pages *page, m_treeindex.m_pagehash) page->dockPage(); treeWidget->expandItem(topItem); @@ -216,7 +214,7 @@ void MainWin::closeEvent(QCloseEvent *event) m_console->writeSettings(); m_console->terminate(); event->accept(); - foreach(Pages *page, m_pagehash){ + foreach(Pages *page, m_treeindex.m_pagehash){ if( !page->isDocked() ) page->close(); } @@ -249,8 +247,8 @@ void MainWin::readSettings() void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/) { /* Is this one of the first level pages */ - if( m_pagehash.value(item) ){ - Pages* page = m_pagehash.value(item); + if( m_treeindex.value(item) ){ + Pages* page = m_treeindex.value(item); int stackindex=stackedWidget->indexOf(page); if( stackindex >= 0 ){ @@ -279,8 +277,8 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre if ( previousitem ){ /* Is this one of the first level pages */ - if( m_pagehash.value(previousitem) ){ - Pages* page = m_pagehash.value(previousitem); + if( m_treeindex.value(previousitem) ){ + Pages* page = m_treeindex.value(previousitem); treeWidget->removeAction(actionToggleDock); foreach( QAction* pageaction, page->m_contextActions ){ treeWidget->removeAction(pageaction); @@ -289,8 +287,8 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre } /* Is this one of the first level pages */ - if( m_pagehash.value(currentitem) ){ - Pages* page = m_pagehash.value(currentitem); + if( m_treeindex.value(currentitem) ){ + Pages* page = m_treeindex.value(currentitem); int stackindex = stackedWidget->indexOf(page); /* Is this page currently on the stack */ @@ -394,8 +392,8 @@ void MainWin::toggleDockContextWindow() QTreeWidgetItem *currentitem = treeWidget->currentItem(); /* Is this one of the first level pages */ - if( m_pagehash.value(currentitem) ){ - Pages* page = m_pagehash.value(currentitem); + if( m_treeindex.value(currentitem) ){ + Pages* page = m_treeindex.value(currentitem); page->togglePageDocking(); if ( page->isDocked() ){ stackedWidget->setCurrentWidget(page); @@ -417,8 +415,8 @@ void MainWin::setContextMenuDockText() QTreeWidgetItem *currentitem = treeWidget->currentItem(); /* Is this one of the first level pages */ - if( m_pagehash.value(currentitem) ){ - Pages* page = m_pagehash.value(currentitem); + if( m_treeindex.value(currentitem) ){ + Pages* page = m_treeindex.value(currentitem); setContextMenuDockText(page, currentitem); } } @@ -427,7 +425,7 @@ void MainWin::setContextMenuDockText() * Function to set the text of the toggle dock context menu when page and * widget item are known. This is the more commonly used. */ -void MainWin::setContextMenuDockText( Pages* page, QTreeWidgetItem* item ) +void MainWin::setContextMenuDockText(Pages* page, QTreeWidgetItem* item) { QString docktext(""); if( page->isDocked() ){ @@ -445,7 +443,7 @@ void MainWin::setContextMenuDockText( Pages* page, QTreeWidgetItem* item ) * Function to set the color of the tree widget item based on whether it is * docked or not. */ -void MainWin::setTreeWidgetItemDockColor( Pages* page, QTreeWidgetItem* item ) +void MainWin::setTreeWidgetItemDockColor(Pages* page, QTreeWidgetItem* item) { if( item->text(0) != "Console" ){ if( page->isDocked() ){ @@ -460,6 +458,23 @@ void MainWin::setTreeWidgetItemDockColor( Pages* page, QTreeWidgetItem* item ) } } +/* + * Overload of previous function, use treeindex to get item from page + * This is called when an undocked window is closed. + */ +void MainWin::setTreeWidgetItemDockColor(Pages* page) +{ + QTreeWidgetItem* item = m_treeindex.value(page); + if( item ){ + setTreeWidgetItemDockColor(page, item); + } +} + +/* + * This function is called when the stack item is changed. Call + * the virtual function here. Avoids a window being undocked leaving + * a window at the top of the stack unpopulated. + */ void MainWin::stackItemChanged(int) { Pages* page = (Pages*)stackedWidget->currentWidget(); diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 18d5792667..cbe6634eb7 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -45,6 +45,7 @@ #include "run/run.h" #include "restore/restore.h" #include "medialist/medialist.h" +#include "pagehash.h" class Console; @@ -63,6 +64,7 @@ public: void setContextMenuDockText(); void setContextMenuDockText(Pages *, QTreeWidgetItem *); void setTreeWidgetItemDockColor(Pages *, QTreeWidgetItem *); + void setTreeWidgetItemDockColor(Pages *); public slots: void input_line(); @@ -90,8 +92,9 @@ private: private: Console *m_console; Pages *m_pagespophold; - QHash m_pagehash; - QHash m_widgethash; + PageHash m_treeindex; +// QHash m_pagehash; +// QHash m_widgethash; QStringList m_cmd_history; int m_cmd_last; }; diff --git a/bacula/src/qt-console/pagehash.cpp b/bacula/src/qt-console/pagehash.cpp new file mode 100644 index 0000000000..69add1f4a7 --- /dev/null +++ b/bacula/src/qt-console/pagehash.cpp @@ -0,0 +1,54 @@ +/* + 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 new file mode 100644 index 0000000000..2d03cc7e58 --- /dev/null +++ b/bacula/src/qt-console/pagehash.h @@ -0,0 +1,55 @@ +#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* PageHash::value(QTreeWidgetItem *); + QTreeWidgetItem* PageHash::value(Pages *); + QHash m_pagehash; + QHash m_widgethash; +}; + +#endif /* _PAGEHASH_H_ */ diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index 6cd60eba72..7516473214 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -109,11 +109,12 @@ void Pages::closeEvent(QCloseEvent* /*event*/) { /* A Widget was closed, lets toggle it back into the window, and set it in front. */ dockPage(); + /* in case the current widget is the one which represents this, lets set the context + * menu to undock */ mainWin->setContextMenuDockText(); -// setTreeWidgetItemDockColor(page, item); -// foreach(Pages *page, m_pagehash){ -// if -// } + /* in case the current widget is not the one which represents this, lets set the + * color back to black */ + mainWin->setTreeWidgetItemDockColor(this); #ifdef xxx /* FIXME Really having problems getting it to the front, -- 2.39.5