From 672dc30b96804c5f712ec03f89ba9eb9ca852123 Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Thu, 29 Mar 2007 02:46:14 +0000 Subject: [PATCH] dhb Use of QHash instead of QList, solves all the issues of Items being removed from QList and the key pointing to the wrong object. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4448 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/mainwin.cpp | 45 +++++++++++++++---------------- bacula/src/qt-console/mainwin.h | 3 +-- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 1538d180fe..aa23377287 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -83,10 +83,10 @@ void MainWin::createPages() /* Create Tree Widget Item */ item = createPage("Console", topItem); - m_console->SetPassedValues(stackedWidget, item, m_pages++ ); + m_console->SetPassedValues(stackedWidget, item, m_pages ); /* Append to pageslist */ - m_pageslist.append(m_console); + m_pageshash.insert(m_pages, m_console); /* Set Color of treeWidgetItem for the console * It will be set to gree in the console class if the connection is made. @@ -99,24 +99,25 @@ void MainWin::createPages() * All should be * 1. create tree widget item * 2. create object passing pointer to tree widget item (modified constructors to pass QTreeWidget pointers) - * 3. append to stacklist - * And it can even be done in one line. + * 3. append to stackhash */ /* brestore */ - m_pageslist.append(new bRestore(stackedWidget, - createPage("brestore", topItem), m_pages++ )); + m_pages++; + item=createPage("brestore", topItem); + bRestore* brestore=new bRestore(stackedWidget, item, m_pages); + m_pageshash.insert(m_pages, brestore); /* lastly for now, the medialist */ - m_pageslist.append(new MediaList(stackedWidget, m_console, - createPage("Storage Tree", topItem ), m_pages++)); + m_pages++; + item=createPage("Storage Tree", topItem ); + MediaList* medialist=new MediaList(stackedWidget, m_console, item, m_pages); + m_pageshash.insert(m_pages, medialist); /* Iterate through and add to the stack */ - for (QList::iterator pagesItem = m_pageslist.begin(); - pagesItem != m_pageslist.end(); ++pagesItem ) { - (*pagesItem)->dockPage(); - } + foreach (Pages* pagesItem, m_pageshash) + pagesItem->dockPage(); treeWidget->expandItem(topItem); stackedWidget->setCurrentIndex(0); @@ -240,13 +241,13 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) { /* Use tree item's Qt::UserRole to get treeindex */ int treeindex = item->data(column, Qt::UserRole).toInt(); - int stackindex=stackedWidget->indexOf(m_pageslist[treeindex]); + int stackindex=stackedWidget->indexOf(m_pageshash.value(treeindex)); if( stackindex >= 0 ){ stackedWidget->setCurrentIndex(stackindex); } /* run the virtual function in case this class overrides it */ - m_pageslist[treeindex]->PgSeltreeWidgetClicked(); + m_pageshash.value(treeindex)->PgSeltreeWidgetClicked(); } /* @@ -258,8 +259,8 @@ void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column) int treeindex = item->data(column, Qt::UserRole).toInt(); /* Use tree item's Qt::UserRole to get treeindex */ - if (m_pageslist[treeindex]->isDocked()) { - m_pagespophold = m_pageslist[treeindex]; + if (m_pageshash.value(treeindex)->isDocked()) { + m_pagespophold = m_pageshash.value(treeindex); /* Create a popup menu before floating window */ QMenu *popup = new QMenu( treeWidget ); @@ -268,10 +269,10 @@ void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column) popup->exec(QCursor::pos()); } else { /* Just pull it back in without prompting */ - m_pageslist[treeindex]->togglePageDocking(); + m_pageshash.value(treeindex)->togglePageDocking(); } /* Here is the virtual function so that different classes can do different things */ - m_pageslist[treeindex]->PgSeltreeWidgetDoubleClicked(); + m_pageshash.value(treeindex)->PgSeltreeWidgetDoubleClicked(); } void MainWin::labelDialogClicked() @@ -347,13 +348,11 @@ void MainWin::undockWindow() void MainWin::undockWindowButton() { int curindex = stackedWidget->currentIndex(); - QList::iterator pagesItem = m_pageslist.begin(); - while ((pagesItem != m_pageslist.end())){ - if (curindex == stackedWidget->indexOf(*pagesItem)) { - (*pagesItem)->togglePageDocking(); + foreach (Pages* pagesItem, m_pageshash){ + if (curindex == stackedWidget->indexOf(pagesItem)) { + pagesItem->togglePageDocking(); break; } - ++pagesItem; } } diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 1f0a900e02..5e3e7c504b 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -86,8 +86,7 @@ private: private: Console *m_console; Pages *m_pagespophold; - QList m_pageslist; - QList m_pagesindex; + QHash m_pageshash; QStringList m_cmd_history; int m_cmd_last; int m_pages; -- 2.39.5