From d957bc123ea0bf6bce65caacd6aeefed977bfefb Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Mon, 28 Apr 2008 23:30:18 +0000 Subject: [PATCH] Change fileset and client windows from tree widgets to table widgets. Fix a segfault on closing the window in mainwin. You may desire to look at the change to mainwin. 2 more windows to change to table widgets. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6857 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/clients/clients.cpp | 97 +++++++++++----------- bacula/src/qt-console/clients/clients.h | 4 +- bacula/src/qt-console/clients/clients.ui | 30 +------ bacula/src/qt-console/fileset/fileset.cpp | 98 +++++++++++------------ bacula/src/qt-console/fileset/fileset.h | 4 +- bacula/src/qt-console/fileset/fileset.ui | 12 +-- bacula/src/qt-console/mainwin.cpp | 4 +- 7 files changed, 105 insertions(+), 144 deletions(-) diff --git a/bacula/src/qt-console/clients/clients.cpp b/bacula/src/qt-console/clients/clients.cpp index 9e39ab9ecc..66c4f2c2c1 100644 --- a/bacula/src/qt-console/clients/clients.cpp +++ b/bacula/src/qt-console/clients/clients.cpp @@ -50,7 +50,7 @@ Clients::Clients() QTreeWidgetItem* thisitem = mainWin->getFromHash(this); thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/network-server.png"))); - /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_client.h */ + /* tableWidget, Storage Tree Tree Widget inherited from ui_client.h */ m_populated = false; m_checkcurwidget = true; m_closeable = false; @@ -69,36 +69,30 @@ Clients::~Clients() * The main meat of the class!! The function that querries the director and * creates the widgets with appropriate values. */ -void Clients::populateTree() +void Clients::populateTable() { - QTreeWidgetItem *clientItem, *topItem; + QTableWidgetItem *tableItem; + QBrush blackBrush(Qt::black); if (!m_console->preventInUseConnect()) return; m_checkcurwidget = false; - mp_treeWidget->clear(); + tableWidget->clear(); m_checkcurwidget = true; QStringList headerlist = (QStringList() << tr("Client Name") << tr("File Retention") << tr("Job Retention") << tr("AutoPrune") << tr("ClientId") << tr("Uname") ); - topItem = new QTreeWidgetItem(mp_treeWidget); - topItem->setText(0, tr("Clients")); - topItem->setData(0, Qt::UserRole, 0); - topItem->setExpanded(true); - - mp_treeWidget->setColumnCount(headerlist.count()); - mp_treeWidget->setHeaderLabels(headerlist); + tableWidget->setColumnCount(headerlist.count()); + tableWidget->setHorizontalHeaderLabels(headerlist); + tableWidget->setRowCount(m_console->client_list.count()); + tableWidget->verticalHeader()->hide(); + int row = 0; foreach (QString clientName, m_console->client_list){ - clientItem = new QTreeWidgetItem(topItem); - clientItem->setText(0, clientName); - clientItem->setData(0, Qt::UserRole, 1); - clientItem->setExpanded(true); - /* Set up query QString and header QStringList */ QString query(""); - query += "SELECT FileRetention, JobRetention, AutoPrune, ClientId, Uname" + query += "SELECT Name, FileRetention, JobRetention, AutoPrune, ClientId, Uname" " FROM Client" " WHERE "; query += " Name='" + clientName + "'"; @@ -118,23 +112,25 @@ void Clients::populateTree() /* there will only be one of these */ foreach (resultline, results) { fieldlist = resultline.split("\t"); - int index = 0; + int column = 0; /* Iterate through fields in the record */ foreach (field, fieldlist) { field = field.trimmed(); /* strip leading & trailing spaces */ - clientItem->setData(index+1, Qt::UserRole, 1); - /* Put media fields under the pool tree item */ - clientItem->setData(index+1, Qt::UserRole, 1); - clientItem->setText(index+1, field); - index++; + tableItem = new QTableWidgetItem(field, 1); + tableItem->setFlags(Qt::ItemIsSelectable); + tableItem->setForeground(blackBrush); + tableItem->setData(Qt::UserRole, 1); + tableWidget->setItem(row, column, tableItem); + column++; } } } } + row ++; } /* Resize the columns */ for(int cnter=0; cnterresizeColumnToContents(cnter); + tableWidget->resizeColumnToContents(cnter); } } @@ -145,7 +141,7 @@ void Clients::populateTree() void Clients::PgSeltreeWidgetClicked() { if(!m_populated) { - populateTree(); + populateTable(); m_populated=true; } } @@ -154,32 +150,31 @@ void Clients::PgSeltreeWidgetClicked() * Added to set the context menu policy based on currently active treeWidgetItem * signaled by currentItemChanged */ -void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem ) +void Clients::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem ) { /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */ if (m_checkcurwidget) { + int currentRow = currentwidgetitem->row(); + QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0); + m_currentlyselected = currentrowzeroitem->text(); + /* The Previous item */ if (previouswidgetitem) { /* avoid a segfault if first time */ - int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt(); - if (treedepth == 1){ - mp_treeWidget->removeAction(actionListJobsofClient); - mp_treeWidget->removeAction(actionStatusClientInConsole); - mp_treeWidget->removeAction(actionStatusClientWindow); - mp_treeWidget->removeAction(actionPurgeJobs); - mp_treeWidget->removeAction(actionPrune); - } + tableWidget->removeAction(actionListJobsofClient); + tableWidget->removeAction(actionStatusClientInConsole); + tableWidget->removeAction(actionStatusClientWindow); + tableWidget->removeAction(actionPurgeJobs); + tableWidget->removeAction(actionPrune); } - int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt(); - if (treedepth == 1){ + if (m_currentlyselected.length() != 0) { /* set a hold variable to the client name in case the context sensitive * menu is used */ - m_currentlyselected=currentwidgetitem->text(0); - mp_treeWidget->addAction(actionListJobsofClient); - mp_treeWidget->addAction(actionStatusClientInConsole); - mp_treeWidget->addAction(actionStatusClientWindow); - mp_treeWidget->addAction(actionPurgeJobs); - mp_treeWidget->addAction(actionPrune); + tableWidget->addAction(actionListJobsofClient); + tableWidget->addAction(actionStatusClientInConsole); + tableWidget->addAction(actionStatusClientWindow); + tableWidget->addAction(actionPurgeJobs); + tableWidget->addAction(actionPrune); } } } @@ -191,14 +186,16 @@ void Clients::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetIte */ void Clients::createContextMenu() { - mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); - mp_treeWidget->addAction(actionRefreshClients); - connect(mp_treeWidget, SIGNAL( - currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), - this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); + tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + tableWidget->addAction(actionRefreshClients); + /* for the tableItemChanged to maintain m_currentJob */ + connect(tableWidget, SIGNAL( + currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), + this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *))); + /* connect to the action specific to this pages class */ connect(actionRefreshClients, SIGNAL(triggered()), this, - SLOT(populateTree())); + SLOT(populateTable())); connect(actionListJobsofClient, SIGNAL(triggered()), this, SLOT(showJobs())); connect(actionStatusClientInConsole, SIGNAL(triggered()), this, @@ -238,8 +235,8 @@ void Clients::consoleStatusClient() void Clients::currentStackItem() { if(!m_populated) { - populateTree(); - /* Create the context menu for the client tree */ + populateTable(); + /* Create the context menu for the client table */ m_populated=true; } } diff --git a/bacula/src/qt-console/clients/clients.h b/bacula/src/qt-console/clients/clients.h index d7a9982279..9779dde686 100644 --- a/bacula/src/qt-console/clients/clients.h +++ b/bacula/src/qt-console/clients/clients.h @@ -49,10 +49,10 @@ public: virtual void currentStackItem(); public slots: - void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); + void tableItemChanged(QTableWidgetItem *, QTableWidgetItem *); private slots: - void populateTree(); + void populateTable(); void showJobs(); void consoleStatusClient(); void statusClientWindow(); diff --git a/bacula/src/qt-console/clients/clients.ui b/bacula/src/qt-console/clients/clients.ui index b00486c22f..8f65323d66 100644 --- a/bacula/src/qt-console/clients/clients.ui +++ b/bacula/src/qt-console/clients/clients.ui @@ -5,40 +5,16 @@ 0 0 - 413 - 258 + 492 + 428 Client Tree - - 9 - - - 9 - - - 9 - - - 9 - - - 6 - - - 6 - - - - - 1 - - - + diff --git a/bacula/src/qt-console/fileset/fileset.cpp b/bacula/src/qt-console/fileset/fileset.cpp index 9e6a0334e2..47d6b762d9 100644 --- a/bacula/src/qt-console/fileset/fileset.cpp +++ b/bacula/src/qt-console/fileset/fileset.cpp @@ -48,7 +48,7 @@ FileSet::FileSet() QTreeWidgetItem* thisitem = mainWin->getFromHash(this); thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/system-file-manager.png"))); - /* mp_treeWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */ + /* tableWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */ m_populated = false; m_checkcurwidget = true; m_closeable = false; @@ -68,33 +68,28 @@ FileSet::~FileSet() * The main meat of the class!! The function that querries the director and * creates the widgets with appropriate values. */ -void FileSet::populateTree() +void FileSet::populateTable() { - QTreeWidgetItem *filesetItem, *topItem; + QTableWidgetItem *tableItem; + QBrush blackBrush(Qt::black); if (!m_console->preventInUseConnect()) return; m_checkcurwidget = false; - mp_treeWidget->clear(); + tableWidget->clear(); m_checkcurwidget = true; QStringList headerlist = (QStringList() << tr("FileSet Name") << tr("FileSet Id") << tr("Create Time")); - topItem = new QTreeWidgetItem(mp_treeWidget); - topItem->setText(0, tr("FileSet")); - topItem->setData(0, Qt::UserRole, 0); - topItem->setExpanded(true); - - mp_treeWidget->setColumnCount(headerlist.count()); - mp_treeWidget->setHeaderLabels(headerlist); + tableWidget->setColumnCount(headerlist.count()); + tableWidget->setHorizontalHeaderLabels(headerlist); + tableWidget->setRowCount(m_console->fileset_list.count()); + tableWidget->verticalHeader()->hide(); + int row = 0; foreach(QString filesetName, m_console->fileset_list) { - filesetItem = new QTreeWidgetItem(topItem); - filesetItem->setText(0, filesetName); - filesetItem->setData(0, Qt::UserRole, 1); - filesetItem->setExpanded(true); /* Set up query QString and header QStringList */ QString query(""); @@ -102,7 +97,7 @@ void FileSet::populateTree() " FROM FileSet" " WHERE "; query += " FileSet='" + filesetName + "'"; - query += " ORDER BY FileSet"; + query += " ORDER BY CreateTime DESC LIMIT 1"; QStringList results; if (mainWin->m_sqlDebug) { @@ -110,30 +105,31 @@ void FileSet::populateTree() } if (m_console->sql_cmd(query, results)) { int resultCount = results.count(); - if (resultCount == 1){ + if (resultCount) { QString resultline; QString field; QStringList fieldlist; - /* there will only be one of these */ - foreach (resultline, results) { - fieldlist = resultline.split("\t"); - int index = 0; - /* Iterate through fields in the record */ - foreach (field, fieldlist) { - field = field.trimmed(); /* strip leading & trailing spaces */ - filesetItem->setData(index, Qt::UserRole, 1); - /* Put media fields under the pool tree item */ - filesetItem->setData(index, Qt::UserRole, 1); - filesetItem->setText(index, field); - index++; - } + /* only use the last one */ + resultline = results[resultCount - 1]; + fieldlist = resultline.split("\t"); + int column = 0; + /* Iterate through fields in the record */ + foreach (field, fieldlist) { + field = field.trimmed(); /* strip leading & trailing spaces */ + tableItem = new QTableWidgetItem(field, 1); + tableItem->setFlags(Qt::ItemIsSelectable); + tableItem->setForeground(blackBrush); + tableItem->setData(Qt::UserRole, 1); + tableWidget->setItem(row, column, tableItem); + column++; } } } + row++; } /* Resize the columns */ for (int cnter=0; cnterresizeColumnToContents(cnter); + tableWidget->resizeColumnToContents(cnter); } } @@ -144,7 +140,7 @@ void FileSet::populateTree() void FileSet::PgSeltreeWidgetClicked() { if (!m_populated) { - populateTree(); + populateTable(); createContextMenu(); m_populated = true; } @@ -154,27 +150,25 @@ void FileSet::PgSeltreeWidgetClicked() * Added to set the context menu policy based on currently active treeWidgetItem * signaled by currentItemChanged */ -void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem, - QTreeWidgetItem *previouswidgetitem ) +void FileSet::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem) { /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */ if (m_checkcurwidget) { + int currentRow = currentwidgetitem->row(); + QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0); + m_currentlyselected = currentrowzeroitem->text(); + /* The Previous item */ if (previouswidgetitem) { /* avoid a segfault if first time */ - int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt(); - if (treedepth == 1) { - mp_treeWidget->removeAction(actionStatusFileSetInConsole); - mp_treeWidget->removeAction(actionShowJobs); - } + tableWidget->removeAction(actionStatusFileSetInConsole); + tableWidget->removeAction(actionShowJobs); } - int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt(); - if (treedepth == 1){ + if (m_currentlyselected.length() != 0) { /* set a hold variable to the fileset name in case the context sensitive * menu is used */ - m_currentlyselected=currentwidgetitem->text(0); - mp_treeWidget->addAction(actionStatusFileSetInConsole); - mp_treeWidget->addAction(actionShowJobs); + tableWidget->addAction(actionStatusFileSetInConsole); + tableWidget->addAction(actionShowJobs); } } } @@ -186,14 +180,14 @@ void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem, */ void FileSet::createContextMenu() { - mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); - mp_treeWidget->addAction(actionRefreshFileSet); - connect(mp_treeWidget, SIGNAL( - currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), - this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); + tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + tableWidget->addAction(actionRefreshFileSet); + connect(tableWidget, SIGNAL( + currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)), + this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *))); /* connect to the action specific to this pages class */ connect(actionRefreshFileSet, SIGNAL(triggered()), this, - SLOT(populateTree())); + SLOT(populateTable())); connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this, SLOT(consoleStatusFileSet())); connect(actionShowJobs, SIGNAL(triggered()), this, @@ -217,8 +211,8 @@ void FileSet::consoleStatusFileSet() void FileSet::currentStackItem() { if(!m_populated) { - populateTree(); - /* Create the context menu for the fileset tree */ + populateTable(); + /* Create the context menu for the fileset table */ createContextMenu(); m_populated=true; } diff --git a/bacula/src/qt-console/fileset/fileset.h b/bacula/src/qt-console/fileset/fileset.h index ad13973ee2..ab2ef52c7e 100644 --- a/bacula/src/qt-console/fileset/fileset.h +++ b/bacula/src/qt-console/fileset/fileset.h @@ -49,10 +49,10 @@ public: virtual void currentStackItem(); public slots: - void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); + void tableItemChanged(QTableWidgetItem *, QTableWidgetItem *); private slots: - void populateTree(); + void populateTable(); void consoleStatusFileSet(); void showJobs(); diff --git a/bacula/src/qt-console/fileset/fileset.ui b/bacula/src/qt-console/fileset/fileset.ui index 7b0aaf36ce..eca3b9d0ef 100644 --- a/bacula/src/qt-console/fileset/fileset.ui +++ b/bacula/src/qt-console/fileset/fileset.ui @@ -5,22 +5,16 @@ 0 0 - 318 - 246 + 341 + 277 FileSet Tree - - 9 - - - 6 - - + diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index fa5870fde5..9a2b5ac78d 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -254,11 +254,11 @@ void MainWin::closeEvent(QCloseEvent *event) { m_isClosing = true; writeSettings(); - foreach(Console *console, m_consoleHash){ +/* foreach(Console *console, m_consoleHash){ console->writeSettings(); console->terminate(); console->closeStackPage(); - } + } */ /* close all non console pages, this will call settings in destructors */ while (m_consoleHash.count() < m_pagehash.count()) { foreach(Pages *page, m_pagehash) { -- 2.39.5