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
20class QLineEdit;
21class QCheckBox;
22class QTextEdit;
23
24namespace MantidQt {
25namespace API {
26
27const QString REMOTEONLY = "REMOTE_ONLY";
28const QString LOCALONLY = "LOCAL_ONLY";
29const QString LOCALCHANGED = "LOCAL_CHANGED";
30const QString REMOTECHANGED = "REMOTE_CHANGED";
31const QString BOTHUNCHANGED = "UPDATED";
32const QString BOTHCHANGED = "CHANGED";
33const QString UPLOADST = "UPLOADING";
34const QString DOWNLOADST = "DOWNLOADING";
35const QString PROTECTEDENTRY = "protected";
36const QString DELETABLEENTRY = "deletable";
37
75class EXPORT_OPT_MANTIDQT_COMMON RepoModel : public QAbstractItemModel {
76 Q_OBJECT
77
87 class RepoItem {
88 public:
89 // construct the RepoItem passing the script repository path
90 RepoItem(QString label, QString path = "/", RepoItem *parent = nullptr);
91
92 ~RepoItem();
93 // append child to build the directory tree
94 void appendChild(RepoItem *child);
95 // access to the row_th file/folder child of this entry
96 RepoItem *child(int row) const;
98 int row() const;
99 // return the number of files/folders that are children of this entry
100 int childCount() const;
103 const QString &path() const { return keypath; };
106 const QString &label() const { return m_label; };
109 RepoItem *parent() const { return parentItem; };
111 bool removeChild(int row);
112
113 private:
117 QString m_label;
119 QString keypath;
122
123 private:
125 const RepoItem &operator=(const RepoItem &);
126 };
127
128 class UploadForm : public QDialog {
129 public:
130 UploadForm(const QString &file2upload, QWidget *parent = nullptr);
131 ~UploadForm() override;
132 QString email();
133 QString author();
134 QString comment();
135 bool saveInfo();
136 void setEmail(const QString & /*email*/);
137 void setAuthor(const QString & /*author*/);
138 void lastSaveOption(bool option);
139
140 protected:
141 QLineEdit *author_le;
142 QLineEdit *email_le;
143 QCheckBox *save_ck;
144 QTextEdit *comment_te;
145 };
146
153 class DeleteQueryBox : public QMessageBox {
154 public:
155 DeleteQueryBox(const QString &path, QWidget *parent = nullptr);
156 ~DeleteQueryBox() override;
157 QString comment();
158
159 private:
160 QTextEdit *comment_te;
161 };
162
163public:
165 RepoModel(QObject *parent = nullptr);
167 ~RepoModel() override;
169 QVariant data(const QModelIndex &index, int role) const override;
171 Qt::ItemFlags flags(const QModelIndex &index) const override;
173 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
175 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
177 QModelIndex parent(const QModelIndex &index) const override;
179 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
181 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
183 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
184
185 static const QString &localOnlySt();
186 static const QString &remoteOnlySt();
187 static const QString &localChangedSt();
188 static const QString &remoteChangedSt();
189 static const QString &updatedSt();
190 static const QString &bothChangedSt();
191 static const QString &downloadSt();
192 static const QString &uploadSt();
193
194 QString fileDescription(const QModelIndex &index);
195 QString filePath(const QModelIndex &index);
196 QString author(const QModelIndex &index);
197
199
200signals:
201 void executingThread(bool /*_t1*/);
202
203private:
205 void setupModelData(RepoItem *parent);
207 const QString &fromStatus(Mantid::API::SCRIPTSTATUS status) const;
213 QString repo_path;
215 RepoItem *getParent(const QString &folder, QList<RepoItem *> &parents);
216
217 Q_DISABLE_COPY(RepoModel)
218
219
220 void handleExceptions(const Mantid::API::ScriptRepoException &ex, const QString &title,
221 bool showWarning = true) const;
222
223 // handle download in thread
224 QFuture<QString> download_threads;
225 QFutureWatcher<QString> download_watcher;
226 QModelIndex download_index;
228 bool isDownloading(const QModelIndex &index) const;
229private slots:
230 void downloadFinished();
231
232private:
233 // handle connection to the uploader server in thread
234 // this connection are used to upload or deleting files.
235
236 // QFuture variable, used to check if the thread is running, alive, etc...
237 QFuture<QString> upload_threads;
238 // The mechanism to have a call back function executed after finishing the
239 // thread
240 QFutureWatcher<QString> upload_watcher;
241 // keep track of the file being used to the connection with uploader
243 QModelIndex upload_index;
244 // check if the file pointed by the index is inside a connection with uploader
245 bool isUploading(const QModelIndex &index) const;
246private slots:
247 // call back method executed after finishing the thread
248 void uploadFinished();
249};
250
251} // namespace API
252} // 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
Auxiliary Dialog to get the option from the user about removing the entries from the local folder or ...
Definition RepoModel.h:153
A nested class to help RepoModel to implement the QAbstractItemModel.
Definition RepoModel.h:87
QString keypath
the path of the script repository
Definition RepoModel.h:119
const RepoItem & operator=(const RepoItem &)
RepoItem * parent() const
access to the parent of this entry
Definition RepoModel.h:109
const QString & label() const
access to the label provided at construction
Definition RepoModel.h:106
QString m_label
the label of this entry
Definition RepoModel.h:117
const QString & path() const
access to the script repository path
Definition RepoModel.h:103
QList< RepoItem * > childItems
track the list of children for this entry
Definition RepoModel.h:115
RepoItem * parentItem
the parent of this entry
Definition RepoModel.h:121
RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework.
Definition RepoModel.h:75
QFutureWatcher< QString > upload_watcher
Definition RepoModel.h:240
Mantid::API::ScriptRepository_sptr repo_ptr
pointer to the ScriptRepository
Definition RepoModel.h:211
QModelIndex download_index
Definition RepoModel.h:226
QFutureWatcher< QString > download_watcher
Definition RepoModel.h:225
Mantid::API::ScriptRepository_sptr getRepoPtr()
Definition RepoModel.h:198
QFuture< QString > upload_threads
Definition RepoModel.h:237
QString repo_path
ScriptLocalRepository path, to be able to retrieve the absolute path.
Definition RepoModel.h:213
RepoItem * rootItem
pointer to the RepoItem root
Definition RepoModel.h:209
QFuture< QString > download_threads
Definition RepoModel.h:224
The ScriptRepository class is intended to be used mainly by the users, who will be willing to share a...
const QString LOCALCHANGED
Definition RepoModel.h:29
const QString REMOTECHANGED
Definition RepoModel.h:30
const QString DELETABLEENTRY
Definition RepoModel.h:36
const QString BOTHUNCHANGED
Definition RepoModel.h:31
const QString REMOTEONLY
Definition RepoModel.h:27
const QString LOCALONLY
Definition RepoModel.h:28
const QString UPLOADST
Definition RepoModel.h:33
const QString BOTHCHANGED
Definition RepoModel.h:32
const QString DOWNLOADST
Definition RepoModel.h:34
const QString PROTECTEDENTRY
Definition RepoModel.h:35
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< ScriptRepository > ScriptRepository_sptr
shared pointer to the function base class
SCRIPTSTATUS
Represent the possible states for a given file: