19 #include <QApplication>
24 : QAbstractItemModel(parent)
26 , m_visibleRanks({1, 2})
28 for (
auto rank : m_visibleRanks)
29 m_items[rank - 1] = model->realDataItems(rank);
31 updateSubscriptions();
34 Qt::UniqueConnection);
55 if (!
m_items[rank - 1].isEmpty()) {
85 const int rowOfItem =
m_items[rank - 1].indexOf(item);
87 m_items[rank - 1].removeAll(item);
129 return QModelIndex();
132 return createIndex(0, 0,
nullptr);
136 return createIndex(has1D ? 1 : 0, 0,
nullptr);
139 return QModelIndex();
144 if (!hasIndex(row, column,
parent))
145 return QModelIndex();
148 return createIndex(row, column,
nullptr);
152 return createIndex(row, column,
m_items[rank - 1][row]);
154 return QModelIndex();
159 if (!
index.isValid())
160 return QModelIndex();
162 if (
index.internalPointer() ==
nullptr)
163 return QModelIndex();
184 return m_items[rank - 1].size();
197 case Qt::DisplayRole:
201 QFont f(QApplication::font());
202 f.setPointSize(f.pointSize() * 1.5);
207 case Qt::SizeHintRole: {
208 QFont f(QApplication::font());
209 f.setPointSize(f.pointSize() * 1.5);
211 QSize s = QFontMetrics(f).boundingRect(title).size();
212 return QSize(s.width() * 2, s.height() * 2);
215 case Qt::TextAlignmentRole:
216 return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
218 case Qt::BackgroundRole:
221 case Qt::ForegroundRole:
231 if (role == Qt::ToolTipRole)
234 if (role == Qt::DecorationRole) {
235 if (item->isSpecularData())
236 return item->hasImportErrors() ? QIcon(
":/images/warning_16x16.png")
237 : QIcon(
":/images/1D_OK.png");
238 return QIcon(
":/images/2D_OK.png");
241 if (role == Qt::DisplayRole) {
242 const auto numErrors =
243 (item->dataLoader() !=
nullptr) ? item->dataLoader()->numErrors() : 0;
246 return item->dataName();
248 return item->dataName() +
" (1 parser warning)";
249 return item->dataName() + QString(
" (%1 parser warnings)").arg(numErrors);
252 if (role == Qt::EditRole)
253 return item->dataName();
261 return Qt::NoItemFlags;
263 auto f = QAbstractItemModel::flags(
index);
264 f |= Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
266 if (
index.column() == 0)
267 f |= Qt::ItemIsEditable;
274 if (!
index.isValid())
277 if (role == Qt::EditRole &&
index.column() == 0) {
288 if (!
index.isValid())
297 return QModelIndex();
302 return createIndex(
index, 0, item);
304 return QModelIndex();
309 if (!
index.isValid())
312 return index.internalPointer() ==
nullptr;
ApplicationSettings * appSettings
global pointer to the instance
Defines class ApplicationSettings.
Defines class RealDataItem.
Defines class RealDataModel.
Defines class RealDataTreeModel.
const Palette & styleSheetPalette() const
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
bool isSpecularData() const
AbstractDataLoader * dataLoader() const
void setDataName(const QString &name)
void importContentsProcessed()
The RealDataModel class is a model to store all imported RealDataItem's.
QVector< RealDataItem * > realDataItems() const
RealDataItem * insertDataItem(int rank)
void remove(RealDataItem *item)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent(const QModelIndex &index) const override
QModelIndex indexForItem(RealDataItem *item) const
QSet< int > m_visibleRanks
Qt::ItemFlags flags(const QModelIndex &index) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void refreshAfterModelChange()
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
RealDataItem * insertIntensityDataItem()
bool isHeadline(const QModelIndex &index) const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
RealDataTreeModel(QObject *parent, RealDataModel *model)
RealDataItem * topMostItem() const
The topmost visible item. Can be null of course.
RealDataItem * insertSpecularDataItem()
RealDataItem * itemForIndex(const QModelIndex &index) const
QVector< RealDataItem * > m_items[2]
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void onContentsProcessed(RealDataItem *item)
void updateSubscriptions()
void removeItem(RealDataItem *item)
void setVisibleRanks(QSet< int > visibleRanks)
QModelIndex indexOfHeadline(int rank) const
RealDataItem * insertDataItem(int rank)
QColor headlineBackground