##// END OF EJS Templates
Added cpp_utils as subproject and removed few warnings...
Added cpp_utils as subproject and removed few warnings Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1422:a323cf6b7201
r1485:4f6ae2f1ca26
Show More
VariableInspectorWidget.cpp
265 lines | 9.8 KiB | text/x-c | CppLexer
/ gui / src / Variable / VariableInspectorWidget.cpp
Switched to new TS impl but quite broken!...
r1420 #include <DataSource/DataSourceController.h>
Alexandre Leroux
Calls rename dialog when clicking action in the menu
r685 #include <Variable/RenameVariableDialog.h>
All the codebase is modified to build with new Variable Controller...
r1348 #include <Variable/VariableController2.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110 #include <Variable/VariableInspectorWidget.h>
Alexandre Leroux
Adds header in the menu
r290 #include <Variable/VariableMenuHeaderWidget.h>
All the codebase is modified to build with new Variable Controller...
r1348 #include <Variable/VariableModel2.h>
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110
#include <ui_VariableInspectorWidget.h>
Implement of the abort download process
r422 #include <QMouseEvent>
Alexandre Leroux
Affects model to the Variable Widget
r152 #include <QSortFilterProxyModel>
Add implementation of progress bar on variable inspector connected to...
r401 #include <QStyledItemDelegate>
Alexandre Leroux
Adds header in the menu
r290 #include <QWidgetAction>
Alexandre Leroux
Affects model to the Variable Widget
r152
Rename "DragDropHelper" in "DragDropGuiController"
r1075 #include <DragAndDrop/DragDropGuiController.h>
Alexandre Leroux
Affects model to the Variable Widget
r152 #include <SqpApplication.h>
Alexandre Leroux
Pull request fixes
r251 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
Add implementation of progress bar on variable inspector connected to...
r401
Switched to new TS impl but quite broken!...
r1420 class QProgressBarItemDelegate : public QStyledItemDelegate
{
Add implementation of progress bar on variable inspector connected to...
r401
public:
Switched to new TS impl but quite broken!...
r1420 QProgressBarItemDelegate(QObject* parent) : QStyledItemDelegate { parent } {}
Add implementation of progress bar on variable inspector connected to...
r401
Switched to new TS impl but quite broken!...
r1420 void paint(
QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
Add implementation of progress bar on variable inspector connected to...
r401 {
auto data = index.data(Qt::DisplayRole);
Correction MR
r402 auto progressData = index.data(VariableRoles::ProgressRole);
Switched to new TS impl but quite broken!...
r1420 if (data.isValid() && progressData.isValid())
{
Add implementation of progress bar on variable inspector connected to...
r401 auto name = data.value<QString>();
auto progress = progressData.value<double>();
Switched to new TS impl but quite broken!...
r1420 if (progress > 0)
{
Implement of the abort download process
r422 auto cancelButtonWidth = 20;
Switched to new TS impl but quite broken!...
r1420 auto progressBarOption = QStyleOptionProgressBar {};
Implement of the abort download process
r422 auto progressRect = option.rect;
progressRect.setWidth(progressRect.width() - cancelButtonWidth);
progressBarOption.rect = progressRect;
Add implementation of progress bar on variable inspector connected to...
r401 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
r422
Switched to new TS impl but quite broken!...
r1420 QApplication::style()->drawControl(
QStyle::CE_ProgressBar, &progressBarOption, painter);
Implement of the abort download process
r422
// Cancel button
auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
Switched to new TS impl but quite broken!...
r1420 option.rect.height());
auto buttonOption = QStyleOptionButton {};
Implement of the abort download process
r422 buttonOption.rect = buttonRect;
buttonOption.text = "X";
QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
}
Switched to new TS impl but quite broken!...
r1420 else
{
Implement of the abort download process
r422 QStyledItemDelegate::paint(painter, option, index);
Add implementation of progress bar on variable inspector connected to...
r401 }
}
Switched to new TS impl but quite broken!...
r1420 else
{
Add implementation of progress bar on variable inspector connected to...
r401 QStyledItemDelegate::paint(painter, option, index);
}
}
Implement of the abort download process
r422
Switched to new TS impl but quite broken!...
r1420 bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
const QModelIndex& index)
Implement of the abort download process
r422 {
Switched to new TS impl but quite broken!...
r1420 if (event->type() == QEvent::MouseButtonRelease)
{
Implement of the abort download process
r422 auto data = index.data(Qt::DisplayRole);
auto progressData = index.data(VariableRoles::ProgressRole);
Switched to new TS impl but quite broken!...
r1420 if (data.isValid() && progressData.isValid())
{
Implement of the abort download process
r422 auto cancelButtonWidth = 20;
auto progressRect = option.rect;
progressRect.setWidth(progressRect.width() - cancelButtonWidth);
// Cancel button
auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
Switched to new TS impl but quite broken!...
r1420 option.rect.height());
Implement of the abort download process
r422
Switched to new TS impl but quite broken!...
r1420 auto e = (QMouseEvent*)event;
Correction for MR
r447 auto clickX = e->x();
auto clickY = e->y();
Implement of the abort download process
r422
Switched to new TS impl but quite broken!...
r1420 auto x = buttonRect.left(); // the X coordinate
auto y = buttonRect.top(); // the Y coordinate
auto w = buttonRect.width(); // button width
Implement of the abort download process
r422 auto h = buttonRect.height(); // button height
Switched to new TS impl but quite broken!...
r1420 if (clickX > x && clickX < x + w)
{
if (clickY > y && clickY < y + h)
{
// auto& variableModel = sqpApp->variableModel();
// variableModel->abortProgress(index);
Implement of the abort download process
r422 }
Few corrections
r763 return true;
Implement of the abort download process
r422 }
Switched to new TS impl but quite broken!...
r1420 else
{
Few corrections
r763 return QStyledItemDelegate::editorEvent(event, model, option, index);
Implement of the abort download process
r422 }
}
Switched to new TS impl but quite broken!...
r1420 else
{
Few corrections
r763 return QStyledItemDelegate::editorEvent(event, model, option, index);
Implement of the abort download process
r422 }
}
Switched to new TS impl but quite broken!...
r1420 else
{
Few corrections
r763 return QStyledItemDelegate::editorEvent(event, model, option, index);
Implement of the abort download process
r422 }
Few corrections
r763
return QStyledItemDelegate::editorEvent(event, model, option, index);
Implement of the abort download process
r422 }
Add implementation of progress bar on variable inspector connected to...
r401 };
Switched to new TS impl but quite broken!...
r1420 VariableInspectorWidget::VariableInspectorWidget(QWidget* parent)
: QWidget { parent }
, ui { new Ui::VariableInspectorWidget }
, m_ProgressBarItemDelegate { new QProgressBarItemDelegate { this } }
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110 {
ui->setupUi(this);
Alexandre Leroux
Affects model to the Variable Widget
r152
// Sets model for table
Temporal parameters of the selected variables can be updated using the...
r304 // auto sortFilterModel = new QSortFilterProxyModel{this};
// sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
Alexandre Leroux
Affects model to the Variable Widget
r152
Ported Mock plugin to new IDataProvider interface compatible with...
r1350 m_model = new VariableModel2();
All the codebase is modified to build with new Variable Controller...
r1348 ui->tableView->setModel(m_model);
Switched to new TS impl but quite broken!...
r1420 connect(m_model, &VariableModel2::createVariable, [](const QVariantHash& productData) {
Ported Mock plugin to new IDataProvider interface compatible with...
r1350 sqpApp->dataSourceController().requestVariable(productData);
});
auto vc = &(sqpApp->variableController());
connect(vc, &VariableController2::variableAdded, m_model, &VariableModel2::variableAdded);
connect(vc, &VariableController2::variableDeleted, m_model, &VariableModel2::variableDeleted);
connect(m_model, &VariableModel2::asyncChangeRange, vc, &VariableController2::asyncChangeRange);
Alexandre Leroux
Fixes refresh problem in Variable widget
r368
// 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
Switched to new TS impl but quite broken!...
r1420 // connect(m_model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
Ported Mock plugin to new IDataProvider interface compatible with...
r1350 // SLOT(refresh()));
Alexandre Leroux
Fixes refresh problem in Variable widget
r368
Switched to new TS impl but quite broken!...
r1420 // ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
Add implementation of progress bar on variable inspector connected to...
r401 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
Alexandre Leroux
Activates menu on variable widget
r245
Alexandre Leroux
Uses Qt::SizeHintRole to set column width and height
r278 // Fixes column sizes
auto model = ui->tableView->model();
const auto count = model->columnCount();
Switched to new TS impl but quite broken!...
r1420 for (auto i = 0; i < count; ++i)
{
Alexandre Leroux
Uses Qt::SizeHintRole to set column width and height
r278 ui->tableView->setColumnWidth(
i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
}
Alexandre Leroux
Activates multi-selection on variable widget
r286 // Sets selection options
ui->tableView->setSelectionBehavior(QTableView::SelectRows);
ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
Alexandre Leroux
Activates menu on variable widget
r245 // Connection to show a menu when right clicking on the tree
ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableView, &QTableView::customContextMenuRequested, this,
Switched to new TS impl but quite broken!...
r1420 &VariableInspectorWidget::onTableMenuRequested);
Alexandre Leroux
Initializes the variable inspector and adds it to the MainWindow
r110 }
VariableInspectorWidget::~VariableInspectorWidget()
{
delete ui;
}
Alexandre Leroux
Activates menu on variable widget
r245
Switched to new TS impl but quite broken!...
r1420 void VariableInspectorWidget::onTableMenuRequested(const QPoint& pos) noexcept
Alexandre Leroux
Activates menu on variable widget
r245 {
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
Switched to new TS impl but quite broken!...
r1420 auto selectedVariables = QVector<std::shared_ptr<Variable2>> {};
for (const auto& selectedRow : qAsConst(selectedRows))
{
if (auto selectedVariable = this->m_model->variables()[selectedRow.row()])
{
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287 selectedVariables.push_back(selectedVariable);
Alexandre Leroux
Retrieves the current selected variable when clicking on the variable widget
r246 }
}
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287
Switched to new TS impl but quite broken!...
r1420 QMenu tableMenu {};
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287
// 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...
r291 // Adds menu-specific actions
Switched to new TS impl but quite broken!...
r1420 if (!selectedVariables.isEmpty())
{
Alexandre Leroux
Create 'Rename action' in variable menu
r683 tableMenu.addSeparator();
Alexandre Leroux
Adds 'Duplicate' action on variable menu
r706 // 'Rename' and 'Duplicate' actions (only if one variable selected)
Switched to new TS impl but quite broken!...
r1420 if (selectedVariables.size() == 1)
{
Alexandre Leroux
Create 'Rename action' in variable menu
r683 auto selectedVariable = selectedVariables.front();
Switched to new TS impl but quite broken!...
r1420 auto duplicateFun = [varW = std::weak_ptr<Variable2>(selectedVariable)]() {
if (auto var = varW.lock())
{
Alexandre Leroux
Fixes crashes on release when duplicating/renaming a variable
r770 sqpApp->variableController().cloneVariable(var);
}
Alexandre Leroux
Adds 'Duplicate' action on variable menu
r706 };
tableMenu.addAction(tr("Duplicate"), duplicateFun);
Switched to new TS impl but quite broken!...
r1420 auto renameFun = [varW = std::weak_ptr<Variable2>(selectedVariable), this]() {
if (auto var = varW.lock())
{
Alexandre Leroux
Fixes crashes on release when duplicating/renaming a variable
r770 // Generates forbidden names (names associated to existing variables)
All the codebase is modified to build with new Variable Controller...
r1348 auto allVariables = sqpApp->variableController().variables();
Alexandre Leroux
Fixes crashes on release when duplicating/renaming a variable
r770 auto forbiddenNames = QVector<QString>(allVariables.size());
std::transform(allVariables.cbegin(), allVariables.cend(),
Switched to new TS impl but quite broken!...
r1420 forbiddenNames.begin(),
[](const auto& variable) { return variable->name(); });
Alexandre Leroux
Fixes crashes on release when duplicating/renaming a variable
r770
Switched to new TS impl but quite broken!...
r1420 RenameVariableDialog dialog { var->name(), forbiddenNames, this };
if (dialog.exec() == QDialog::Accepted)
{
Alexandre Leroux
Fixes crashes on release when duplicating/renaming a variable
r770 var->setName(dialog.name());
}
Alexandre Leroux
Calls rename dialog when clicking action in the menu
r685 }
Alexandre Leroux
Create 'Rename action' in variable menu
r683 };
tableMenu.addAction(tr("Rename..."), renameFun);
}
Alexandre Leroux
Adds an entry to the menu for deleting a variable...
r291 // 'Delete' action
Alexandre Leroux
Variable deletion (7)...
r336 auto deleteFun = [&selectedVariables]() {
Switched to new TS impl but quite broken!...
r1420 for (const auto& var : selectedVariables)
All the codebase is modified to build with new Variable Controller...
r1348 sqpApp->variableController().deleteVariable(var);
Alexandre Leroux
Adds an entry to the menu for deleting a variable...
r291 };
Switched to new TS impl but quite broken!...
r1420 tableMenu.addAction(QIcon { ":/icones/delete.png" }, tr("Delete"), deleteFun);
Alexandre Leroux
Adds an entry to the menu for deleting a variable...
r291 }
Switched to new TS impl but quite broken!...
r1420 if (!tableMenu.isEmpty())
{
Alexandre Leroux
Adds header in the menu
r290 // Generates menu header (inserted before first action)
auto firstAction = tableMenu.actions().first();
Switched to new TS impl but quite broken!...
r1420 auto headerAction = new QWidgetAction { &tableMenu };
headerAction->setDefaultWidget(
new VariableMenuHeaderWidget { selectedVariables, &tableMenu });
Alexandre Leroux
Adds header in the menu
r290 tableMenu.insertAction(firstAction, headerAction);
Alexandre Leroux
Handles multi-selection when displaying the menu of the variable widget...
r287 // Displays menu
Alexandre Leroux
Fixed menus position
r655 tableMenu.exec(QCursor::pos());
Alexandre Leroux
Pull request fixes
r251 }
Alexandre Leroux
Activates menu on variable widget
r245 }
Alexandre Leroux
Fixes refresh problem in Variable widget
r368
void VariableInspectorWidget::refresh() noexcept
{
ui->tableView->viewport()->update();
}