16 #include "Base/Util/Assert.h"
25 #include "Sample/Multilayer/MultiLayer.h"
29 : QAbstractListModel(parent)
30 , m_sampleItems(model)
46 if (role == Qt::ToolTipRole)
47 return item->description();
49 if (role == Qt::DisplayRole) {
50 auto descr = item->description();
51 if (!descr.isEmpty()) {
52 descr.prepend(
"<br><br>");
53 const int maxDescriptionLines = 8;
54 while (descr.count(
"\n") >= maxDescriptionLines) {
55 descr.truncate(descr.lastIndexOf(
"\n"));
58 descr.replace(
"\n",
"<br>");
60 return "<b>" + item->sampleName() +
"</b>" + descr;
63 if (role == Qt::EditRole)
64 return item->sampleName();
71 auto f = QAbstractItemModel::flags(index);
72 f |= Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
82 if (role == Qt::EditRole && index.column() == 0) {
84 emit dataChanged(index, index);
88 if (role == Qt::ToolTipRole && index.column() == 0) {
90 emit dataChanged(index, index);
108 return index(row, 0);
110 return QModelIndex();
116 if (!index.isValid())
119 beginRemoveRows(index.parent(), index.row(), index.row());
129 beginInsertRows(QModelIndex(), row, row);
132 sample_item->addStandardMaterials();
138 const QString& title,
139 const QString& description)
147 sample->setDescription(description);
150 beginInsertRows(QModelIndex(), row, row);
154 }
catch (
const std::exception& ex) {
155 QString message(
"Exception thrown while trying to build GUI models.\n");
156 QString details = QString::fromStdString(ex.what());
163 #ifdef BORNAGAIN_PYTHON
175 sampleItem->setDescription(
"Imported from python code");
178 beginInsertRows(QModelIndex(), row, row);
Defines class DetailedMessageBox.
Defines class GUI::ExamplesFactory.
Defines class GUISampleBuilder.
Defines class MultiLayerItem.
Defines class MultiLayerItems.
Implements class PyImportAssistant.
Defines class SampleListModel.
Defines functions from namespace GUI::Util::String.
A dialog similar to standard QMessageBox intended for detailed warning messages. On the contrary to Q...
void setDescription(const QString &description)
void setSampleName(const QString &name)
Main model to hold sample items.
void removeMultiLayer(MultiLayerItem *sample)
QStringList sampleNames() const
QVector< MultiLayerItem * > sampleItems() const
MultiLayerItem * addMultiLayer()
Adds a sample and returns the new item.
QModelIndex createSample()
Create a new sample (sample) and return the index of it.
Qt::ItemFlags flags(const QModelIndex &index) const override
SampleListModel(QObject *parent, MultiLayerItems *model)
QModelIndex createSampleFromPython()
Create sample from an imported python code.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void removeSample(MultiLayerItem *item)
Remove the given sample. nullptr is allowed.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
MultiLayerItem * itemForIndex(const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role) override
MultiLayerItems * m_sampleItems
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 * itemizeSample(const QString &name)
Create a sample item of the built-in example with the given internal name.
static QMainWindow * mainWindow
QString suggestName(const QStringList &existingNames, const QString &name)
Returns a name suggestion based on the given name.
MultiLayerItem * itemizeSample(const MultiLayer &sample)
Populates GUI sample with domain sample.
std::unique_ptr< MultiLayer > importMultiLayer()
Show select-file dialog, try to import via python, return created sample.