From f3a0b4d09379e63a26ec410088617fe20d5cd27f Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Thu, 20 Mar 2014 18:47:48 +0100 Subject: - added tab view - added filter box --- src/dialog.cpp | 172 +++++++++++++++++++++++++++++++-------- src/dialog.h | 16 +++- src/globals.h | 4 +- src/main.cpp | 4 +- src/sessiontreemodel.cpp | 73 ++++------------- src/sessiontreemodel.h | 7 +- src/ui/dialog.ui | 206 +++++++++++++++++++++++++++++++++++------------ src/vsession.cpp | 4 + 8 files changed, 333 insertions(+), 153 deletions(-) diff --git a/src/dialog.cpp b/src/dialog.cpp index 3adfef6..798d6be 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -16,7 +16,10 @@ Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { - model_ = new SessionTreeModel(parent); + model_[0] = new SessionTreeModel(parent); + model_[1] = new SessionTreeModel(parent); + model_[2] = new SessionTreeModel(parent); + ui->setupUi(this); pvsSettings_ = NULL; @@ -29,7 +32,10 @@ Dialog::Dialog(QWidget *parent) connect(centerTimer_, SIGNAL(timeout()), this, SLOT(onCenterTimer())); centerTimer_->start(1000); - ui->treeView->setModel(model_); + activeTab = 0; + ui->tabButtonLocal->setChecked(true); + + setListModel(model_[0]); QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); @@ -37,7 +43,9 @@ Dialog::Dialog(QWidget *parent) Dialog::~Dialog() { delete ui; - delete model_; + delete model_[0]; + delete model_[1]; + delete model_[2]; } void Dialog::changeEvent(QEvent *e) { @@ -83,19 +91,25 @@ void Dialog::on_treeView_activated(QModelIndex index) { } } -void Dialog::addItems(const QList& entries, const QString& section) { - this->model_->addItems(entries, section); - ui->treeView->expandAll(); +void Dialog::addItems(const QList& entries, int tab) { + if (tab < 0 || tab > 2) { + return; + } + this->model_[tab]->addItems(entries); } -void Dialog::addLabelItem(const QString& label, const QString& section) { - this->model_->addLabelItem(label, section); - ui->treeView->expandAll(); +void Dialog::addLabelItem(const QString& label, int tab) { + if (tab < 0 || tab > 2) { + return; + } + this->model_[tab]->addLabelItem(label); } -void Dialog::removeItem(const QString& name, const QString& section) { - this->model_->removeItem(name, section); - ui->treeView->expandAll(); +void Dialog::removeItem(const QString& name, int tab) { + if (tab < 0 || tab > 2) { + return; + } + this->model_[tab]->removeItem(name); } void Dialog::on_pushButtonAbort_clicked() { @@ -168,23 +182,25 @@ void Dialog::on_comboBoxOthers_currentIndexChanged(int index) { bool Dialog::selectSession(const QString& name) { QModelIndex root(ui->treeView->rootIndex()); - for (int i = 0; i < model_->rowCount(root); ++i) { - QModelIndex section = model_->index(i, 0, root); - if (!section.isValid()) break; - for (int row = 0; row < model_->rowCount(section); ++row) { - QModelIndex index = model_->index(row, 0, section); - if (!index.isValid()) break; - - SessionTreeItem* item = - static_cast(index.internalPointer()); - const Session* s(item->session()); - if (!s) continue; - if (s->shortDescription() == name) { - ui->treeView->selectionModel() - ->setCurrentIndex(index, QItemSelectionModel::Select); - return true; - } - } + for (int k = 0; k <= 2; ++k) { + for (int i = 0; i < model_[k]->rowCount(root); ++i) { + QModelIndex section = model_[k]->index(i, 0, root); + if (!section.isValid()) break; + for (int row = 0; row < model_[k]->rowCount(section); ++row) { + QModelIndex index = model_[k]->index(row, 0, section); + if (!index.isValid()) break; + + SessionTreeItem* item = + static_cast(index.internalPointer()); + const Session* s(item->session()); + if (!s) continue; + if (s->shortDescription() == name) { + ui->treeView->selectionModel() + ->setCurrentIndex(index, QItemSelectionModel::Select); + return true; + } + } + } } return false; } @@ -273,8 +289,8 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { if (debugMode) { qDebug() << "Cannot read backup file " << xml_backup_filename << " either"; } - this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."),QCoreApplication::instance()->translate("Dialog", "Virtual Sessions")); - this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions")); + this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1); + this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), 1); return; } @@ -288,7 +304,7 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { qSort(sessions.begin(), sessions.end(), myLessThan); - this->addItems(sessions, QCoreApplication::instance()->translate("Dialog", "Virtual Sessions")); + this->addItems(sessions, 1); } else { @@ -312,12 +328,12 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { const QList sessions = VSession::readXmlFile(xml_filename); - this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."),QCoreApplication::instance()->translate("Dialog", "Virtual Sessions")); + this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1); if (!sessions.isEmpty()) { - this->addItems(sessions, QCoreApplication::instance()->translate("Dialog", "Virtual Sessions")); + this->addItems(sessions, 1); } else { - this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions")); + this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1); } } @@ -327,12 +343,16 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI const Session* s(item->session()); if (!s) { + if (debugMode) { + qDebug() << "invalid selection"; + } // no valid session has been selected, do nothing return; } if (s->type() == Session::VSESSION) { const VSession* vs = (VSession*) s; + ui->label_name->setText(vs->getAttribute("short_description", "param")); ui->label_name->setToolTip(vs->getAttribute("short_description", "param")); @@ -351,3 +371,85 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI ui->textBrowser->setPlainText(QCoreApplication::instance()->translate("Dialog", "Running on this machine.")); } } + +void Dialog::on_tabButtonLocal_clicked() { + onTabButtonChanged(0); +} + +void Dialog::on_tabButtonMyClasses_clicked() { + onTabButtonChanged(1); +} + +void Dialog::on_tabButtonAllClasses_clicked() { + onTabButtonChanged(2); +} + +void Dialog::onTabButtonChanged(int tab) { + if (tab < 0 || tab > 2) { + // no valid button + return; + } + + // give focus to treeView + ui->treeView->setFocus(); + + // one button needs to be enabled + if (this->activeTab == tab) { + switch (tab) { + case 0: ui->tabButtonLocal->setChecked(true); break; + case 1: ui->tabButtonMyClasses->setChecked(true); break; + case 2: ui->tabButtonAllClasses->setChecked(true); break; + } + } + + + this->activeTab = tab; + + // when button was pressed disable the other buttons + if (tab == 0) { + ui->tabButtonMyClasses->setChecked(false); + ui->tabButtonAllClasses->setChecked(false); + } else if (tab == 1) { + ui->tabButtonLocal->setChecked(false); + ui->tabButtonAllClasses->setChecked(false); + } else { + ui->tabButtonLocal->setChecked(false); + ui->tabButtonMyClasses->setChecked(false); + } + + // load the new list + setListModel(model_[tab]); + + // reconnect the treeModel + QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), + this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); +} + +void Dialog::on_filterEdit_textChanged() { + SessionTreeModel *newModel; + + // filter the current model + if (ui->filterEdit->text() != "" && ui->filterEdit->text().length() > 2) { + newModel = new SessionTreeModel(this); + newModel->addItems(this->model_[activeTab]->lookForItem(ui->filterEdit->text())); + } else { + newModel = model_[activeTab]; + } + + setListModel(newModel); + if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) { + ui->treeView->selectionModel()->clearSelection(); + ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); + } + // reconnect the treeModel + QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), + this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); +} + +void Dialog::setListModel(QAbstractItemModel *model) { + if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) { + } else { + ui->treeView->model()->deleteLater(); + } + ui->treeView->setModel(model); +} diff --git a/src/dialog.h b/src/dialog.h index af795a9..aa2fa30 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -19,9 +19,9 @@ class Dialog : public QDialog { public: explicit Dialog(QWidget *parent = 0); ~Dialog(); - void addItems(const QList&, const QString& section); - void addLabelItem(const QString& label, const QString& section); - void removeItem(const QString& name, const QString& section); + void addItems(const QList&, int tab); + void addLabelItem(const QString& label, int tab); + void removeItem(const QString& name, int tab); bool selectSession(const QString& name); void selectPreviousSession(); void showSettingsPVS(); @@ -33,13 +33,17 @@ class Dialog : public QDialog { private: Ui::Dialog *ui; - SessionTreeModel *model_; + SessionTreeModel *model_[3]; QSettings *pvsSettings_; QPoint oldCenter_; QTimer *centerTimer_; QString autoStartEntry_; + int activeTab; void readPVSSettings(); void writePVSSettings(); + void onTabButtonChanged(int tab); + void configClearButton(); + void setListModel(QAbstractItemModel *model); private slots: void on_comboBoxOthers_currentIndexChanged(int index); @@ -47,6 +51,10 @@ class Dialog : public QDialog { void on_pushButtonStart_clicked(); void on_pushButtonAbort_clicked(); void on_treeView_activated(QModelIndex index); + void on_tabButtonLocal_clicked(); + void on_tabButtonMyClasses_clicked(); + void on_tabButtonAllClasses_clicked(); + void on_filterEdit_textChanged(); void treeView_selectionChanged(const QModelIndex& current, const QModelIndex&); void onCenterTimer(); diff --git a/src/globals.h b/src/globals.h index 8215c19..0b8739c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -13,8 +13,8 @@ #define VMCHOOSER_SESSION_START_SCRIPT "/opt/openslx/vmchooser/sessionstart" -#define VMCHOOSER_DEFAULT_WIDTH 800 -#define VMCHOOSER_DEFAULT_HEIGHT 600 +#define VMCHOOSER_DEFAULT_WIDTH 1024 +#define VMCHOOSER_DEFAULT_HEIGHT 768 #define OPENSLXCONFIG "/opt/openslx/config" diff --git a/src/main.cpp b/src/main.cpp index 9acc10e..86deb3f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -197,11 +197,11 @@ int main(int argc, char *argv[]) { if (xsessions.size()) { qSort(xsessions.begin(), xsessions.end(), myLessThan); - w.addItems(xsessions, a.translate("Dialog", "X Sessions")); + w.addItems(xsessions, 0); } if (!vSessionUrl.isEmpty()) { - w.addLabelItem(a.translate("Dialog", "Loading..."), a.translate("Dialog", "Virtual Sessions")); + w.addLabelItem(a.translate("Dialog", "Loading..."), 1); } QSettings SLXsettings(OPENSLXCONFIG, QSettings::NativeFormat); diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp index 177049d..2078aaa 100644 --- a/src/sessiontreemodel.cpp +++ b/src/sessiontreemodel.cpp @@ -150,77 +150,38 @@ QModelIndex SessionTreeModel::parent(const QModelIndex &index) const { return createIndex(parentItem->row(), 0, parentItem); } -void SessionTreeModel::addItems(const QList& sessions, - const QString& section) { - SessionTreeItem* parentItem; - - bool sectionExists = false; - - for (int i = 0; i < root_->childCount(); ++i) { - SessionTreeItem* item = root_->child(i); - if (item->text() == section) { - parentItem = item; - sectionExists = true; - break; - } - } - - if (!sectionExists) { - parentItem = new SessionTreeItem(section, root_); - root_->appendChild(parentItem); - } - +void SessionTreeModel::addItems(const QList& sessions) { foreach (Session* s, sessions) { - parentItem->appendChild(new SessionTreeItem(s, parentItem)); + root_->appendChild(new SessionTreeItem(s, root_)); } } -void SessionTreeModel::addLabelItem(const QString& label, const QString& section) { - SessionTreeItem* parentItem; - - bool sectionExists = false; - - for (int i = 0; i < root_->childCount(); ++i) { - SessionTreeItem* item = root_->child(i); - if (item->text() == section) { - parentItem = item; - sectionExists = true; - break; - } - } - - if (!sectionExists) { - parentItem = new SessionTreeItem(section, root_); - root_->appendChild(parentItem); - } - - parentItem->appendChild(new SessionTreeItem(label, parentItem)); +void SessionTreeModel::addLabelItem(const QString& label) { + root_->appendChild(new SessionTreeItem(label, root_)); } -void SessionTreeModel::removeItem(const QString& name, const QString& section) { - SessionTreeItem* parentItem; - - bool sectionExists = false; - +void SessionTreeModel::removeItem(const QString& name) { for (int i = 0; i < root_->childCount(); ++i) { SessionTreeItem* item = root_->child(i); - if (item->text() == section) { - parentItem = item; - sectionExists = true; - break; + if (item->text() == name) { + root_->removeChild(item); } } +} + +QList SessionTreeModel::lookForItem(const QString& label) { + QList result; - if (sectionExists) { - for (int i = 0; i < parentItem->childCount(); ++i) { - SessionTreeItem* item = parentItem->child(i); - if (item->text() == name) { - parentItem->removeChild(item); - } + for (int i = 0; i < root_->childCount(); ++i) { + SessionTreeItem* item = root_->child(i); + if (item->session()->shortDescription().contains(label, Qt::CaseInsensitive)) { + result.append(const_cast(item->session())); } } + return result; } void SessionTreeModel::updateView() { emit layoutChanged(); } + diff --git a/src/sessiontreemodel.h b/src/sessiontreemodel.h index b8fd7ab..9079c59 100644 --- a/src/sessiontreemodel.h +++ b/src/sessiontreemodel.h @@ -27,9 +27,10 @@ class SessionTreeModel : public QAbstractItemModel { int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; - void addItems(const QList& sessions, const QString& section); - void addLabelItem(const QString& label, const QString& section); - void removeItem(const QString& name, const QString& section); + void addItems(const QList& sessions); + void addLabelItem(const QString& label); + void removeItem(const QString& name); + QList lookForItem(const QString& label); void updateView(); diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index 6f8ce05..bd59605 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -102,55 +102,139 @@ margin-bottom:0px;} + + 3 + + + 3 + - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - #treeView {border-top:1px solid #999; -border-bottom:1px solid #999;} - - - - QFrame::HLine - - - QFrame::Plain - - + + 0 - - - 32 - 32 - - - - 12 + + 3 - - true - - - 23 - - + + + + 0 + + + + + Local + + + true + + + + + + + My Classes + + + true + + + + + + + All Classes + + + true + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + #treeView { +border:1px solid #999; +} + + + + QFrame::HLine + + + QFrame::Plain + + + 0 + + + + 32 + 32 + + + + 12 + + + true + + + 23 + + + + + + + 5 + + + 4 + + + + + Filter: + + + + + + + + 0 + 0 + + + + + + + + + true + 0 @@ -174,17 +258,6 @@ border-bottom:1px solid #999;} - - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Click on an item on the left side for more infos.</p></body></html> - - - @@ -281,6 +354,17 @@ p, li { white-space: pre-wrap; } + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Ubuntu'; font-size:11pt;">Click on an item on the left side for more infos.</span></p></body></html> + + + @@ -391,6 +475,13 @@ p, li { white-space: pre-wrap; } 9 + + + + Report Bug + + + @@ -404,6 +495,19 @@ p, li { white-space: pre-wrap; } + + + + Help + + + false + + + false + + + diff --git a/src/vsession.cpp b/src/vsession.cpp index ebe369a..f8512fc 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -262,6 +262,10 @@ void VSession::mergePoolXml() { } bool VSession::run() const { + if (debugMode) { + qDebug() << "Sarting session " << this->getAttribute("short_description", "param") << " ..."; + } + QString command = getAttribute("command"); if (!command.isEmpty()) { return QProcess::startDetached(command); -- cgit v1.2.3-55-g7522