1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/**
*
* This file is part of Tulip (https://tulip.labri.fr)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#include "PanelSelectionWizard.h"
#include "ui_PanelSelectionWizard.h"
#include "../../../utils/PluginNames.h"
#include <QAbstractButton>
#include <QMessageBox>
#include <QMouseEvent>
#include <tulip/View.h>
#include <tulip/TulipMetaTypes.h>
#include <tulip/GraphHierarchiesModel.h>
#include <tulip/PluginModel.h>
using namespace tlp;
using namespace std;
PanelSelectionWizard::PanelSelectionWizard(GraphHierarchiesModel *model, QWidget *parent)
: QWizard(parent), _ui(new Ui::PanelSelectionWizard), _model(model), _view(nullptr) {
#if !defined(__LINUX)
setWizardStyle(QWizard::ClassicStyle);
#endif
_ui->setupUi(this);
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(pageChanged(int)));
_ui->graphCombo->setModel(_model);
_ui->graphCombo->selectIndex(_model->indexOf(_model->currentGraph()));
_ui->panelList->setModel(
new SimplePluginListModel(PluginLister::availablePlugins<tlp::View>(), _ui->panelList));
connect(_ui->panelList->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this,
SLOT(panelSelected(QModelIndex)));
connect(_ui->panelList, SIGNAL(doubleClicked(QModelIndex)), button(QWizard::FinishButton),
SLOT(click()));
_ui->panelList->setCurrentIndex(_ui->panelList->model()->index(0, 0));
}
PanelSelectionWizard::~PanelSelectionWizard() {
delete _ui;
}
void PanelSelectionWizard::panelSelected(const QModelIndex &index) {
_currentItem = index.data().toString();
_ui->panelDescription->setHtml(
PluginLister::pluginInformation(QStringToTlpString(_currentItem)).info().c_str());
// NexButton is temporarily hidden
// QWizard::HaveNextButtonOnLastPage has been removed
// from options property in PanelSelectionWizard.ui
button(QWizard::NextButton)->setEnabled(true);
}
tlp::Graph *PanelSelectionWizard::graph() const {
return _model->data(_ui->graphCombo->selectedIndex(), TulipModel::GraphRole)
.value<tlp::Graph *>();
}
void PanelSelectionWizard::setSelectedGraph(tlp::Graph *g) {
_ui->graphCombo->selectIndex(_model->indexOf(g));
}
tlp::View *PanelSelectionWizard::panel() const {
return _view;
}
void PanelSelectionWizard::createView() {
if (QStringToTlpString(_currentItem) == ViewName::GeographicViewName && !checkInternetAccess()) {
QMessageBox::warning(
nullptr, QString("No internet access"),
QString("There seems to be no internet access.<br/>Check your network configuration."));
return;
}
_view = PluginLister::getPluginObject<View>(QStringToTlpString(_currentItem));
_view->setupUi();
_view->setGraph(graph());
_view->setState(DataSet());
}
void PanelSelectionWizard::clearView() {
delete _view;
_view = nullptr;
for (auto id : pageIds()) {
if (id == startId() || id == currentId())
continue;
QWizardPage *p = page(id);
removePage(id);
delete p;
}
_ui->placeHolder = new QWizardPage();
addPage(_ui->placeHolder);
}
void PanelSelectionWizard::done(int result) {
if (result == QDialog::Accepted && _view == nullptr) {
createView();
} else if (result == QDialog::Rejected) {
clearView();
}
QWizard::done(result);
}
void PanelSelectionWizard::pageChanged(int id) {
// temporarily display OK instead of Finish
setButtonText(QWizard::FinishButton, "OK");
if (id == startId()) {
clearView();
button(QWizard::FinishButton)->setEnabled(true);
}
if (page(id) == _ui->placeHolder) {
createView();
bool inPlaceHolder = true;
for (auto w : _view->configurationWidgets()) {
QWizardPage *p;
if (inPlaceHolder) {
p = _ui->placeHolder;
inPlaceHolder = false;
} else {
p = new QWizardPage;
addPage(p);
}
p->setLayout(new QVBoxLayout);
p->layout()->addWidget(w);
}
}
// NexButton is temporarily hidden
// QWizard::HaveNextButtonOnLastPage has been removed
// from options property in PanelSelectionWizard.ui
button(QWizard::NextButton)->setEnabled(nextId() != -1);
}
|