Skip to content

Commit

Permalink
Provide the delete functionality to RepoModel
Browse files Browse the repository at this point in the history
Extend RepoModel to support the delete entry functionality.

re #7031
  • Loading branch information
gesnerpassos committed May 28, 2013
1 parent 72ea93a commit ac7fc3d
Show file tree
Hide file tree
Showing 2 changed files with 340 additions and 32 deletions.
52 changes: 40 additions & 12 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/RepoModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "MantidAPI/ScriptRepository.h"
#include <QtConcurrentRun>
#include <QFutureWatcher>
#include <QMessageBox>

class QLineEdit;
class QCheckBox;
Expand All @@ -34,6 +35,9 @@ const QString BOTHUNCHANGED = "UPDATED";
const QString BOTHCHANGED = "CHANGED";
const QString UPLOADST = "UPLOADING";
const QString DOWNLOADST = "DOWNLOADING";
const QString PROTECTEDENTRY = "protected";
const QString DELETABLEENTRY = "deletable";


/** RepoModel : Wrapper for ScriptRepository to fit the Model View Qt Framework.
Expand Down Expand Up @@ -122,7 +126,8 @@ const QString DOWNLOADST = "DOWNLOADING";
/// access to the parent of this entry
/// @return : this entry parent's
RepoItem * parent() const{return parentItem;};

/// allow to remove a child, which allows erasing rows from the view.
bool removeChild(int row);
private:
/// track the list of children for this entry
QList<RepoItem * >childItems;
Expand Down Expand Up @@ -156,6 +161,20 @@ const QString DOWNLOADST = "DOWNLOADING";
QTextEdit * comment_te;
};

/** Auxiliary Dialog to get the option from the user about removing the entries
* from the local folder or the central repository. When removing from central
* repository, it will allow also to provide the justification.
*/
class DeleteQueryBox : public QMessageBox{
public:
DeleteQueryBox(const QString & path, Mantid::API::SCRIPTSTATUS status, QWidget* parent = 0);
virtual ~DeleteQueryBox();
bool deleteCentral();
QString comment();
private:
QTextEdit * comment_te;
QCheckBox * delete_ck;
};

public:
/// constructor
Expand Down Expand Up @@ -194,23 +213,28 @@ const QString DOWNLOADST = "DOWNLOADING";
QString fileDescription(const QModelIndex & index);
QString filePath(const QModelIndex & index);
QString author(const QModelIndex& index);

protected:
/// Implements the QAbstractItemModel::removeRows to allow deleting rows from the view.
bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
private:
/// auxiliary method to populate the model
void setupModelData(RepoItem *parent);
/// auxiliary method to match the ScriptStatus to string
const QString & fromStatus(Mantid::API::SCRIPTSTATUS status)const;

/// pointer to the RepoItem root
RepoItem *rootItem;
/// pointer to the ScriptRepository
Mantid::API::ScriptRepository_sptr repo_ptr;
QString last_selected;
/// ScriptLocalRepository path, to be able to retrieve the absolute path
QString repo_path;
/// auxiliary method to help populating the model
RepoItem * getParent(const QString & folder, QList<RepoItem*>&parents);
private:
RepoModel( const RepoModel& );
const RepoModel& operator=( const RepoModel& );

Q_DISABLE_COPY(RepoModel);
/// logger
static Mantid::Kernel::Logger & g_log;

/// auxiliary method to deal with exceptions
void handleExceptions(const Mantid::API::ScriptRepoException & ex,
const QString & title,
bool showWarning=true)const;
Expand All @@ -223,20 +247,24 @@ const QString DOWNLOADST = "DOWNLOADING";
bool isDownloading(const QModelIndex & index)const ;
private slots:
void downloadFinished();

private:
//handle upload in thread
//handle connection to the uploader server in thread
// this connection are used to upload or deleting files.

// QFuture variable, used to check if the thread is running, alive, etc...
QFuture<QString> upload_threads;
// The mechanism to have a call back function executed after finishing the thread
QFutureWatcher<QString> upload_watcher;
QModelIndex upload_index;
// keep track of the file being used to the connection with uploader
QString uploading_path;
QModelIndex delete_index;
// check if the file pointed by the index is inside a connection with uploader
bool isUploading(const QModelIndex & index)const ;
private slots:
// call back method executed after finishing the thread
void uploadFinished();

};


}; // namespace API
};// namespace Mantid

Expand Down

0 comments on commit ac7fc3d

Please sign in to comment.