Mantid
Loading...
Searching...
No Matches
RepoModel.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2013 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 +
7#pragma once
10#include <QAbstractItemModel>
11#include <QDialog>
12#include <QFutureWatcher>
13#include <QList>
14#include <QMessageBox>
15#include <QModelIndex>
16#include <QStringList>
17#include <QVariant>
18#include <QWidget>
19
20namespace MantidQt {
21namespace API {
22
23const QString REMOTEONLY = "REMOTE_ONLY";
24const QString LOCALONLY = "LOCAL_ONLY";
25const QString LOCALCHANGED = "LOCAL_CHANGED";
26const QString REMOTECHANGED = "REMOTE_CHANGED";
27const QString BOTHUNCHANGED = "UPDATED";
28const QString BOTHCHANGED = "CHANGED";
29const QString DOWNLOADST = "DOWNLOADING";
30
68class EXPORT_OPT_MANTIDQT_COMMON RepoModel : public QAbstractItemModel {
69 Q_OBJECT
70
80 class RepoItem {
81 public:
82 // construct the RepoItem passing the script repository path
83 RepoItem(QString label, QString path = "/", RepoItem *parent = nullptr);
84
85 ~RepoItem();
86 // append child to build the directory tree
87 void appendChild(RepoItem *child);
88 // access to the row_th file/folder child of this entry
89 RepoItem *child(int row) const;
91 int row() const;
92 // return the number of files/folders that are children of this entry
93 int childCount() const;
96 const QString &path() const { return keypath; };
99 const QString &label() const { return m_label; };
102 RepoItem *parent() const { return parentItem; };
103
104 private:
108 QString m_label;
110 QString keypath;
113
114 private:
116 const RepoItem &operator=(const RepoItem &);
117 };
118
119public:
121 RepoModel(QObject *parent = nullptr);
123 ~RepoModel() override;
125 QVariant data(const QModelIndex &index, int role) const override;
127 Qt::ItemFlags flags(const QModelIndex &index) const override;
129 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
131 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
133 QModelIndex parent(const QModelIndex &index) const override;
135 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
137 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
139 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
140
141 static const QString &localOnlySt();
142 static const QString &remoteOnlySt();
143 static const QString &localChangedSt();
144 static const QString &remoteChangedSt();
145 static const QString &updatedSt();
146 static const QString &bothChangedSt();
147 static const QString &downloadSt();
148
149 QString fileDescription(const QModelIndex &index);
150 QString filePath(const QModelIndex &index);
151 QString author(const QModelIndex &index);
152
154
155signals:
156 void executingThread(bool /*_t1*/);
157
158private:
160 void setupModelData(RepoItem *parent);
162 const QString &fromStatus(Mantid::API::SCRIPTSTATUS status) const;
168 QString repo_path;
170 RepoItem *getParent(const QString &folder, QList<RepoItem *> &parents);
171
172 Q_DISABLE_COPY(RepoModel)
173
174
175 void handleExceptions(const Mantid::API::ScriptRepoException &ex, const QString &title,
176 bool showWarning = true) const;
177
178 // handle download in thread
179 QFuture<QString> download_threads;
180 QFutureWatcher<QString> download_watcher;
181 QModelIndex download_index;
183 bool isDownloading(const QModelIndex &index) const;
184private slots:
185 void downloadFinished();
186};
187
188} // namespace API
189} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
double value
The value of the point.
Definition FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
A nested class to help RepoModel to implement the QAbstractItemModel.
Definition RepoModel.h:80
QString keypath
the path of the script repository
Definition RepoModel.h:110
const RepoItem & operator=(const RepoItem &)
RepoItem * parent() const
access to the parent of this entry
Definition RepoModel.h:102
const QString & label() const
access to the label provided at construction
Definition RepoModel.h:99
QString m_label
the label of this entry
Definition RepoModel.h:108
const QString & path() const
access to the script repository path
Definition RepoModel.h:96
QList< RepoItem * > childItems
track the list of children for this entry
Definition RepoModel.h:106
RepoItem * parentItem
the parent of this entry
Definition RepoModel.h:112
RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework.
Definition RepoModel.h:68
Mantid::API::ScriptRepository_sptr repo_ptr
pointer to the ScriptRepository
Definition RepoModel.h:166
QModelIndex download_index
Definition RepoModel.h:181
QFutureWatcher< QString > download_watcher
Definition RepoModel.h:180
Mantid::API::ScriptRepository_sptr getRepoPtr()
Definition RepoModel.h:153
QString repo_path
ScriptLocalRepository path, to be able to retrieve the absolute path.
Definition RepoModel.h:168
RepoItem * rootItem
pointer to the RepoItem root
Definition RepoModel.h:164
QFuture< QString > download_threads
Definition RepoModel.h:179
The ScriptRepository class is intended to be used mainly by users, who will want to share and downloa...
const QString LOCALCHANGED
Definition RepoModel.h:25
const QString REMOTECHANGED
Definition RepoModel.h:26
const QString BOTHUNCHANGED
Definition RepoModel.h:27
const QString REMOTEONLY
Definition RepoModel.h:23
const QString LOCALONLY
Definition RepoModel.h:24
const QString BOTHCHANGED
Definition RepoModel.h:28
const QString DOWNLOADST
Definition RepoModel.h:29
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< ScriptRepository > ScriptRepository_sptr
shared pointer to the ScriptRepository base class
SCRIPTSTATUS
Represent the possible states for a given file: