From 8c871615bfe26da9b7c13b23231ae801144d0d1a Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Tue, 27 Mar 2007 15:12:23 +0000 Subject: [PATCH] dhb Having a frustrating time. This compliles and runs fine. Have the iterating when the index can be pulled from the tree widget item sort of accomplished. Need to think more about how to consistently get to a window in the list git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4432 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/batstack.cpp | 16 +++-- bacula/src/qt-console/batstack.h | 3 +- bacula/src/qt-console/console/console.cpp | 5 -- bacula/src/qt-console/console/console.h | 1 - bacula/src/qt-console/mainwin.cpp | 61 ++++++++----------- bacula/src/qt-console/mainwin.h | 3 +- bacula/src/qt-console/medialist/medialist.cpp | 6 +- bacula/src/qt-console/medialist/medialist.h | 2 +- bacula/src/qt-console/restore/brestore.cpp | 5 +- bacula/src/qt-console/restore/restore.h | 2 +- 10 files changed, 48 insertions(+), 56 deletions(-) diff --git a/bacula/src/qt-console/batstack.cpp b/bacula/src/qt-console/batstack.cpp index bbf9ad5a85..df52485296 100644 --- a/bacula/src/qt-console/batstack.cpp +++ b/bacula/src/qt-console/batstack.cpp @@ -64,10 +64,11 @@ void BatStack::Togglestack() } } -void BatStack::SetBSTreeWidgetItem(QTreeWidgetItem *treeItem) -{ - m_treeItem=treeItem; -} +/* needed this so that the console class could set m_treeItem */ +//void BatStack::SetBSTreeWidgetItem(QTreeWidgetItem *treeItem) +//{ +// m_treeItem=treeItem; +//} bool BatStack::isStacked() { @@ -93,3 +94,10 @@ void BatStack::PgSeltreeWidgetClicked(){ void BatStack::PgSeltreeWidgetDoubleClicked(){ } + +void BatStack::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/batstack.h b/bacula/src/qt-console/batstack.h index 0ae62023d4..ee3197c466 100644 --- a/bacula/src/qt-console/batstack.h +++ b/bacula/src/qt-console/batstack.h @@ -42,12 +42,13 @@ public: void AddTostack(); void RemoveFromstack(); void Togglestack(); - void SetBSTreeWidgetItem(QTreeWidgetItem *treeItem); + //void SetBSTreeWidgetItem(QTreeWidgetItem *treeItem); bool isStacked(); QStackedWidget *m_parent; QTreeWidgetItem *m_treeItem; virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); + void SetPassedValues(QStackedWidget*, QTreeWidgetItem*, int ); public slots: /* closeEvent is a virtual function inherited from QWidget */ diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index 7af520a198..d161f25dde 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -570,11 +570,6 @@ void Console::notify(bool enable) m_notifier->setEnabled(enable); } -void Console::setTreeItem(QTreeWidgetItem *item) -{ - m_treeItem = item; -} - void Console::setDirRes(DIRRES *dir) { m_dir = dir; diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index 264651fe1f..c434d9064b 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -90,7 +90,6 @@ public: void beginNewCommand(); void displayToPrompt(); void discardToPrompt(); - void setTreeItem(QTreeWidgetItem *item); void setDirRes(DIRRES *dir); void dosql(QString* sqlcmd, QStringList& strlstret); diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index f321f6ea84..e6391d99b9 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -79,11 +79,10 @@ void MainWin::createPages() topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); /* Create Tree Widget Item */ item = createPage("Console", topItem); - m_console->setTreeItem(item); + m_console->SetPassedValues(stackedWidget, item, m_pages++ ); /* Append to bstacklist */ m_bstacklist.append(m_console); /* Set BatStack m_treeItem */ - m_console->SetBSTreeWidgetItem(item); QBrush redBrush(Qt::red); item->setForeground(0, redBrush); @@ -96,12 +95,13 @@ void MainWin::createPages() * */ /* brestore */ - m_bstacklist.append(new bRestore( stackedWidget, createPage("brestore", topItem) )); + m_bstacklist.append( new bRestore( stackedWidget, createPage("brestore", topItem), m_pages++ )); /* lastly for now, the medialist */ - m_bstacklist.append(new MediaList(stackedWidget, m_console, createPage("Storage Tree", topItem ))); + m_bstacklist.append( new MediaList(stackedWidget, m_console, createPage("Storage Tree", topItem ), m_pages++)); /* Iterate through and add to the stack */ + /* foreach will not take a QList of pointers, darn */ for ( QList::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) { (*bstackItem)->AddTostack(); } @@ -220,20 +220,15 @@ void MainWin::readSettings() void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) { - /* Iterate through and find the tree widget item clicked */ column+=0; - QList::iterator bstackItem; - bstackItem = m_bstacklist.begin(); - while ( bstackItem != m_bstacklist.end() ){ - if ( item == (*bstackItem)->m_treeItem ) { - int stackindex=stackedWidget->indexOf( *bstackItem ); - if( stackindex >= 0 ){ - stackedWidget->setCurrentIndex(stackindex); - } - (*bstackItem)->PgSeltreeWidgetClicked(); - } - ++bstackItem; + /* Use tree item's Qt::UserRole to get treeindex */ + int treeindex = item->data(column, Qt::UserRole).toInt(); + int stackindex=stackedWidget->indexOf( m_bstacklist[treeindex] ); + if( stackindex >= 0 ){ + stackedWidget->setCurrentIndex(stackindex); } + /* run the virtual function in case this class overrides it */ + m_bstacklist[treeindex]->PgSeltreeWidgetClicked(); } /* @@ -242,23 +237,20 @@ void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column) { /* Iterate through and find the tree widget item double clicked */ column+=0; - QList::iterator bstackItem; - bstackItem = m_bstacklist.begin(); - while ( bstackItem != m_bstacklist.end() ){ - if ( item == (*bstackItem)->m_treeItem ) { - /* This could be a call a virtual function ?? or just popup a popup menu for an action */ - if ( (*bstackItem)->isStacked() == true ){ - m_bstackpophold=*bstackItem; - QMenu *popup = new QMenu( treeWidget ); - connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut())); - popup->exec(QCursor::pos()); - } else { - (*bstackItem)->Togglestack(); - } - (*bstackItem)->PgSeltreeWidgetDoubleClicked(); - } - ++bstackItem; + /* Use tree item's Qt::UserRole to get treeindex */ + int treeindex = item->data(column, Qt::UserRole).toInt(); + if ( m_bstacklist[treeindex]->isStacked() == true ){ + m_bstackpophold=m_bstacklist[treeindex]; + /* Create a popup menu before pulling window out */ + QMenu *popup = new QMenu( treeWidget ); + connect(popup->addAction("Pull Window Out"), SIGNAL(triggered()), this, SLOT(pullWindowOut())); + popup->exec(QCursor::pos()); + } else { + /* Just pull it back in without prompting */ + m_bstacklist[treeindex]->Togglestack(); } + /* Here is the virtual function so that different classes can do different things */ + m_bstacklist[treeindex]->PgSeltreeWidgetDoubleClicked(); } void MainWin::labelDialogClicked() @@ -334,11 +326,10 @@ void MainWin::pullWindowOut() void MainWin::pullWindowOutButton() { int curindex = stackedWidget->currentIndex(); - QList::iterator bstackItem; - bstackItem = m_bstacklist.begin(); + QList::iterator bstackItem = m_bstacklist.begin(); bool done=false; while ( (bstackItem != m_bstacklist.end()) && not(done) ){ - if ( curindex == stackedWidget->indexOf( *bstackItem ) ){ + if ( curindex == stackedWidget->indexOf( *bstackItem )){ (*bstackItem)->Togglestack(); done=true; } diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index 13ee72acdc..662d19277f 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -85,10 +85,9 @@ private: private: QString m_UserInput; Console *m_console; -// bRestore *m_brestore; -// MediaList *m_medialist; BatStack *m_bstackpophold; QList m_bstacklist; + QList m_bstackindex; QStringList m_cmd_history; int m_cmd_last; int m_pages; diff --git a/bacula/src/qt-console/medialist/medialist.cpp b/bacula/src/qt-console/medialist/medialist.cpp index 1e3e453730..a58fc5385d 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -42,14 +42,13 @@ #include "joblist/joblist.h" #include -MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem) +MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem, int indexseq) { + SetPassedValues(parent, treeItem, indexseq ); setupUi(this); - m_parent=parent; m_treeWidget = treeWidget; /* our Storage Tree Tree Widget */ m_console = console; - m_treeItem = treeItem; createConnections(); m_populated=false; m_headerlist = new QStringList(); @@ -85,6 +84,7 @@ void MediaList::populateTree() /* Start with a list of pools */ m_poollist->clear(); + m_headerlist->clear(); m_headerlist->append("Volume Name"); m_headerlist->append("Media Id"); m_headerlist->append("Type"); diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index 5964eedc5a..1e07e3dae8 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -44,7 +44,7 @@ class MediaList : public BatStack, public Ui::MediaListForm Q_OBJECT public: - MediaList(QStackedWidget *parent,Console *console, QTreeWidgetItem *treeItem); + MediaList(QStackedWidget *parent,Console *console, QTreeWidgetItem *treeItem, int indexseq); ~MediaList(); virtual void PgSeltreeWidgetClicked(); virtual void PgSeltreeWidgetDoubleClicked(); diff --git a/bacula/src/qt-console/restore/brestore.cpp b/bacula/src/qt-console/restore/brestore.cpp index 94d79ecbef..d2ca3e95a1 100644 --- a/bacula/src/qt-console/restore/brestore.cpp +++ b/bacula/src/qt-console/restore/brestore.cpp @@ -38,10 +38,9 @@ #include "bat.h" #include "restore.h" -bRestore::bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem) +bRestore::bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem, int indexseq) { + SetPassedValues(parent, treeItem, indexseq ); (void)parent; setupUi(this); - m_parent=parent; - m_treeItem = treeItem; } diff --git a/bacula/src/qt-console/restore/restore.h b/bacula/src/qt-console/restore/restore.h index 91f29252db..2b67940a15 100644 --- a/bacula/src/qt-console/restore/restore.h +++ b/bacula/src/qt-console/restore/restore.h @@ -97,7 +97,7 @@ class bRestore : public BatStack, public Ui::bRestoreForm Q_OBJECT public: - bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem); + bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem, int indexseq); public slots: -- 2.39.5