16 #include "Base/Util/SysUtils.h"
32 ItemDelegateForSampleTree(QObject* parent)
38 void paint(QPainter* painter,
const QStyleOptionViewItem& option,
39 const QModelIndex& index)
const override
43 QStyleOptionViewItem options = option;
44 initStyleOption(&options, index);
48 painter->setPen(QPen(Qt::lightGray, 1));
49 painter->drawLine(options.rect.left(), options.rect.bottom(), options.rect.right(),
50 options.rect.bottom());
54 QSize
sizeHint(
const QStyleOptionViewItem& option,
const QModelIndex& index)
const override
57 s.setHeight(std::max(s.height(), 32));
66 , m_document(document)
70 setContextMenuPolicy(Qt::CustomContextMenu);
72 setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
76 setItemDelegate(
new ItemDelegateForSampleTree(
this));
78 connect(selectionModel(), &QItemSelectionModel::currentChanged,
this,
95 "Import sample from Python script.\n The script should contain a function "
96 "returning a valid multi-layer.");
99 if (BaseUtils::System::getenv(
"PYTHONHOME").empty())
103 #ifdef BORNAGAIN_PYTHON
116 auto* menu =
new QMenu(
this);
120 QString title, description;
122 auto icon = QIcon(
":/SampleDesignerToolbox/images/sample_layers2.png");
123 auto* action = menu->addAction(icon, title);
124 action->setToolTip(description);
125 connect(action, &QAction::triggered,
164 QSize s = QListView::sizeHint();
165 s.setWidth(std::max(300, s.width()));
173 scheduleDelayedItemsLayout();
179 setCurrentIndex(newIndex);
184 const QString& description)
187 if (newIndex.isValid()) {
188 setCurrentIndex(newIndex);
195 #ifdef BORNAGAIN_PYTHON
197 if (newIndex.isValid()) {
198 setCurrentIndex(newIndex);
229 auto* removeAction =
new QAction(parent);
230 removeAction->setText(
"Remove");
231 removeAction->setIcon(QIcon(
":/images/delete.svg"));
232 removeAction->setIconText(
"Remove");
233 removeAction->setToolTip(
"Remove this sample");
234 connect(removeAction, &QAction::triggered, [=]() {
removeSample(item); });
244 menu.setToolTipsVisible(
true);
246 if (sampleAtPoint !=
nullptr) {
253 menu.exec(mapToGlobal(pos));
Defines class ApplicationSettings.
Defines class GUI::ExamplesFactory.
Defines class ItemDelegateForHTML.
Defines class MultiLayerItem.
Defines class ProjectDocument.
Defines class SampleListModel.
Defines class SampleListView.
For representing HTML text in an item */.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QVector< MultiLayerItem * > sampleItems() const
Project document class handles all data related to the opened project (sample, job,...
MultiLayerItems * sampleItems()
List model for sample selection (used in the left pane of the layer oriented sample editor)
QModelIndex createSample()
Create a new sample (sample) and return the index of it.
QModelIndex createSampleFromPython()
Create sample from an imported python code.
void removeSample(MultiLayerItem *item)
Remove the given sample. nullptr is allowed.
MultiLayerItem * itemForIndex(const QModelIndex &index) const
QModelIndex createSampleFromExamples(const QString &className, const QString &title, const QString &description)
Create sample from list of built-in examples.
QModelIndex indexForItem(MultiLayerItem *item) const
MultiLayerItem * currentSample()
QAction * m_chooseFromLibraryAction
QAction * chooseFromLibraryAction()
ProjectDocument * m_document
QSize sizeHint() const override
SampleListModel * m_model
QList< QAction * > getOverlayActions(const QModelIndex &index, bool asHover)
void setCurrentSample(MultiLayerItem *sample)
QAction * createRemoveAction(QObject *parent, MultiLayerItem *item)
QAction * importSampleAction()
void currentSampleChanged(MultiLayerItem *current)
void selectFirstSample()
Select first sample, if any sample exists.
QAction * newSampleAction()
void onCurrentChanged(const QModelIndex &index)
void showContextMenu(const QPoint &pos)
QAction * m_newSampleAction
void createSampleFromLibrary(const QString &classname, const QString &title, const QString &description)
void importSampleFromPython()
QAction * m_importSampleAction
void removeSample(MultiLayerItem *item)
SampleListView(QWidget *parent, ProjectDocument *document)
QStringList exampleNames()
The internal example name, e.g. for creation with itemizeSample.
std::tuple< QString, QString > exampleInfo(const QString &name)
Returns human readable name and description.