Mantid
|
RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework. More...
#include <RepoModel.h>
Classes | |
class | DeleteQueryBox |
Auxiliary Dialog to get the option from the user about removing the entries from the local folder or the central repository. More... | |
class | RepoItem |
A nested class to help RepoModel to implement the QAbstractItemModel. More... | |
class | UploadForm |
Signals | |
void | executingThread (bool) |
Public Member Functions | |
QString | author (const QModelIndex &index) |
int | columnCount (const QModelIndex &parent=QModelIndex()) const override |
provide the number of the columns More... | |
QVariant | data (const QModelIndex &index, int role) const override |
access to the ScriptRepository data More... | |
QString | fileDescription (const QModelIndex &index) |
Return the description of the file for a defined entry. More... | |
QString | filePath (const QModelIndex &index) |
Return the operative system file path if it exists. More... | |
Qt::ItemFlags | flags (const QModelIndex &index) const override |
information on the available interaction More... | |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override |
header strings More... | |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
access to the index More... | |
QModelIndex | parent (const QModelIndex &index) const override |
access to parent More... | |
RepoModel (QObject *parent=nullptr) | |
constructor More... | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
Count how many file/folders are direct children of the given folder, through the abstraction of QModelIndex. More... | |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override |
change data More... | |
~RepoModel () override | |
destructor More... | |
Static Public Member Functions | |
static const QString & | bothChangedSt () |
static const QString & | downloadSt () |
static const QString & | localChangedSt () |
static const QString & | localOnlySt () |
static const QString & | remoteChangedSt () |
static const QString & | remoteOnlySt () |
static const QString & | updatedSt () |
static const QString & | uploadSt () |
Private Slots | |
void | downloadFinished () |
void | uploadFinished () |
Private Member Functions | |
const QString & | fromStatus (Mantid::API::SCRIPTSTATUS status) const |
auxiliary method to match the ScriptStatus to string More... | |
RepoItem * | getParent (const QString &folder, QList< RepoItem * > &parents) |
auxiliary method to help populating the model More... | |
void | handleExceptions (const Mantid::API::ScriptRepoException &ex, const QString &title, bool showWarning=true) const |
auxiliary method to deal with exceptions More... | |
bool | isDownloading (const QModelIndex &index) const |
bool | isUploading (const QModelIndex &index) const |
void | setupModelData (RepoItem *parent) |
auxiliary method to populate the model More... | |
Private Attributes | |
QModelIndex | download_index |
QFuture< QString > | download_threads |
QFutureWatcher< QString > | download_watcher |
QString | downloading_path |
QString | repo_path |
ScriptLocalRepository path, to be able to retrieve the absolute path. More... | |
Mantid::API::ScriptRepository_sptr | repo_ptr |
pointer to the ScriptRepository More... | |
RepoItem * | rootItem |
pointer to the RepoItem root More... | |
QModelIndex | upload_index |
QFuture< QString > | upload_threads |
QFutureWatcher< QString > | upload_watcher |
QString | uploading_path |
RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework.
The ScriptRepository has an hierarchical access to the folders and files, as so, it was necessary to extend the QAbstractItemModel in order to provide access to the entries on ScriptRepository.
The RepoModel will be given to a QTreeView and as so, it will allow the user to interact with the ScriptRepository through the Qt ModelView Framework.
The requirements for a class to fit this framework is to reimplement the following methods:
Through these methods, the RepoModel will be able to provide access to the ScriptRepository service. Allowing the users to upload and download files and folders.
Some extra services are provided, to allow the classes to show the description of the files as well as open the files to be inspected by the users:
This class should be constructed just once, and as so, the copy constructor and the assignment will be make private to ensure this.
Definition at line 75 of file RepoModel.h.
RepoModel::RepoModel | ( | QObject * | parent = nullptr | ) |
constructor
The constructor of RepoModel.
It is intended to have just one model and to pass on through shared pointer. To enforce this, the copy constructor is disabled. It will construct the hierarchical tree of ScriptRepository through the setuptModelData.
Definition at line 154 of file RepoModel.cpp.
References download_watcher, downloadFinished(), downloading_path, Mantid::Kernel::ConfigServiceImpl::getString(), nofile_flag, repo_path, repo_ptr, rootItem, setupModelData(), upload_watcher, uploadFinished(), and uploading_path.
|
override |
destructor
desctructor of repomodel.
Definition at line 170 of file RepoModel.cpp.
References rootItem.
QString RepoModel::author | ( | const QModelIndex & | index | ) |
Definition at line 710 of file RepoModel.cpp.
References author(), index, and repo_ptr.
Referenced by author(), MantidQt::API::ScriptRepositoryView::currentChanged(), MantidQt::API::RepoModel::UploadForm::setAuthor(), and setData().
|
static |
Definition at line 943 of file RepoModel.cpp.
References MantidQt::API::BOTHCHANGED.
Referenced by fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
override |
provide the number of the columns
Return the number of columns defined for the given index.
But, for all the index, the number of columns will be always 4. (path, status, autoupdate, delete)
Definition at line 693 of file RepoModel.cpp.
|
override |
access to the ScriptRepository data
Provide access to the data through the defined QAbstractItemModel definition.
The index parameter defines how to access the corresponded data while the role define the kind of information desired from RepoModel. This method will be queried from QView in order to populate the view.
From the index.internalPointer the RepoModel will have access to the path, which uniquely define its entry on ScriptRepository.
The RepoModel defines 4 columns:
The path, provides the name of the file. The status, give information on the ScriptRepository entries. Currently, an entry may be found on the following states:
The AutoUpdate allow to flag the entries to receive the updates automatically when new files are available at the central repository.
The delete column will return a string "protected" or "deletable" that will be used to know if it can be deleted or not. For the current version, folders are protected, and files are deletable.
The repomodel will react to the following roles:
Definition at line 212 of file RepoModel.cpp.
References Mantid::API::ScriptInfo::auto_update, MantidQt::API::DELETABLEENTRY, Mantid::API::ScriptInfo::directory, downloadSt(), fromStatus(), handleExceptions(), index, isDownloading(), isUploading(), MantidQt::API::RepoModel::RepoItem::path(), MantidQt::API::PROTECTEDENTRY, Mantid::API::REMOTE_ONLY, repo_ptr, and uploadSt().
Referenced by MantidQt::API::ScriptRepositoryView::RepoDelegate::editorEvent(), and MantidQt::API::ScriptRepositoryView::CheckBoxDelegate::editorEvent().
|
privateslot |
Definition at line 883 of file RepoModel.cpp.
References download_index, download_threads, downloading_path, executingThread(), and nofile_flag.
Referenced by RepoModel().
|
static |
Definition at line 945 of file RepoModel.cpp.
References MantidQt::API::DOWNLOADST.
Referenced by data(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
signal |
Referenced by downloadFinished(), setData(), and uploadFinished().
QString RepoModel::fileDescription | ( | const QModelIndex & | index | ) |
Return the description of the file for a defined entry.
Definition at line 697 of file RepoModel.cpp.
References index, and repo_ptr.
Referenced by MantidQt::API::ScriptRepositoryView::currentChanged().
QString RepoModel::filePath | ( | const QModelIndex & | index | ) |
Return the operative system file path if it exists.
otherwise it returns an empty string
index | to find the entry |
Definition at line 727 of file RepoModel.cpp.
References Mantid::API::ScriptInfo::directory, index, Mantid::API::REMOTE_ONLY, repo_path, and repo_ptr.
Referenced by MantidQt::API::ScriptRepositoryView::cell_activated().
|
override |
information on the available interaction
Define the interaction with the user allowed.
Currently the user is allowed to select the path column, to collapse, expand the folders, and he is allowed to submit actions to the columns 1 and 2 (download/upload triggers) and (auto update flag).
Definition at line 572 of file RepoModel.cpp.
References index.
|
private |
auxiliary method to match the ScriptStatus to string
Match the Mantid::API::SCRIPTSTATUS to a string for the user to understand.
status | the SCRIPTSTATUS |
Definition at line 348 of file RepoModel.cpp.
References bothChangedSt(), localChangedSt(), localOnlySt(), remoteChangedSt(), remoteOnlySt(), and updatedSt().
Referenced by data().
|
private |
auxiliary method to help populating the model
Auxiliary method to help setupModelData to populate all the entries of RepoModel.
For any entry of ScriptRepository should have a parent (by definition, all the entries are children of the root entry). Besides, given an entry, if the path contains a '/' this means that the entry is child of one folder. And all the folders are parents by definition.
So, the idea of this getParent is that given a folder name, it must be related to a RepoItem that is a parent. If it does not exists, it should be created.
folder | relative path inside the repository for the folder. |
parents | Reference to the list of parents |
Definition at line 760 of file RepoModel.cpp.
References MantidQt::API::RepoModel::RepoItem::appendChild(), and MantidQt::API::RepoModel::RepoItem::path().
Referenced by setupModelData().
|
private |
auxiliary method to deal with exceptions
Definition at line 870 of file RepoModel.cpp.
References Mantid::Kernel::Logger::information(), Mantid::API::ScriptRepoException::systemError(), and Mantid::API::ScriptRepoException::what().
Referenced by data().
|
override |
header strings
Return the header for the columns.
The RepoModel defines 4 columns with the following information:
section | The column number |
orientation | It will accept only the Horizontal orientation. |
role | Only the DisplayRole will be accepted. It will not provide tool tip for the headers. |
Definition at line 595 of file RepoModel.cpp.
|
override |
access to the index
An hierarchical structure is able to define any point giving the parent, the row and the column.
This method is ment to be used to the View to iterate through the model.
row | the index of the children (file/folder) under the given folder(parent) |
column | The related column (repomodel defines 3 (path, status, autoupdate) |
parent | The QModelIndex parent which refers to the parent folder. |
Definition at line 627 of file RepoModel.cpp.
References MantidQt::API::RepoModel::RepoItem::child(), parent(), and rootItem.
|
private |
Definition at line 897 of file RepoModel.cpp.
References downloading_path, index, and MantidQt::API::RepoModel::RepoItem::path().
Referenced by data().
|
private |
Definition at line 925 of file RepoModel.cpp.
References index, MantidQt::API::RepoModel::RepoItem::path(), and uploading_path.
Referenced by data().
|
static |
Definition at line 937 of file RepoModel.cpp.
References MantidQt::API::LOCALCHANGED.
Referenced by MantidQt::API::ScriptRepositoryView::RepoDelegate::editorEvent(), fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
static |
Definition at line 933 of file RepoModel.cpp.
References MantidQt::API::LOCALONLY.
Referenced by MantidQt::API::ScriptRepositoryView::RepoDelegate::editorEvent(), fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
override |
access to parent
Provide the parent of a given entry, through the QModelIndex abstraction.
index | The QModelIndex that identifies one entry. |
Definition at line 654 of file RepoModel.cpp.
References index, MantidQt::API::RepoModel::RepoItem::parent(), rootItem, and MantidQt::API::RepoModel::RepoItem::row().
Referenced by index(), rowCount(), and setupModelData().
|
static |
Definition at line 939 of file RepoModel.cpp.
References MantidQt::API::REMOTECHANGED.
Referenced by fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
static |
Definition at line 935 of file RepoModel.cpp.
References MantidQt::API::REMOTEONLY.
Referenced by fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
override |
Count how many file/folders are direct children of the given folder, through the abstraction of QModelIndex.
parent | the index to the folder. |
Definition at line 673 of file RepoModel.cpp.
References MantidQt::API::RepoModel::RepoItem::childCount(), parent(), and rootItem.
|
override |
change data
The ScriptRepository allows to download and upload file and folders.
And to configure the AutoUpdate option for the entries. These actions will be available through the setData method.
The setData will recognize only the EditRole as a valid Role. The RepoModel will recognize the following entries. The path can not be edited (column 0) is not editable. the AutoUpdate flag (column 2) will accept the following actions: setTrue and setFalse, to enable or disable the automatic update.
The Status (column 1) will accept the following actions: Download and Upload.
Definition at line 384 of file RepoModel.cpp.
References author(), delete_thread(), download_index, download_thread(), download_threads, download_watcher, downloading_path, executingThread(), index, MantidQt::API::RepoModel::RepoItem::path(), repo_ptr, upload_index, upload_thread(), upload_threads, upload_watcher, uploading_path, and value.
Referenced by MantidQt::API::ScriptRepositoryView::RepoDelegate::editorEvent(), MantidQt::API::ScriptRepositoryView::CheckBoxDelegate::editorEvent(), and MantidQt::API::ScriptRepositoryView::RemoveEntryDelegate::editorEvent().
|
private |
auxiliary method to populate the model
Populate the RepoModel with RepoItem entries that reproduce the hierarchical organization of ScriptRepository entries.
It will get the information from ScriptRepository from the listFiles, which means, that it will reconstruct the hierarchical organization of the files and folders through the list of strings with the relative path of each entry.
root | The RepoItem root |
Definition at line 821 of file RepoModel.cpp.
References getParent(), parent(), and repo_ptr.
Referenced by RepoModel().
|
static |
Definition at line 941 of file RepoModel.cpp.
References MantidQt::API::BOTHUNCHANGED.
Referenced by MantidQt::API::ScriptRepositoryView::RepoDelegate::editorEvent(), fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
privateslot |
Definition at line 904 of file RepoModel.cpp.
References delete_mark, executingThread(), nofile_flag, upload_index, upload_threads, and uploading_path.
Referenced by RepoModel().
|
static |
Definition at line 947 of file RepoModel.cpp.
References MantidQt::API::UPLOADST.
Referenced by data(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().
|
private |
Definition at line 224 of file RepoModel.h.
Referenced by downloadFinished(), and setData().
|
private |
Definition at line 222 of file RepoModel.h.
Referenced by downloadFinished(), and setData().
|
private |
Definition at line 223 of file RepoModel.h.
Referenced by RepoModel(), and setData().
|
private |
Definition at line 225 of file RepoModel.h.
Referenced by downloadFinished(), isDownloading(), RepoModel(), and setData().
|
private |
ScriptLocalRepository path, to be able to retrieve the absolute path.
Definition at line 211 of file RepoModel.h.
Referenced by filePath(), and RepoModel().
|
private |
pointer to the ScriptRepository
Definition at line 209 of file RepoModel.h.
Referenced by author(), data(), fileDescription(), filePath(), RepoModel(), setData(), and setupModelData().
|
private |
pointer to the RepoItem root
Definition at line 207 of file RepoModel.h.
Referenced by index(), parent(), RepoModel(), rowCount(), and ~RepoModel().
|
private |
Definition at line 241 of file RepoModel.h.
Referenced by setData(), and uploadFinished().
|
private |
Definition at line 235 of file RepoModel.h.
Referenced by setData(), and uploadFinished().
|
private |
Definition at line 238 of file RepoModel.h.
Referenced by RepoModel(), and setData().
|
private |
Definition at line 240 of file RepoModel.h.
Referenced by isUploading(), RepoModel(), setData(), and uploadFinished().