From 72e6c6f5750406b593382b73e17f5963ae2147eb Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Mon, 9 Apr 2007 01:47:56 +0000 Subject: [PATCH] Use a hash QHash instead of QHash m_pagehash This way, the integer stored in QT::UserRole is not needed at all. The hash directly allows for conversion from a known treeWidgetItem to a page. Since the integer is not required to be passed and held in subclasses of the pages class, clean up the constructors of Subclasses to not get the integer value and set back to nearly like they were before. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4528 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/console/console.cpp | 31 +++------- bacula/src/qt-console/console/console.h | 2 + bacula/src/qt-console/mainwin.cpp | 61 +++++++------------ bacula/src/qt-console/mainwin.h | 4 +- bacula/src/qt-console/medialist/medialist.cpp | 4 +- bacula/src/qt-console/medialist/medialist.h | 2 +- bacula/src/qt-console/pages.cpp | 13 ---- bacula/src/qt-console/pages.h | 2 - bacula/src/qt-console/restore/brestore.cpp | 4 +- bacula/src/qt-console/restore/restore.h | 2 +- 10 files changed, 39 insertions(+), 86 deletions(-) diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index e37843173d..2dc8b1b739 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -118,7 +118,7 @@ void Console::connect() /* Update page selector to green to indicate that Console is connected */ mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/connected.png"))); QBrush greenBrush(Qt::green); - m_treeItem->setForeground(0, greenBrush); + m_consoleItem->setForeground(0, greenBrush); } jcr.dir_bsock = m_sock; @@ -416,7 +416,7 @@ void Console::write_dir(const char *msg) mainWin->set_status(" Director not connected. Click on connect button."); mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); QBrush redBrush(Qt::red); - m_treeItem->setForeground(0, redBrush); + m_consoleItem->setForeground(0, redBrush); m_at_prompt = false; } } @@ -570,7 +570,7 @@ int Console::read() m_sock = NULL; mainWin->actionConnect->setIcon(QIcon(QString::fromUtf8("images/disconnected.png"))); QBrush redBrush(Qt::red); - m_treeItem->setForeground(0, redBrush); + m_consoleItem->setForeground(0, redBrush); m_notifier->setEnabled(false); delete m_notifier; m_notifier = NULL; @@ -610,27 +610,12 @@ void Console::notify(bool enable) m_notifier->setEnabled(enable); } +void Console::setTreeItem(QTreeWidgetItem *item) +{ + m_consoleItem = item; +} + void Console::setDirRes(DIRRES *dir) { m_dir = dir; } -#ifdef xxx -******FIXME****** Just Delete me -void Console::dosql(QString* sqlcmd, QStringList& strlstret) -{ - int stat; - /* don't effect the string coming in */ - QString cmd(*sqlcmd); - - cmd = ".sql \"" + cmd + "\""; - - write_dir(cmd.toUtf8().data()); - while ((stat=read()) > 0) { - QString line = msg(); - QRegExp regex("^Using Catalog"); - if ( regex.indexIn(line) < 0 ){ - strlstret.append(line); - } - } -} -#endif diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index d25ceb1524..e3274359f4 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -94,6 +94,7 @@ public: void beginNewCommand(); void displayToPrompt(); void discardToPrompt(); + void setTreeItem(QTreeWidgetItem *item); void setDirRes(DIRRES *dir); QStringList job_list; @@ -123,6 +124,7 @@ private: bool m_at_prompt; QSocketNotifier *m_notifier; QTextCursor *m_cursor; + QTreeWidgetItem *m_consoleItem; bool m_api_set; bool m_messages_pending; QTimer *m_timer; diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 3fd51f1b31..c3b569000d 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -47,7 +47,6 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) treeWidget->setHeaderLabel("Select Page"); treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); - m_pages = 0; createPages(); resetFocus(); @@ -78,16 +77,15 @@ void MainWin::createPages() /* The top tree item representing the director */ topItem = createTopPage(dir->name()); - topItem->setData(0, Qt::UserRole, QVariant(m_pages)); - m_pages++; topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); /* Create Tree Widget Item */ item = createPage("Console", topItem); - m_console->SetPassedValues(stackedWidget, item, m_pages ); + m_console->setTreeItem(item); /* Append to pagelist */ - m_pagehash.insert(m_pages, m_console); + m_pagehash.insert(item, m_console); + m_widgethash.insert(m_console, item); /* Set Color of treeWidgetItem for the console * It will be set to gree in the console class if the connection is made. @@ -104,17 +102,17 @@ void MainWin::createPages() */ /* brestore */ - m_pages++; item=createPage("brestore", topItem); - bRestore* brestore=new bRestore(stackedWidget, item, m_pages); - m_pagehash.insert(m_pages, brestore); + bRestore* brestore=new bRestore(stackedWidget); + m_pagehash.insert(item, brestore); + m_widgethash.insert(brestore, item); /* lastly for now, the medialist */ - m_pages++; item=createPage("Media", topItem ); - MediaList* medialist=new MediaList(stackedWidget, m_console, item, m_pages); - m_pagehash.insert(m_pages, medialist); + MediaList* medialist=new MediaList(stackedWidget, m_console); + m_pagehash.insert(item, medialist); + m_widgethash.insert(medialist, item); /* Iterate through and add to the stack */ foreach(Pages *page, m_pagehash) @@ -248,14 +246,11 @@ void MainWin::readSettings() * This subroutine is called with an item in the Page Selection window * is clicked */ -void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) +void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/) { - /* Use tree item's Qt::UserRole to get treeindex */ - int treeindex = item->data(column, Qt::UserRole).toInt(); - /* Is this one of the first level pages */ - if( m_pagehash.value(treeindex) ){ - Pages* page = m_pagehash.value(treeindex); + if( m_pagehash.value(item) ){ + Pages* page = m_pagehash.value(item); int stackindex=stackedWidget->indexOf(page); if( stackindex >= 0 ){ @@ -263,9 +258,7 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) stackedWidget->setCurrentWidget(page); } /* run the virtual function in case this class overrides it */ - if( treeindex > 0 ){ - page->PgSeltreeWidgetClicked(); - } + page->PgSeltreeWidgetClicked(); } } @@ -282,15 +275,12 @@ void MainWin::treeItemDoubleClicked(QTreeWidgetItem * /*item*/, int /*column*/) */ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *previousitem) { - int treeindex; /* The Previous item */ - /* Use tree item's Qt::UserRole to get treeindex now for the previousitem */ if ( previousitem ){ - treeindex = previousitem->data(0, Qt::UserRole).toInt(); /* Is this one of the first level pages */ - if( m_pagehash.value(treeindex) ){ - Pages* page = m_pagehash.value(treeindex); + if( m_pagehash.value(previousitem) ){ + Pages* page = m_pagehash.value(previousitem); treeWidget->removeAction(actionToggleDock); foreach( QAction* pageaction, page->m_contextActions ){ treeWidget->removeAction(pageaction); @@ -298,12 +288,9 @@ void MainWin::treeItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem *pre } } - /* Use tree item's Qt::UserRole to get treeindex */ - treeindex = currentitem->data(0, Qt::UserRole).toInt(); - /* Is this one of the first level pages */ - if( m_pagehash.value(treeindex) ){ - Pages* page = m_pagehash.value(treeindex); + if( m_pagehash.value(currentitem) ){ + Pages* page = m_pagehash.value(currentitem); int stackindex = stackedWidget->indexOf(page); /* Is this page currently on the stack */ @@ -406,12 +393,9 @@ void MainWin::toggleDockContextWindow() { QTreeWidgetItem *currentitem = treeWidget->currentItem(); - /* Use tree item's Qt::UserRole to get treeindex */ - int treeindex = currentitem->data(0, Qt::UserRole).toInt(); - /* Is this one of the first level pages */ - if( m_pagehash.value(treeindex) ){ - Pages* page = m_pagehash.value(treeindex); + if( m_pagehash.value(currentitem) ){ + Pages* page = m_pagehash.value(currentitem); page->togglePageDocking(); if ( page->isDocked() ){ stackedWidget->setCurrentWidget(page); @@ -432,12 +416,9 @@ void MainWin::setContextMenuDockText() { QTreeWidgetItem *currentitem = treeWidget->currentItem(); - /* Use tree item's Qt::UserRole to get treeindex */ - int treeindex = currentitem->data(0, Qt::UserRole).toInt(); - /* Is this one of the first level pages */ - if( m_pagehash.value(treeindex) ){ - Pages* page = m_pagehash.value(treeindex); + if( m_pagehash.value(currentitem) ){ + Pages* page = m_pagehash.value(currentitem); setContextMenuDockText(page, currentitem); } } diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 21f6cfa956..18d5792667 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -90,10 +90,10 @@ private: private: Console *m_console; Pages *m_pagespophold; - QHash m_pagehash; + QHash m_pagehash; + QHash m_widgethash; QStringList m_cmd_history; int m_cmd_last; - int m_pages; }; #endif /* _MAINWIN_H_ */ diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 13c14d0fef..663e34901c 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -42,13 +42,13 @@ #include "mediaedit/mediaedit.h" #include "joblist/joblist.h" -MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem, int indexseq) +MediaList::MediaList(QStackedWidget *parent, Console *console) { - SetPassedValues(parent, treeItem, indexseq ); setupUi(this); /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_medialist.h */ mp_console = console; + m_parent = parent; createConnections(); m_populated = false; m_checkcurwidget = true; diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index 875da89d7b..fb4e2c94e4 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -43,7 +43,7 @@ class MediaList : public Pages, public Ui::MediaListForm Q_OBJECT public: - MediaList(QStackedWidget *parent,Console *console, QTreeWidgetItem *treeItem, int indexseq); + MediaList(QStackedWidget *parent, Console *console); ~MediaList(); virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index 19d225f4da..6cd60eba72 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -159,16 +159,3 @@ void Pages::PgSeltreeWidgetDoubleClicked() void Pages::currentStackItem() { } - -/* - * This function exists because to have an easy way for programmers adding new features to understand - * exactly what values needed to be set in order to behave correctly in the interface. It can - * be called from the constructor, like with medialist or after being constructed, like with - * Console. - */ -void Pages::SetPassedValues(QStackedWidget* passedStackedWidget, QTreeWidgetItem* passedTreeItem, int indexseq ) -{ - m_parent = passedStackedWidget; - m_treeItem = passedTreeItem; - m_treeItem->setData(0, Qt::UserRole, QVariant(indexseq)); -} diff --git a/bacula/src/qt-console/pages.h b/bacula/src/qt-console/pages.h index 8ed8920875..a1b3eb2995 100644 --- a/bacula/src/qt-console/pages.h +++ b/bacula/src/qt-console/pages.h @@ -58,9 +58,7 @@ public: void togglePageDocking(); bool isDocked(); QStackedWidget *m_parent; - QTreeWidgetItem *m_treeItem; QList m_contextActions; - void SetPassedValues(QStackedWidget*, QTreeWidgetItem*, int ); virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); virtual void currentStackItem(); diff --git a/bacula/src/qt-console/restore/brestore.cpp b/bacula/src/qt-console/restore/brestore.cpp index bfe4fdc210..0e38dd69de 100644 --- a/bacula/src/qt-console/restore/brestore.cpp +++ b/bacula/src/qt-console/restore/brestore.cpp @@ -38,9 +38,9 @@ #include "bat.h" #include "restore.h" -bRestore::bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem, int indexseq) +bRestore::bRestore(QStackedWidget *parent) { - SetPassedValues(parent, treeItem, indexseq ); + m_parent = parent; (void)parent; setupUi(this); } diff --git a/bacula/src/qt-console/restore/restore.h b/bacula/src/qt-console/restore/restore.h index 5822ee2494..4bbe1fcbb1 100644 --- a/bacula/src/qt-console/restore/restore.h +++ b/bacula/src/qt-console/restore/restore.h @@ -97,7 +97,7 @@ class bRestore : public Pages, public Ui::bRestoreForm Q_OBJECT public: - bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem, int indexseq); + bRestore(QStackedWidget *parent); ~bRestore(); public slots: -- 2.39.5