##// END OF EJS Templates
Add DownloadProgress emission for mock plugin
Add DownloadProgress emission for mock plugin

File last commit:

r388:ff0aebb946e3
r394:ef71cf285dcb
Show More
VariableInspectorWidget.cpp
200 lines | 7.7 KiB | text/x-c | CppLexer
/ gui / src / Variable / VariableInspectorWidget.cpp
Alexandre Leroux
Affects model to the Variable Widget
r143 #include <Variable/VariableController.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105 #include <Variable/VariableInspectorWidget.h>
Alexandre Leroux
Adds header in the menu
r268 #include <Variable/VariableMenuHeaderWidget.h>
Alexandre Leroux
Affects model to the Variable Widget
r143 #include <Variable/VariableModel.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105
#include <ui_VariableInspectorWidget.h>
Implement of the abort download process
r388 #include <QMouseEvent>
Alexandre Leroux
Affects model to the Variable Widget
r143 #include <QSortFilterProxyModel>
Add implementation of progress bar on variable inspector connected to...
r369 #include <QStyledItemDelegate>
Alexandre Leroux
Adds header in the menu
r268 #include <QWidgetAction>
Alexandre Leroux
Affects model to the Variable Widget
r143
#include <SqpApplication.h>
Alexandre Leroux
Pull request fixes
r234 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
Add implementation of progress bar on variable inspector connected to...
r369
class QProgressBarItemDelegate : public QStyledItemDelegate {
public:
Correction MR
r370 QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {}
Add implementation of progress bar on variable inspector connected to...
r369
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
auto data = index.data(Qt::DisplayRole);
Correction MR
r370 auto progressData = index.data(VariableRoles::ProgressRole);
Add implementation of progress bar on variable inspector connected to...
r369 if (data.isValid() && progressData.isValid()) {
auto name = data.value<QString>();
auto progress = progressData.value<double>();
Implement of the abort download process
r388 if (progress > 0) {
auto cancelButtonWidth = 20;
Add implementation of progress bar on variable inspector connected to...
r369 auto progressBarOption = QStyleOptionProgressBar{};
Implement of the abort download process
r388 auto progressRect = option.rect;
progressRect.setWidth(progressRect.width() - cancelButtonWidth);
progressBarOption.rect = progressRect;
Add implementation of progress bar on variable inspector connected to...
r369 progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = progress;
progressBarOption.text
= QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
progressBarOption.textVisible = true;
progressBarOption.textAlignment = Qt::AlignCenter;
Implement of the abort download process
r388
Add implementation of progress bar on variable inspector connected to...
r369 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption,
painter);
Implement of the abort download process
r388
// Cancel button
auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
option.rect.height());
auto buttonOption = QStyleOptionButton{};
buttonOption.rect = buttonRect;
buttonOption.text = "X";
QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
}
else {
QStyledItemDelegate::paint(painter, option, index);
Add implementation of progress bar on variable inspector connected to...
r369 }
}
else {
QStyledItemDelegate::paint(painter, option, index);
}
}
Implement of the abort download process
r388
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
const QModelIndex &index)
{
if (event->type() == QEvent::MouseButtonRelease) {
auto data = index.data(Qt::DisplayRole);
auto progressData = index.data(VariableRoles::ProgressRole);
if (data.isValid() && progressData.isValid()) {
auto cancelButtonWidth = 20;
auto progressRect = option.rect;
progressRect.setWidth(progressRect.width() - cancelButtonWidth);
// Cancel button
auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
option.rect.height());
QMouseEvent *e = (QMouseEvent *)event;
int clickX = e->x();
int clickY = e->y();
auto x = buttonRect.left(); // the X coordinate
auto y = buttonRect.top(); // the Y coordinate
auto w = buttonRect.width(); // button width
auto h = buttonRect.height(); // button height
if (clickX > x && clickX < x + w) {
if (clickY > y && clickY < y + h) {
qCritical(LOG_VariableInspectorWidget()) << tr("editorEvent CLIC");
auto variableModel = sqpApp->variableController().variableModel();
variableModel->abortProgress(index);
}
}
else {
QStyledItemDelegate::editorEvent(event, model, option, index);
}
}
else {
QStyledItemDelegate::editorEvent(event, model, option, index);
}
}
else {
QStyledItemDelegate::editorEvent(event, model, option, index);
}
}
Add implementation of progress bar on variable inspector connected to...
r369 };
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
Add implementation of progress bar on variable inspector connected to...
r369 : QWidget{parent},
ui{new Ui::VariableInspectorWidget},
Correction MR
r370 m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}}
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105 {
ui->setupUi(this);
Alexandre Leroux
Affects model to the Variable Widget
r143
// Sets model for table
Temporal parameters of the selected variables can be updated using the...
r281 // auto sortFilterModel = new QSortFilterProxyModel{this};
// sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
Alexandre Leroux
Affects model to the Variable Widget
r143
Alexandre Leroux
Fixes refresh problem in Variable widget
r340 auto variableModel = sqpApp->variableController().variableModel();
ui->tableView->setModel(variableModel);
// Adds extra signal/slot between view and model, so the view can be updated instantly when
// there is a change of data in the model
connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
SLOT(refresh()));
Temporal parameters of the selected variables can be updated using the...
r281 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
Add implementation of progress bar on variable inspector connected to...
r369 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
Alexandre Leroux
Activates menu on variable widget
r228
Alexandre Leroux
Uses Qt::SizeHintRole to set column width and height
r258 // Fixes column sizes
auto model = ui->tableView->model();
const auto count = model->columnCount();
for (auto i = 0; i < count; ++i) {
ui->tableView->setColumnWidth(
i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
}
Alexandre Leroux
Activates multi-selection on variable widget
r264 // Sets selection options
ui->tableView->setSelectionBehavior(QTableView::SelectRows);
ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
Alexandre Leroux
Activates menu on variable widget
r228 // Connection to show a menu when right clicking on the tree
ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableView, &QTableView::customContextMenuRequested, this,
&VariableInspectorWidget::onTableMenuRequested);
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r105 }
VariableInspectorWidget::~VariableInspectorWidget()
{
delete ui;
}
Alexandre Leroux
Activates menu on variable widget
r228
void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
{
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r265 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
// Gets the model to retrieve the underlying selected variables
auto model = sqpApp->variableController().variableModel();
auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
for (const auto &selectedRow : qAsConst(selectedRows)) {
if (auto selectedVariable = model->variable(selectedRow.row())) {
selectedVariables.push_back(selectedVariable);
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r229 }
}
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r265
QMenu tableMenu{};
// Emits a signal so that potential receivers can populate the menu before displaying it
emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
Alexandre Leroux
Adds an entry to the menu for deleting a variable...
r269 // Adds menu-specific actions
if (!selectedVariables.isEmpty()) {
// 'Delete' action
Alexandre Leroux
Variable deletion (7)...
r310 auto deleteFun = [&selectedVariables]() {
sqpApp->variableController().deleteVariables(selectedVariables);
Alexandre Leroux
Adds an entry to the menu for deleting a variable...
r269 };
tableMenu.addSeparator();
tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
}
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r265 if (!tableMenu.isEmpty()) {
Alexandre Leroux
Adds header in the menu
r268 // Generates menu header (inserted before first action)
auto firstAction = tableMenu.actions().first();
auto headerAction = new QWidgetAction{&tableMenu};
headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
tableMenu.insertAction(firstAction, headerAction);
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r265 // Displays menu
tableMenu.exec(mapToGlobal(pos));
Alexandre Leroux
Pull request fixes
r234 }
Alexandre Leroux
Activates menu on variable widget
r228 }
Alexandre Leroux
Fixes refresh problem in Variable widget
r340
void VariableInspectorWidget::refresh() noexcept
{
ui->tableView->viewport()->update();
}