From: Dirk H Bartley Date: Sat, 24 Mar 2007 20:05:09 +0000 (+0000) Subject: dhb This solves the really not elegant at all way to determine what tree item X-Git-Tag: Release-7.0.0~6718 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0f002d2979039e32155296a1aa4551465f5b0ea6;p=bacula%2Fbacula dhb This solves the really not elegant at all way to determine what tree item goes with what stacked widget item. ( When a tree item is clicked ) This begins the framework for being able to add and destroy tree widget items and associated stacked widget items on the fly. I still need to fix a few items such as the ability to close a window and never get it back, ... ever. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4407 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/batstack.cpp b/bacula/src/qt-console/batstack.cpp index d144ea4b32..369f07e440 100644 --- a/bacula/src/qt-console/batstack.cpp +++ b/bacula/src/qt-console/batstack.cpp @@ -64,3 +64,7 @@ void BatStack::Togglestack() AddTostack(); } } + +void BatStack::SetBSTreeWidgetItem(QTreeWidgetItem *treeItem){ + m_treeItem=treeItem; +} diff --git a/bacula/src/qt-console/batstack.h b/bacula/src/qt-console/batstack.h index beb086d469..a21a04b87b 100644 --- a/bacula/src/qt-console/batstack.h +++ b/bacula/src/qt-console/batstack.h @@ -34,20 +34,20 @@ */ #include +#include class BatStack : public QWidget { -// Q_OBJECT - public: void AddTostack(); void RemoveFromstack(); void Togglestack(); + void SetBSTreeWidgetItem(QTreeWidgetItem *treeItem); QStackedWidget *m_parent; -// BatStack(); + QTreeWidgetItem *m_treeItem; private: bool m_stacked; -// int m_PgSelTreeIndex; }; + #endif /* _BATSTACK_H_ */ diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 3009edf102..fa81992be0 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -65,39 +65,56 @@ MainWin::MainWin(QWidget *parent) : QMainWindow(parent) void MainWin::createPages() { DIRRES *dir; - QTreeWidgetItem *item, *topItem; - m_console = new Console(stackedWidget); - m_console->AddTostack(); - - m_brestore = new bRestore(stackedWidget); - m_brestore->AddTostack(); - - m_medialist = new MediaList(stackedWidget, m_console); - m_medialist->AddTostack(); + /* Create console tree stacked widget item */ + m_console = new Console(stackedWidget); + /* Console is special needs director*/ /* Just take the first Director */ LockRes(); dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); m_console->setDirRes(dir); UnlockRes(); - + /* The top tree item representing the director */ topItem = createTopPage(dir->name(), false); topItem->setIcon(0, QIcon(QString::fromUtf8("images/server.png"))); - + /* Create Tree Widget Item */ item = createPage("Console", topItem, true); + /* Append to bstacklist */ + m_bstacklist.append(m_console); + /* FIXME Associate tree item with console, may not be needed. */ m_console->setTreeItem(item); + /* Set BatStack m_treeItem */ + m_console->SetBSTreeWidgetItem(item); QBrush redBrush(Qt::red); item->setForeground(0, redBrush); + /* Now with the console created, on with the rest, these are easy */ + /* 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 */ + + /* brestore */ item = createPage("brestore", topItem, true); + m_brestore = new bRestore(stackedWidget,item); + m_bstacklist.append(m_brestore); + + /* lastly for now, the medialist */ item = createPage("Storage Tree", topItem, true); + m_medialist = new MediaList(stackedWidget, m_console, item); + m_bstacklist.append(m_medialist); - treeWidget->expandItem(topItem); + /* Iterate through and add to the stack */ + for ( QList::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) { + (*bstackItem)->AddTostack(); + } + treeWidget->expandItem(topItem); stackedWidget->setCurrentIndex(0); } +/* FIXME These Two are not needed any more because UserRole is not used. */ /* Create a root Tree Widget */ QTreeWidgetItem *MainWin::createTopPage(char *name, bool canDisplay) { @@ -111,7 +128,7 @@ QTreeWidgetItem *MainWin::createTopPage(char *name, bool canDisplay) return item; } -/* Create A Tree Widget Item Representing a Page */ +/* Create A Tree Widget Item which will be associated with a Page in the stacked widget */ QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent, bool canDisplay) { QTreeWidgetItem *item = new QTreeWidgetItem(parent); @@ -124,7 +141,6 @@ QTreeWidgetItem *MainWin::createPage(char *name, QTreeWidgetItem *parent, bool c return item; } - /* * Handle up and down arrow keys for the command line * history. @@ -218,21 +234,15 @@ void MainWin::readSettings() void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) { - /* There just has to be a more elegant way of doing this - * as more and more pages get added, this could get realllly long */ - int treeindex = item->data(column, Qt::UserRole).toInt(); - int stackindex=-1; - if( treeindex == 0 ) { - stackindex=stackedWidget->indexOf( m_console ); - } - if( treeindex == 1 ) { - stackindex=stackedWidget->indexOf( m_brestore ); - } - if( treeindex == 2 ) { - stackindex=stackedWidget->indexOf( m_medialist ); - } - if( stackindex >= 0 ){ - stackedWidget->setCurrentIndex(stackindex); + /* Iterate through and find the tree widget item clicked */ + column+=0; + for ( QList::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) { + if ( item == (*bstackItem)->m_treeItem ) { + int stackindex=stackedWidget->indexOf( *bstackItem ); + if( stackindex >= 0 ){ + stackedWidget->setCurrentIndex(stackindex); + } + } } } @@ -240,17 +250,12 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int column) */ void MainWin::treeItemDoubleClicked(QTreeWidgetItem *item, int column) { - /* There just has to be a more elegant way of doing this - * as more and more pages get added, this could get realllly long */ - int treeindex = item->data(column, Qt::UserRole).toInt(); - if( treeindex == 0 ) { - m_console->Togglestack(); - } - if( treeindex == 1 ) { - m_brestore->Togglestack(); - } - if( treeindex == 2 ) { - m_medialist->Togglestack(); + /* Iterate through and find the tree widget item double clicked */ + column+=0; + for ( QList::iterator bstackItem = m_bstacklist.begin(); bstackItem != m_bstacklist.end(); ++bstackItem ) { + if ( item == (*bstackItem)->m_treeItem ) { + (*bstackItem)->Togglestack(); + } } } diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index e44a54bc42..61082e5103 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -38,6 +38,7 @@ #define _MAINWIN_H_ #include +#include #include "ui_main.h" #include "label/label.h" #include "run/run.h" @@ -84,6 +85,8 @@ private: Console *m_console; bRestore *m_brestore; MediaList *m_medialist; + BatStack *m_bstack; + QList m_bstacklist; 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 9189855f00..ad8af3950a 100644 --- a/bacula/src/qt-console/medialist/medialist.cpp +++ b/bacula/src/qt-console/medialist/medialist.cpp @@ -43,15 +43,16 @@ #include //#include -MediaList::MediaList(QStackedWidget *parent, Console *console) +MediaList::MediaList(QStackedWidget *parent, Console *console, QTreeWidgetItem *treeItem) { setupUi(this); m_parent=parent; // AddTostack(); m_poollist = new QStringList(); - m_treeWidget = treeWidget; /* our medialist screen */ + m_treeWidget = treeWidget; /* our Storage Tree Tree Widget */ m_console = console; + m_treeItem = treeItem; createConnections(); m_popupmedia=""; } @@ -78,7 +79,7 @@ void MediaList::populateTree() } for ( QStringList::Iterator poolitem = m_poollist->begin(); poolitem != m_poollist->end(); ++poolitem ) { treeitem = new QTreeWidgetItem(topItem); - m_console->setTreeItem(treeitem); + //m_console->setTreeItem(treeitem); poolitem->replace(QRegExp("\n"), ""); treeitem->setText(0, poolitem->toUtf8().data()); treeitem->setData(0, Qt::UserRole, 1); diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index 73a120b148..bb01cab5bf 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); + MediaList(QStackedWidget *parent,Console *console, QTreeWidgetItem *treeItem); void populateTree(); public slots: diff --git a/bacula/src/qt-console/restore/brestore.cpp b/bacula/src/qt-console/restore/brestore.cpp index 5c339756a2..94d79ecbef 100644 --- a/bacula/src/qt-console/restore/brestore.cpp +++ b/bacula/src/qt-console/restore/brestore.cpp @@ -38,9 +38,10 @@ #include "bat.h" #include "restore.h" -bRestore::bRestore(QStackedWidget *parent) +bRestore::bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem) { (void)parent; setupUi(this); m_parent=parent; + m_treeItem = treeItem; } diff --git a/bacula/src/qt-console/restore/restore.cpp b/bacula/src/qt-console/restore/restore.cpp index f02aa1cd23..039db0c768 100644 --- a/bacula/src/qt-console/restore/restore.cpp +++ b/bacula/src/qt-console/restore/restore.cpp @@ -38,7 +38,7 @@ #include "bat.h" #include "restore.h" -restoreDialog::restoreDialog(Console *console) +restoreDialog::restoreDialog(Console *console ) { QStringList titles; diff --git a/bacula/src/qt-console/restore/restore.h b/bacula/src/qt-console/restore/restore.h index a2c585e4b8..91f29252db 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); + bRestore(QStackedWidget *parent, QTreeWidgetItem *treeItem); public slots: