Mantid
Loading...
Searching...
No Matches
Classes | Signals | Public Member Functions | Static Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
MantidQt::API::RepoModel Class Reference

RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework. More...

#include <RepoModel.h>

Inheritance diagram for MantidQt::API::RepoModel:

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...
 
RepoItemgetParent (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...
 
RepoItemrootItem
 pointer to the RepoItem root More...
 
QModelIndex upload_index
 
QFuture< QString > upload_threads
 
QFutureWatcher< QString > upload_watcher
 
QString uploading_path
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ RepoModel()

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.

◆ ~RepoModel()

RepoModel::~RepoModel ( )
override

destructor

desctructor of repomodel.

Definition at line 170 of file RepoModel.cpp.

References rootItem.

Member Function Documentation

◆ author()

QString RepoModel::author ( const QModelIndex &  index)

◆ bothChangedSt()

const QString & RepoModel::bothChangedSt ( )
static
Returns
string to define the BOTH_CHANGED state

Definition at line 943 of file RepoModel.cpp.

References MantidQt::API::BOTHCHANGED.

Referenced by fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().

◆ columnCount()

int RepoModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
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)

Returns
4.

Definition at line 693 of file RepoModel.cpp.

◆ data()

QVariant RepoModel::data ( const QModelIndex &  index,
int  role 
) const
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:

  • Path
  • Status
  • AutoUpdate
  • Delete

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:

  • LOCAL_ONLY: The file only exists locally.
  • REMOTE_ONLY: The file has not been downloaded.
  • REMOTE_CHANGED: A new version of the file is available.
  • LOCAL_CHANGED: The file has been changed from the original one.
  • BOTH_CHANGED: Locally and remotelly changed.
  • UPDATED: The remote and local file are identical.

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:

  • DisplayRole: to provide the main information.
  • DecorationRole: to provide icons to make easier and fancier to identify the files and folders.
  • ToolTipRole: to provide user help to interact with this class.

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().

◆ downloadFinished

void RepoModel::downloadFinished ( void  )
privateslot

Definition at line 883 of file RepoModel.cpp.

References download_index, download_threads, downloading_path, executingThread(), and nofile_flag.

Referenced by RepoModel().

◆ downloadSt()

const QString & RepoModel::downloadSt ( )
static
Returns
string to define the downloading state

Definition at line 945 of file RepoModel.cpp.

References MantidQt::API::DOWNLOADST.

Referenced by data(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().

◆ executingThread

void MantidQt::API::RepoModel::executingThread ( bool  )
signal

◆ fileDescription()

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().

◆ filePath()

QString RepoModel::filePath ( const QModelIndex &  index)

Return the operative system file path if it exists.

otherwise it returns an empty string

Parameters
indexto find the entry
Returns
The operative system path or empty string

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().

◆ flags()

Qt::ItemFlags RepoModel::flags ( const QModelIndex &  index) const
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.

◆ fromStatus()

const QString & RepoModel::fromStatus ( Mantid::API::SCRIPTSTATUS  status) const
private

auxiliary method to match the ScriptStatus to string

Match the Mantid::API::SCRIPTSTATUS to a string for the user to understand.

Parameters
statusthe SCRIPTSTATUS
Returns
The string that defines the status.

Definition at line 348 of file RepoModel.cpp.

References bothChangedSt(), localChangedSt(), localOnlySt(), remoteChangedSt(), remoteOnlySt(), and updatedSt().

Referenced by data().

◆ getParent()

RepoModel::RepoItem * RepoModel::getParent ( const QString &  folder,
QList< RepoItem * > &  parents 
)
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.

Parameters
folderrelative path inside the repository for the folder.
parentsReference to the list of parents
Returns
Pointer to the RepoItem related to the given folder.

Definition at line 760 of file RepoModel.cpp.

References MantidQt::API::RepoModel::RepoItem::appendChild(), and MantidQt::API::RepoModel::RepoItem::path().

Referenced by setupModelData().

◆ handleExceptions()

void RepoModel::handleExceptions ( const Mantid::API::ScriptRepoException ex,
const QString &  title,
bool  showWarning = true 
) const
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().

◆ headerData()

QVariant RepoModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

header strings

Return the header for the columns.

The RepoModel defines 4 columns with the following information:

  • Path
  • Status
  • AutoUpdate
  • Delete
    Parameters
    sectionThe column number
    orientationIt will accept only the Horizontal orientation.
    roleOnly the DisplayRole will be accepted. It will not provide tool tip for the headers.
    Returns
    The title for the columns.

Definition at line 595 of file RepoModel.cpp.

◆ index()

QModelIndex RepoModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
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.

Parameters
rowthe index of the children (file/folder) under the given folder(parent)
columnThe related column (repomodel defines 3 (path, status, autoupdate)
parentThe QModelIndex parent which refers to the parent folder.
Returns
The QModelIndex that allows to retrieve the information of the desired child.

Definition at line 627 of file RepoModel.cpp.

References MantidQt::API::RepoModel::RepoItem::child(), parent(), and rootItem.

◆ isDownloading()

bool RepoModel::isDownloading ( const QModelIndex &  index) const
private

Definition at line 897 of file RepoModel.cpp.

References downloading_path, index, and MantidQt::API::RepoModel::RepoItem::path().

Referenced by data().

◆ isUploading()

bool RepoModel::isUploading ( const QModelIndex &  index) const
private

Definition at line 925 of file RepoModel.cpp.

References index, MantidQt::API::RepoModel::RepoItem::path(), and uploading_path.

Referenced by data().

◆ localChangedSt()

const QString & RepoModel::localChangedSt ( )
static

◆ localOnlySt()

const QString & RepoModel::localOnlySt ( )
static

◆ parent()

QModelIndex RepoModel::parent ( const QModelIndex &  index) const
override

access to parent

Provide the parent of a given entry, through the QModelIndex abstraction.

Parameters
indexThe QModelIndex that identifies one entry.
Returns
A QModelIndex that indentifies the parent of the given index.

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().

◆ remoteChangedSt()

const QString & RepoModel::remoteChangedSt ( )
static
Returns
string to define the REMOTE_CHANGED state

Definition at line 939 of file RepoModel.cpp.

References MantidQt::API::REMOTECHANGED.

Referenced by fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().

◆ remoteOnlySt()

const QString & RepoModel::remoteOnlySt ( )
static
Returns
string to define the REMOTE_ONLY state

Definition at line 935 of file RepoModel.cpp.

References MantidQt::API::REMOTEONLY.

Referenced by fromStatus(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().

◆ rowCount()

int RepoModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Count how many file/folders are direct children of the given folder, through the abstraction of QModelIndex.

Parameters
parentthe index to the folder.
Returns
the number of children of the given folder.

Definition at line 673 of file RepoModel.cpp.

References MantidQt::API::RepoModel::RepoItem::childCount(), parent(), and rootItem.

◆ setData()

bool RepoModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
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().

◆ setupModelData()

void RepoModel::setupModelData ( RepoItem root)
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.

Parameters
rootThe RepoItem root

Definition at line 821 of file RepoModel.cpp.

References getParent(), parent(), and repo_ptr.

Referenced by RepoModel().

◆ updatedSt()

const QString & RepoModel::updatedSt ( )
static

◆ uploadFinished

void RepoModel::uploadFinished ( void  )
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().

◆ uploadSt()

const QString & RepoModel::uploadSt ( )
static
Returns
string to define the uploading state

Definition at line 947 of file RepoModel.cpp.

References MantidQt::API::UPLOADST.

Referenced by data(), and MantidQt::API::ScriptRepositoryView::RepoDelegate::getIcon().

Member Data Documentation

◆ download_index

QModelIndex MantidQt::API::RepoModel::download_index
private

Definition at line 224 of file RepoModel.h.

Referenced by downloadFinished(), and setData().

◆ download_threads

QFuture<QString> MantidQt::API::RepoModel::download_threads
private

Definition at line 222 of file RepoModel.h.

Referenced by downloadFinished(), and setData().

◆ download_watcher

QFutureWatcher<QString> MantidQt::API::RepoModel::download_watcher
private

Definition at line 223 of file RepoModel.h.

Referenced by RepoModel(), and setData().

◆ downloading_path

QString MantidQt::API::RepoModel::downloading_path
private

Definition at line 225 of file RepoModel.h.

Referenced by downloadFinished(), isDownloading(), RepoModel(), and setData().

◆ repo_path

QString MantidQt::API::RepoModel::repo_path
private

ScriptLocalRepository path, to be able to retrieve the absolute path.

Definition at line 211 of file RepoModel.h.

Referenced by filePath(), and RepoModel().

◆ repo_ptr

Mantid::API::ScriptRepository_sptr MantidQt::API::RepoModel::repo_ptr
private

pointer to the ScriptRepository

Definition at line 209 of file RepoModel.h.

Referenced by author(), data(), fileDescription(), filePath(), RepoModel(), setData(), and setupModelData().

◆ rootItem

RepoItem* MantidQt::API::RepoModel::rootItem
private

pointer to the RepoItem root

Definition at line 207 of file RepoModel.h.

Referenced by index(), parent(), RepoModel(), rowCount(), and ~RepoModel().

◆ upload_index

QModelIndex MantidQt::API::RepoModel::upload_index
private

Definition at line 241 of file RepoModel.h.

Referenced by setData(), and uploadFinished().

◆ upload_threads

QFuture<QString> MantidQt::API::RepoModel::upload_threads
private

Definition at line 235 of file RepoModel.h.

Referenced by setData(), and uploadFinished().

◆ upload_watcher

QFutureWatcher<QString> MantidQt::API::RepoModel::upload_watcher
private

Definition at line 238 of file RepoModel.h.

Referenced by RepoModel(), and setData().

◆ uploading_path

QString MantidQt::API::RepoModel::uploading_path
private

Definition at line 240 of file RepoModel.h.

Referenced by isUploading(), RepoModel(), setData(), and uploadFinished().


The documentation for this class was generated from the following files: