This commit is contained in:
Martchus 2017-01-06 21:29:43 +01:00
parent e3202b7fc5
commit 537d31289d
10 changed files with 47 additions and 41 deletions

View File

@ -45,7 +45,7 @@ RenameFilesDialog::RenameFilesDialog(QWidget *parent) :
m_ui->externalScriptPage->setBackgroundRole(QPalette::Base);
// setup preview tree view
m_engine = new RemamingEngine(this);
m_engine = new RenamingEngine(this);
m_ui->currentTreeView->setModel(m_engine->currentModel());
m_ui->previewTreeView->setModel(m_engine->previewModel());
@ -82,9 +82,9 @@ RenameFilesDialog::RenameFilesDialog(QWidget *parent) :
connect(m_ui->generatePreviewPushButton, &QPushButton::clicked, this, &RenameFilesDialog::startGeneratingPreview);
connect(m_ui->applyChangingsPushButton, &QPushButton::clicked, this, &RenameFilesDialog::startApplyChangings);
connect(m_ui->abortClosePushButton, &QPushButton::clicked, this, &RenameFilesDialog::abortClose);
connect(m_engine, &RemamingEngine::previewGenerated, this, &RenameFilesDialog::showPreviewResults);
connect(m_engine, &RemamingEngine::changingsApplied, this, &RenameFilesDialog::showChangsingsResults);
connect(m_engine, &RemamingEngine::progress, this, &RenameFilesDialog::showPreviewProgress);
connect(m_engine, &RenamingEngine::previewGenerated, this, &RenameFilesDialog::showPreviewResults);
connect(m_engine, &RenamingEngine::changingsApplied, this, &RenameFilesDialog::showChangsingsResults);
connect(m_engine, &RenamingEngine::progress, this, &RenameFilesDialog::showPreviewProgress);
connect(m_ui->currentTreeView, &QTreeView::customContextMenuRequested, this, &RenameFilesDialog::showTreeViewContextMenu);
connect(m_ui->previewTreeView, &QTreeView::customContextMenuRequested, this, &RenameFilesDialog::showTreeViewContextMenu);
connect(m_ui->currentTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &RenameFilesDialog::currentItemSelected);

View File

@ -9,7 +9,7 @@
QT_FORWARD_DECLARE_CLASS(QItemSelection)
namespace RenamingUtility {
class RemamingEngine;
class RenamingEngine;
}
namespace QtGui {
@ -56,7 +56,7 @@ private slots:
private:
std::unique_ptr<Ui::RenameFilesDialog> m_ui;
JavaScriptHighlighter *m_highlighter;
RenamingUtility::RemamingEngine *m_engine;
RenamingUtility::RenamingEngine *m_engine;
int m_itemsProcessed;
int m_errorsOccured;
bool m_changingSelection;

View File

@ -29,7 +29,7 @@ class FileSystemItem
{
public:
FileSystemItem(ItemStatus status = ItemStatus::Current, ItemType type = ItemType::File, const QString &name = QString(), FileSystemItem *parent = nullptr);
explicit FileSystemItem(ItemStatus status = ItemStatus::Current, ItemType type = ItemType::File, const QString &name = QString(), FileSystemItem *parent = nullptr);
~FileSystemItem();
FileSystemItem(const FileSystemItem &other) = delete;
FileSystemItem &operator =(const FileSystemItem &other) = delete;

View File

@ -17,8 +17,8 @@ class FileSystemItemModel : public QAbstractItemModel
Q_OBJECT
public:
FileSystemItemModel(FileSystemItem *rootItem, QObject *parent = nullptr);
virtual ~FileSystemItemModel();
explicit FileSystemItemModel(FileSystemItem *rootItem, QObject *parent = nullptr);
~FileSystemItemModel();
void setRootItem(FileSystemItem *rootItem);
QVariant data(const QModelIndex &index, int role) const;

View File

@ -12,7 +12,7 @@ class FilteredFileSystemItemModel : public QSortFilterProxyModel
Q_OBJECT
public:
FilteredFileSystemItemModel(ItemStatus statusFilter = ItemStatus::Current, QObject *parent = nullptr);
explicit FilteredFileSystemItemModel(ItemStatus statusFilter = ItemStatus::Current, QObject *parent = nullptr);
ItemStatus statusFilter() const;
void setStatusFilter(ItemStatus statusFilter);

View File

@ -16,7 +16,7 @@ using namespace ThreadingUtils;
namespace RenamingUtility {
RemamingEngine::RemamingEngine(QObject *parent) :
RenamingEngine::RenamingEngine(QObject *parent) :
QObject(parent),
#ifndef TAGEDITOR_NO_JSENGINE
m_tagEditorQObj(new TagEditorObject(&m_engine)),
@ -33,12 +33,12 @@ RemamingEngine::RemamingEngine(QObject *parent) :
#ifndef TAGEDITOR_NO_JSENGINE
m_engine.globalObject().setProperty(QStringLiteral("tageditor"), m_tagEditorJsObj);
#endif
connect(this, &RemamingEngine::previewGenerated, this, &RemamingEngine::processPreviewGenerated);
connect(this, &RemamingEngine::changingsApplied, this, &RemamingEngine::processChangingsApplied);
connect(this, &RenamingEngine::previewGenerated, this, &RenamingEngine::processPreviewGenerated);
connect(this, &RenamingEngine::changingsApplied, this, &RenamingEngine::processChangingsApplied);
}
#ifndef TAGEDITOR_NO_JSENGINE
bool RemamingEngine::setProgram(const TAGEDITOR_JS_VALUE &program)
bool RenamingEngine::setProgram(const TAGEDITOR_JS_VALUE &program)
{
if(TAGEDITOR_JS_IS_VALID_PROG(program)) {
m_errorMessage.clear();
@ -56,7 +56,7 @@ bool RemamingEngine::setProgram(const TAGEDITOR_JS_VALUE &program)
}
#endif
bool RemamingEngine::setProgram(const QString &program)
bool RenamingEngine::setProgram(const QString &program)
{
#ifndef TAGEDITOR_NO_JSENGINE
return setProgram(m_engine.evaluate(QStringLiteral("(function(){") % program % QStringLiteral("})")));
@ -67,7 +67,7 @@ bool RemamingEngine::setProgram(const QString &program)
#endif
}
bool RemamingEngine::generatePreview(const QDir &rootDirectory, bool includeSubdirs)
bool RenamingEngine::generatePreview(const QDir &rootDirectory, bool includeSubdirs)
{
#ifndef TAGEDITOR_NO_JSENGINE
TryLocker<> locker(m_mutex);
@ -94,7 +94,7 @@ bool RemamingEngine::generatePreview(const QDir &rootDirectory, bool includeSubd
#endif
}
bool RemamingEngine::applyChangings()
bool RenamingEngine::applyChangings()
{
if(!m_rootItem) {
return false;
@ -117,7 +117,7 @@ bool RemamingEngine::applyChangings()
}
}
bool RemamingEngine::isBusy()
bool RenamingEngine::isBusy()
{
if(m_mutex.tryLock()) {
m_mutex.unlock();
@ -127,17 +127,17 @@ bool RemamingEngine::isBusy()
}
}
void RemamingEngine::abort()
void RenamingEngine::abort()
{
m_aborted.store(1);
}
bool RemamingEngine::isAborted()
bool RenamingEngine::isAborted()
{
return m_aborted.load();
}
bool RemamingEngine::clearPreview()
bool RenamingEngine::clearPreview()
{
TryLocker<> locker(m_mutex);
if(locker) {
@ -149,7 +149,7 @@ bool RemamingEngine::clearPreview()
}
}
FileSystemItemModel *RemamingEngine::model()
FileSystemItemModel *RenamingEngine::model()
{
if(!m_model) {
m_model = new FileSystemItemModel(m_rootItem.get(), this);
@ -157,7 +157,7 @@ FileSystemItemModel *RemamingEngine::model()
return m_model;
}
FilteredFileSystemItemModel *RemamingEngine::currentModel()
FilteredFileSystemItemModel *RenamingEngine::currentModel()
{
if(!m_currentModel) {
m_currentModel = new FilteredFileSystemItemModel(ItemStatus::Current, this);
@ -166,7 +166,7 @@ FilteredFileSystemItemModel *RemamingEngine::currentModel()
return m_currentModel;
}
FilteredFileSystemItemModel *RemamingEngine::previewModel()
FilteredFileSystemItemModel *RenamingEngine::previewModel()
{
if(!m_previewModel) {
m_previewModel = new FilteredFileSystemItemModel(ItemStatus::New, this);
@ -175,24 +175,24 @@ FilteredFileSystemItemModel *RemamingEngine::previewModel()
return m_previewModel;
}
void RemamingEngine::processPreviewGenerated()
void RenamingEngine::processPreviewGenerated()
{
setRootItem(move(m_newlyGeneratedRootItem));
}
void RemamingEngine::processChangingsApplied()
void RenamingEngine::processChangingsApplied()
{
updateModel(nullptr);
updateModel(m_rootItem.get());
}
inline void RemamingEngine::setRootItem(unique_ptr<FileSystemItem> &&rootItem)
inline void RenamingEngine::setRootItem(unique_ptr<FileSystemItem> &&rootItem)
{
updateModel(rootItem.get());
m_rootItem = move(rootItem);
}
void RemamingEngine::updateModel(FileSystemItem *rootItem)
void RenamingEngine::updateModel(FileSystemItem *rootItem)
{
if(m_model) {
m_model->setRootItem(rootItem);
@ -200,7 +200,7 @@ void RemamingEngine::updateModel(FileSystemItem *rootItem)
}
#ifndef TAGEDITOR_NO_JSENGINE
unique_ptr<FileSystemItem> RemamingEngine::generatePreview(const QDir &dir, FileSystemItem *parent)
unique_ptr<FileSystemItem> RenamingEngine::generatePreview(const QDir &dir, FileSystemItem *parent)
{
auto item = make_unique<FileSystemItem>(ItemStatus::Current, ItemType::Dir, dir.dirName(), parent);
item->setApplied(false);
@ -234,7 +234,7 @@ unique_ptr<FileSystemItem> RemamingEngine::generatePreview(const QDir &dir, File
}
#endif
void RemamingEngine::applyChangings(FileSystemItem *parentItem)
void RenamingEngine::applyChangings(FileSystemItem *parentItem)
{
for(FileSystemItem *item : parentItem->children()) {
if(!item->applied() && !item->errorOccured()) {
@ -308,7 +308,7 @@ void RemamingEngine::applyChangings(FileSystemItem *parentItem)
emit progress(m_itemsProcessed, m_errorsOccured);
}
void RemamingEngine::setError(const QList<FileSystemItem *> items)
void RenamingEngine::setError(const QList<FileSystemItem *> items)
{
for(FileSystemItem *item : items) {
item->setErrorOccured(true);
@ -317,7 +317,7 @@ void RemamingEngine::setError(const QList<FileSystemItem *> items)
}
#ifndef TAGEDITOR_NO_JSENGINE
void RemamingEngine::executeScriptForItem(const QFileInfo &fileInfo, FileSystemItem *item)
void RenamingEngine::executeScriptForItem(const QFileInfo &fileInfo, FileSystemItem *item)
{
// make file info for the specified item available in the script
m_tagEditorQObj->setFileInfo(fileInfo, item);

View File

@ -27,12 +27,12 @@ class FileSystemItemModel;
class FilteredFileSystemItemModel;
class TagEditorObject;
class RemamingEngine : public QObject
class RenamingEngine : public QObject
{
Q_OBJECT
public:
RemamingEngine(QObject *parent = nullptr);
explicit RenamingEngine(QObject *parent = nullptr);
FileSystemItem *rootItem() const;
#ifndef TAGEDITOR_NO_JSENGINE
@ -100,34 +100,34 @@ private:
int m_errorLineNumber;
};
inline FileSystemItem *RemamingEngine::rootItem() const
inline FileSystemItem *RenamingEngine::rootItem() const
{
return m_rootItem.get();
}
#ifndef TAGEDITOR_NO_JSENGINE
inline const TAGEDITOR_JS_VALUE &RemamingEngine::scriptProgram() const
inline const TAGEDITOR_JS_VALUE &RenamingEngine::scriptProgram() const
{
return m_program;
}
#endif
inline const QDir &RemamingEngine::rootDirectory() const
inline const QDir &RenamingEngine::rootDirectory() const
{
return m_dir;
}
inline bool RemamingEngine::subdirsIncluded() const
inline bool RenamingEngine::subdirsIncluded() const
{
return m_includeSubdirs;
}
inline const QString &RemamingEngine::errorMessage() const
inline const QString &RenamingEngine::errorMessage() const
{
return m_errorMessage;
}
inline int RemamingEngine::errorLineNumber() const
inline int RenamingEngine::errorLineNumber() const
{
return m_errorLineNumber;
}

View File

@ -32,7 +32,7 @@ class TagEditorObject : public QObject
Q_PROPERTY(QString newRelativeDirectory READ newRelativeDirectory WRITE move)
public:
TagEditorObject(TAGEDITOR_JS_ENGINE *engine);
explicit TagEditorObject(TAGEDITOR_JS_ENGINE *engine);
ActionType action() const;
void setFileInfo(const QFileInfo &file, FileSystemItem *item);

View File

@ -4334,6 +4334,9 @@ Remarks
<comment>Necessary for lupdate.</comment>
<translation></translation>
</message>
</context>
<context>
<name>RenamingUtility::RenamingEngine</name>
<message>
<location filename="../renamingutility/renamingengine.cpp" line="52"/>
<source>Program is not callable.</source>

View File

@ -4334,6 +4334,9 @@ Remarks
<comment>Necessary for lupdate.</comment>
<translation></translation>
</message>
</context>
<context>
<name>RenamingUtility::RenamingEngine</name>
<message>
<location filename="../renamingutility/renamingengine.cpp" line="52"/>
<source>Program is not callable.</source>