19 #include <QApplication>
24 : QAbstractItemModel(parent)
27 , m_namesAreEditable(false)
28 , m_enableEmptyHeadlines(true)
71 QList<InstrumentsTreeModel::InstrumentType> result;
115 return instr.first();
125 return createIndex(row, 0,
nullptr);
129 return QModelIndex();
134 if (!hasIndex(row, column,
parent))
135 return QModelIndex();
138 return createIndex(row, column,
nullptr);
142 return createIndex(row, column,
instruments(type)[row]);
144 return QModelIndex();
149 if (!
index.isValid())
150 return QModelIndex();
152 if (
index.internalPointer() ==
nullptr)
153 return QModelIndex();
160 return QModelIndex();
192 title =
"DepthProbe";
195 case Qt::DisplayRole:
199 QFont f(QApplication::font());
200 f.setPointSize(f.pointSize() * 1.5);
205 case Qt::SizeHintRole: {
206 QFont f(QApplication::font());
207 f.setPointSize(f.pointSize() * 1.5);
209 QSize s = QFontMetrics(f).boundingRect(title).size();
210 return QSize(s.width() * 2, s.height() * 2);
213 case Qt::TextAlignmentRole:
214 return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
216 case Qt::BackgroundRole:
219 case Qt::ForegroundRole:
229 if (role == Qt::ToolTipRole)
230 return item->description();
232 if (role == Qt::DisplayRole)
233 return item->instrumentName();
235 if (role == Qt::EditRole)
236 return item->instrumentName();
238 if (role == Qt::TextAlignmentRole)
239 return QVariant(Qt::AlignLeft | Qt::AlignTop);
241 if (role == Qt::DecorationRole)
244 return QIcon(
":/images/gisas_instrument.svg");
246 return QIcon(
":/images/offspec_instrument.svg");
248 return QIcon(
":/images/specular_instrument.svg");
250 return QIcon(
":/images/depth_instrument.svg");
261 return Qt::NoItemFlags;
263 auto f = QAbstractItemModel::flags(
index);
264 f |= Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
267 f |= Qt::ItemIsEditable;
274 if (!
index.isValid())
277 if (role == Qt::EditRole &&
index.column() == 0) {
283 if (role == Qt::ToolTipRole &&
index.column() == 0) {
294 if (!
index.isValid())
303 return QModelIndex();
306 if (
auto row =
instruments(type).indexOf(item); row >= 0)
307 return createIndex(row, 0, item);
309 return QModelIndex();
315 if (!
index.isValid())
325 if (!
index.isValid())
328 return index.internalPointer() ==
nullptr;
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class InstrumentCollection.
Defines class InstrumentItem and all its children.
Defines class InstrumentsTreeModel.
const Palette & styleSheetPalette() const
QVector< InstrumentItem * > instrumentItems(const std::function< bool(const InstrumentItem *)> &accept) const
void removeInstrument(InstrumentItem *instrument)
Abstract base class for instrument-specific item classes.
void setDescription(const QString &description)
void setInstrumentName(const QString &instrumentName)
Qt::ItemFlags flags(const QModelIndex &index) const override
void enableEmptyHeadlines(bool b)
VisibleInstrumentTypes m_visibleTypes
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void refreshAfterModelChange()
static InstrumentType instrumentType(InstrumentItem *item)
QModelIndex parent(const QModelIndex &index) const override
QModelIndex indexForItem(InstrumentItem *item) const
InstrumentItem * topMostItem() const
The topmost visible item. Can be null of course.
bool m_enableEmptyHeadlines
InstrumentCollection * m_model
QList< InstrumentType > visibleTypes() const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex indexOfHeadline(InstrumentType type) const
InstrumentItem * itemForIndex(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
InstrumentsTreeModel(QObject *parent, InstrumentCollection *model)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool isHeadline(const QModelIndex &index) const
QVector< InstrumentItem * > instruments(InstrumentType type) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setTypeEnabled(InstrumentType type, bool b)
void removeItem(InstrumentItem *item)
QColor headlineBackground