Mantid
Loading...
Searching...
No Matches
CellDelegate.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include <QKeyEvent>
11#include <QPainter>
12
14
15CellDelegate::CellDelegate(QObject *parent, QTreeView const &view, FilteredTreeModel const &filteredModel,
16 QStandardItemModel const &mainModel)
17 : QStyledItemDelegate(parent), m_view(view), m_filteredModel(filteredModel), m_mainModel(mainModel) {}
18
19void CellDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
20 QStyledItemDelegate::paint(painter, option, index);
21 painter->save();
22
24 auto borderColor = getBorderColor(*item);
25 auto borderThickness = getBorderThickness(*item);
26
27 auto isCurrentCell = m_view.currentIndex() == index;
28 auto pen = ([isCurrentCell, &borderColor, item]() -> QPen {
29 if (isCurrentCell & item->isEditable())
30 return QPen(Qt::black);
31 else
32 return QPen(borderColor);
33 })();
34 pen.setWidth(isCurrentCell ? 2 : borderThickness);
35
36 painter->setPen(pen);
37 painter->drawRect(option.rect.adjusted(1, 1, -1, -1));
38 painter->restore();
39}
40} // namespace MantidQt::MantidWidgets::Batch
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
QStandardItemModel const & m_mainModel
Definition: CellDelegate.h:29
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
CellDelegate(QObject *parent, QTreeView const &view, FilteredTreeModel const &filterModel, QStandardItemModel const &mainModel)
FilteredTreeModel const & m_filteredModel
Definition: CellDelegate.h:28
EXPORT_OPT_MANTIDQT_COMMON QStandardItem * modelItemFromIndex(QStandardItemModel &model, QModelIndexForMainModel const &index)
QColor getBorderColor(QStandardItem const &item)
QModelIndexForMainModel fromMainModel(QModelIndex const &mainModelIndex, QAbstractItemModel const &model)
int getBorderThickness(QStandardItem const &item)