Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Modernize signal-slot and migrate to QRegularExpression

andeon180339e6edd7
diff --git a/toonz/sources/toonz/dvdirtreeview.cpp b/toonz/sources/toonz/dvdirtreeview.cpp
index 6d1bc12cf..2cec2a3c5 100644
--- a/toonz/sources/toonz/dvdirtreeview.cpp
+++ b/toonz/sources/toonz/dvdirtreeview.cpp
@@ -1,25 +1,28 @@
-
-
#include <QtGlobal>
#include "dvdirtreeview.h"
#include "filebrowsermodel.h"
-#include "menubarcommandids.h"
#include "filebrowser.h"
+#include "menubarcommandids.h"
+#include "tapp.h"
+#include "toonz/tscenehandle.h"
+
+// TnzQt includes
+#include "toonzqt/icongenerator.h"
+#include "toonzqt/dvdialog.h"
+#include "toonzqt/gutil.h"
+
+// ToonzLib
#include "tconvert.h"
-#include "tsystem.h"
#include "toonz/toonzscene.h"
#include "toonz/namebuilder.h"
#include "toonz/tproject.h"
#include "toonz/preferences.h"
#include "toonz/txshsimplelevel.h"
-#include "toonzqt/icongenerator.h"
-#include "toonzqt/dvdialog.h"
-#include "toonzqt/gutil.h"
-#include "tapp.h"
-#include "toonz/tscenehandle.h"
+#include "tsystem.h"
+// Qt includes
#include <QPainter>
#include <QPixmap>
#include <QMouseEvent>
@@ -30,47 +33,63 @@
#include <QDir>
#include <QMimeData>
#include <QFileSystemWatcher>
+#include <QRegularExpression>
using namespace DVGui;
namespace {
+
//---------------------------------------------------------------------------
-QStringList getLevelFileNames(TFilePath path) {
+QStringList getLevelFileNames(const TFilePath &path) {
TFilePath dir = path.getParentDir();
QDir qDir(QString::fromStdWString(dir.getWideString()));
+
QString levelName =
- QRegExp::escape(QString::fromStdWString(path.getWideName()));
+ QRegularExpression::escape(QString::fromStdWString(path.getWideName()));
QString levelType = QString::fromStdString(path.getType());
- QString exp(levelName + ".[0-9]{1,4}." + levelType);
- QRegExp regExp(exp);
+
+ // Pattern for matching level files: name.[0-9]{1,4}.type
+ QString pattern = QString("^%1\\.[0-9]{1,4}\\.%2$").arg(levelName, levelType);
+ QRegularExpression regExp(pattern);
+
QStringList list = qDir.entryList(QDir::Files);
- return list.filter(regExp);
+ QStringList result;
+
+ for (const QString &file : list) {
+ if (regExp.match(file).hasMatch()) {
+ result.append(file);
+ }
+ }
+
+ return result;
}
+
} // namespace
//=============================================================================
// MyFileSystemWatcher
//-----------------------------------------------------------------------------
-MyFileSystemWatcher::MyFileSystemWatcher() {
+MyFileSystemWatcher::MyFileSystemWatcher(QObject *parent) : QObject(parent) {
m_watcher = new QFileSystemWatcher(this);
- bool ret = connect(m_watcher, SIGNAL(directoryChanged(const QString &)), this,
- SIGNAL(directoryChanged(const QString &)));
- assert(ret);
+ connect(m_watcher, &QFileSystemWatcher::directoryChanged, this,
+ &MyFileSystemWatcher::directoryChanged);
}
void MyFileSystemWatcher::addPaths(const QStringList &paths, bool onlyNewPath) {
if (paths.isEmpty()) return;
- for (int p = 0; p < paths.size(); p++) {
- QString path = paths.at(p);
- // if the path is not watched yet, try to start watching it
+
+ for (const QString &path : paths) {
+ // If the path is not watched yet, try to start watching it
if (!m_watchedPath.contains(path)) {
- // symlink path will not be watched
- if (m_watcher->addPath(path)) m_watchedPath.append(path);
+ // Symlink paths will not be watched
+ if (m_watcher->addPath(path)) {
+ m_watchedPath.append(path);
+ }
}
- // or just add path to the list
+ // Or just add path to the list
else if (!onlyNewPath) {
m_watchedPath.append(path);
}
@@ -79,16 +98,18 @@ void MyFileSystemWatcher::addPaths(const QStringList &paths, bool onlyNewPath) {
void MyFileSystemWatcher::removePaths(const QStringList &paths) {
if (m_watchedPath.isEmpty() || paths.isEmpty()) return;
- for (int p = 0; p < paths.size(); p++) {
- QString path = paths.at(p);
+
+ for (const QString &path : paths) {
// removeOne will return false for symlink paths
- bool ret = m_watchedPath.removeOne(path);
- if (ret && !m_watchedPath.contains(path)) m_watcher->removePath(path);
+ if (m_watchedPath.removeOne(path) && !m_watchedPath.contains(path)) {
+ m_watcher->removePath(path);
+ }
}
}
void MyFileSystemWatcher::removeAllPaths() {
if (m_watchedPath.isEmpty()) return;
+
m_watcher->removePaths(m_watcher->directories());
m_watchedPath.clear();
}
@@ -98,12 +119,11 @@ void MyFileSystemWatcher::removeAllPaths() {
//-----------------------------------------------------------------------------
DvDirTreeViewDelegate::DvDirTreeViewDelegate(DvDirTreeView *parent)
- : QItemDelegate(parent) // QAbstractItemDelegate(parent)
- , m_treeView(parent) {}
+ : QItemDelegate(parent), m_treeView(parent) {}
//-----------------------------------------------------------------------------
-DvDirTreeViewDelegate::~DvDirTreeViewDelegate() {}
+DvDirTreeViewDelegate::~DvDirTreeViewDelegate() = default;
//-----------------------------------------------------------------------------
@@ -111,21 +131,24 @@ QWidget *DvDirTreeViewDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {
DvDirModelNode *node = DvDirModel::instance()->getNode(index);
- if (!node) return 0;
+ if (!node) return nullptr;
+
DvDirModelFileFolderNode *fnode =
dynamic_cast<DvDirModelFileFolderNode *>(node);
- if (!fnode || fnode->isProjectFolder()) return 0;
+ if (!fnode || fnode->isProjectFolder()) return nullptr;
+
QPixmap px = node->getPixmap(m_treeView->isExpanded(index));
QRect rect = option.rect;
+
if (index.data().canConvert(QMetaType::QString)) {
NodeEditor *editor = new NodeEditor(parent, rect, px.width());
editor->setText(index.data().toString());
- connect(editor, SIGNAL(editingFinished()), this,
- SLOT(commitAndCloseEditor()));
+ connect(editor, &NodeEditor::editingFinished, this,
+ &DvDirTreeViewDelegate::commitAndCloseEditor);
return editor;
- } else {
- return QAbstractItemDelegate::createEditor(parent, option, index);
}
+
+ return QAbstractItemDelegate::createEditor(parent, option, index);
}
//-----------------------------------------------------------------------------
@@ -134,34 +157,38 @@ bool DvDirTreeViewDelegate::editorEvent(QEvent *ev, QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index) {
if (ev->type() == QEvent::MouseButtonPress) {
- QMouseEvent *mev = static_cast<QMouseEvent *>(ev);
- QRect bounds = option.rect;
- int x = mev->pos().x() - bounds.x();
+ QMouseEvent *mev = static_cast<QMouseEvent *>(ev);
+ QRect bounds = option.rect;
+ int x = mev->pos().x() - bounds.x();
+
DvDirModelNode *node = DvDirModel::instance()->getNode(index);
DvDirModelProjectNode *pnode = dynamic_cast<DvDirModelProjectNode *>(node);
DvDirVersionControlProjectNode *vcpNode =
dynamic_cast<DvDirVersionControlProjectNode *>(node);
- // shrink / expand the tree by clicking the item
+ // Shrink/expand the tree by clicking the item
if (node) {
- if (m_treeView->isExpanded(index))
+ if (m_treeView->isExpanded(index)) {
m_treeView->collapse(index);
- else
+ } else {
m_treeView->expand(index);
+ }
}
- if ((pnode && pnode->isCurrent() == false && 14 < x && x < 26) ||
- (vcpNode && vcpNode->isCurrent() == false && 14 < x && x < 26)) {
- if (pnode)
+ if ((pnode && !pnode->isCurrent() && 14 < x && x < 26) ||
+ (vcpNode && !vcpNode->isCurrent() && 14 < x && x < 26)) {
+ if (pnode) {
pnode->makeCurrent();
- else if (vcpNode)
+ } else if (vcpNode) {
vcpNode->makeCurrent();
+ }
m_treeView->update();
return true;
} else {
m_treeView->update();
}
}
+
return false;
}
@@ -174,7 +201,7 @@ void DvDirTreeViewDelegate::paint(QPainter *painter,
DvDirModelNode *node = DvDirModel::instance()->getNode(index);
if (!node) return;
- // current node and drag'n drop
+ // Current node and drag'n drop
bool isCurrent = (m_treeView->getCurrentNode() == node);
if (isCurrent) {
painter->fillRect(rect.adjusted(-2, 0, 0, 0),
@@ -191,7 +218,7 @@ void DvDirTreeViewDelegate::paint(QPainter *painter,
}
}
- // icon
+ // Icon
QPixmap px = node->getPixmap(m_treeView->isExpanded(index));
if (!px.isNull()) {
int x = rect.left();
@@ -210,33 +237,33 @@ void DvDirTreeViewDelegate::paint(QPainter *painter,
rect.adjust((pnode || vcpNode) ? 31 : 22, 0, 0, 0);
- // draw text
- QVariant d = index.data();
- QString name = d.toString();
-
- // text color
+ // Draw text
+ QString name = index.data().toString();
+ // Text color
if (fnode && fnode->isProjectFolder()) {
- painter->setPen((isCurrent) ? m_treeView->getSelectedFolderTextColor()
- : m_treeView->getFolderTextColor());
+ painter->setPen(isCurrent ? m_treeView->getSelectedFolderTextColor()
+ : m_treeView->getFolderTextColor());
} else {
- painter->setPen((isCurrent) ? m_treeView->getSelectedTextColor()
- : m_treeView->getTextColor());
+ painter->setPen(isCurrent ? m_treeView->getSelectedTextColor()
+ : m_treeView->getTextColor());
}
painter->drawText(rect, Qt::AlignVCenter | Qt::AlignLeft, name);
- // project folder node, version control node
+ // Project folder node, version control node
if (pnode || vcpNode) {
painter->setPen(m_treeView->getTextColor());
- if ((pnode && pnode->isCurrent()) || (vcpNode && vcpNode->isCurrent()))
+ if ((pnode && pnode->isCurrent()) || (vcpNode && vcpNode->isCurrent())) {
painter->setBrush(Qt::red);
- else
+ } else {
painter->setBrush(Qt::NoBrush);
+ }
int d = 8;
int y = (rect.height() - d) / 2;
painter->drawEllipse(rect.x() - d - 4, rect.y() + y, d, d);
}
+
if (vcNode && vcNode->isUnderVersionControl() &&
TFileStatus(vcNode->getPath()).doesExist() && !vcNode->isUnversioned()) {
if (vcNode->isSynched()) {
@@ -261,10 +288,14 @@ void DvDirTreeViewDelegate::paint(QPainter *painter,
void DvDirTreeViewDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
- if (index.data().canConvert(QMetaType::QString))
+ if (index.data().canConvert(QMetaType::QString)) {
NodeEditor *nodeEditor = qobject_cast<NodeEditor *>(editor);
- else
+ if (nodeEditor) {
+ nodeEditor->setText(index.data().toString());
+ }
+ } else {
QAbstractItemDelegate::setEditorData(editor, index);
+ }
}
//-----------------------------------------------------------------------------
@@ -274,29 +305,37 @@ void DvDirTreeViewDelegate::setModelData(QWidget *editor,
const QModelIndex &index) const {
if (index.data().canConvert(QMetaType::QString)) {
NodeEditor *nodeEditor = qobject_cast<NodeEditor *>(editor);
- model->setData(index, QVariant::fromValue(
- nodeEditor->getText())); // starEditor->text()));
- } else
+ if (nodeEditor) {
+ model->setData(index, QVariant::fromValue(nodeEditor->getText()));
+ }
+ } else {
QAbstractItemDelegate::setModelData(editor, model, index);
+ }
}
//----------------------------------------------------------------------------
void DvDirTreeViewDelegate::commitAndCloseEditor() {
NodeEditor *editor = qobject_cast<NodeEditor *>(sender());
+ if (!editor) return;
+
emit commitData(editor);
emit closeEditor(editor);
- QWidget* w = m_treeView;
- FileBrowser* fileBrowser = nullptr;
+
+ // Find the FileBrowser parent
+ QWidget *w = m_treeView;
+ FileBrowser *fileBrowser = nullptr;
while (w) {
- fileBrowser = qobject_cast<FileBrowser*>(w);
- if (fileBrowser) break;
- w = w->parentWidget();
+ fileBrowser = qobject_cast<FileBrowser *>(w);
+ if (fileBrowser) break;
+ w = w->parentWidget();
}
- if (fileBrowser) fileBrowser->onTreeFolderChanged();
-
+ if (fileBrowser) {
+ fileBrowser->onTreeFolderChanged();
+ }
}
+
//-----------------------------------------------------------------------------
QSize DvDirTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option,
@@ -308,7 +347,9 @@ QSize DvDirTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option,
void DvDirTreeViewDelegate::updateEditorGeometry(
QWidget *editor, const QStyleOptionViewItem &option,
- const QModelIndex &index) const {}
+ const QModelIndex &index) const {
+ QItemDelegate::updateEditorGeometry(editor, option, index);
+}
//=============================================================================
//
@@ -319,9 +360,9 @@ void DvDirTreeViewDelegate::updateEditorGeometry(
DvDirTreeView::DvDirTreeView(QWidget *parent)
: StyledTreeView(parent)
, m_globalSelectionEnabled(true)
- , m_currentDropItem(0)
+ , m_currentDropItem(nullptr)
, m_refreshVersionControlEnabled(false)
- , m_currentRefreshedNode(0) {
+ , m_currentRefreshedNode(nullptr) {
setModel(DvDirModel::instance());
header()->close();
setItemDelegate(new DvDirTreeViewDelegate(this));
@@ -332,43 +373,34 @@ DvDirTreeView::DvDirTreeView(QWidget *parent)
// Connect all possible changes that can alter the
// bottom horizontal scrollbar to resize contents...
- bool ret = true;
- ret = ret && connect(this, SIGNAL(expanded(const QModelIndex &)), this,
- SLOT(resizeToConts()));
-
- ret = ret && connect(this, SIGNAL(collapsed(const QModelIndex &)), this,
- SLOT(resizeToConts()));
-
- ret = ret && connect(this->model(), SIGNAL(layoutChanged()), this,
- SLOT(resizeToConts()));
+ connect(this, &DvDirTreeView::expanded, this, &DvDirTreeView::resizeToConts);
+ connect(this, &DvDirTreeView::collapsed, this, &DvDirTreeView::resizeToConts);
+ connect(this->model(), &QAbstractItemModel::layoutChanged, this,
+ &DvDirTreeView::resizeToConts);
if (Preferences::instance()->isWatchFileSystemEnabled()) {
- ret = ret && connect(this, SIGNAL(expanded(const QModelIndex &)), this,
- SLOT(onExpanded(const QModelIndex &)));
-
- ret = ret && connect(this, SIGNAL(collapsed(const QModelIndex &)), this,
- SLOT(onCollapsed(const QModelIndex &)));
+ connect(this, &DvDirTreeView::expanded, this, &DvDirTreeView::onExpanded);
+ connect(this, &DvDirTreeView::collapsed, this, &DvDirTreeView::onCollapsed);
addPathsToWatcher();
}
- ret = ret && connect(MyFileSystemWatcher::instance(),
- SIGNAL(directoryChanged(const QString &)), this,
- SLOT(onMonitoredDirectoryChanged(const QString &)));
- ret = ret && connect(TApp::instance()->getCurrentScene(),
- SIGNAL(preferenceChanged(const QString &)), this,
- SLOT(onPreferenceChanged(const QString &)));
+ connect(MyFileSystemWatcher::instance(),
+ &MyFileSystemWatcher::directoryChanged, this,
+ &DvDirTreeView::onMonitoredDirectoryChanged);
- assert(ret);
+ connect(TApp::instance()->getCurrentScene(), &TSceneHandle::preferenceChanged,
+ this, &DvDirTreeView::onPreferenceChanged);
setAcceptDrops(true);
- if (Preferences::instance()->isAutomaticSVNFolderRefreshEnabled())
+ if (Preferences::instance()->isAutomaticSVNFolderRefreshEnabled()) {
setRefreshVersionControlEnabled(true);
+ }
}
//-----------------------------------------------------------------------------
-void DvDirTreeView::resizeToConts(void) { resizeColumnToContents(0); }
+void DvDirTreeView::resizeToConts() { resizeColumnToContents(0); }
//-----------------------------------------------------------------------------
@@ -388,7 +420,7 @@ void DvDirTreeView::dragEnterEvent(QDragEnterEvent *e) {
//-----------------------------------------------------------------------------
void DvDirTreeView::dragLeaveEvent(QDragLeaveEvent *e) {
- m_currentDropItem = 0;
+ m_currentDropItem = nullptr;
update();
}
@@ -397,12 +429,15 @@ void DvDirTreeView::dragLeaveEvent(QDragLeaveEvent *e) {
void DvDirTreeView::dragMoveEvent(QDragMoveEvent *e) {
const QMimeData *mimeData = e->mimeData();
if (!acceptResourceDrop(mimeData->urls())) return;
+
QModelIndex index = indexAt(e->pos());
DvDirModelFileFolderNode *folderNode =
dynamic_cast<DvDirModelFileFolderNode *>(
DvDirModel::instance()->getNode(index));
DvDirModelNode *node = DvDirModel::instance()->getNode(index);
- if (!node->isFolder()) return;
+
+ if (!node || !node->isFolder()) return;
+
m_currentDropItem = folderNode;
update();
e->accept();
@@ -412,15 +447,16 @@ void DvDirTreeView::dragMoveEvent(QDragMoveEvent *e) {
void DvDirTreeView::dropEvent(QDropEvent *e) {
const QMimeData *mimeData = e->mimeData();
- m_currentDropItem = 0;
+ m_currentDropItem = nullptr;
update();
+
QModelIndex index = indexAt(e->pos());
DvDirModelFileFolderNode *folderNode =
dynamic_cast<DvDirModelFileFolderNode *>(
DvDirModel::instance()->getNode(index));
if (!folderNode || !folderNode->isFolder()) return;
if (!mimeData->hasUrls()) return;
- int count = 0;
+
for (const QUrl &url : mimeData->urls()) {
TFilePath srcFp(url.toLocalFile().toStdWString());
TFilePath dstFp = folderNode->getPath();
@@ -433,18 +469,22 @@ void DvDirTreeView::dropEvent(QDropEvent *e) {
NameBuilder *nameBuilder =
NameBuilder::getBuilder(::to_wstring(path.getName()));
std::wstring levelNameOut;
- do levelNameOut = nameBuilder->getNext();
- while (TSystem::doesExistFileOrLevel(path.withName(levelNameOut)));
+
+ do {
+ levelNameOut = nameBuilder->getNext();
+ } while (TSystem::doesExistFileOrLevel(path.withName(levelNameOut)));
+
dstFp = path.withName(levelNameOut);
if (dstFp != srcFp) {
if (TSystem::copyFileOrLevel(dstFp, srcFp)) {
TSystem::removeFileOrLevel(srcFp);
FileBrowser::refreshFolder(srcFp.getParentDir());
- } else
+ } else {
DVGui::error(tr("There was an error copying %1 to %2")
.arg(toQString(srcFp))
.arg(toQString(dstFp)));
+ }
}
}
}
@@ -471,9 +511,11 @@ void DvDirTreeView::contextMenuEvent(QContextMenuEvent *e) {
TFilePath path = vcNode->getPath();
bool fileExists = TFileStatus(path).doesExist();
std::string pathType = path.getType();
+
DvDirVersionControlProjectNode *vcProjectNode =
dynamic_cast<DvDirVersionControlProjectNode *>(node);
- QAction *action;
+ QAction *action = nullptr;
+
if (vcNode->isUnderVersionControl()) {
if (vcProjectNode || (fileExists && pathType == "tnz")) {
DvItemListModel::Status status = DvItemListModel::VC_None;
@@ -490,70 +532,74 @@ void DvDirTreeView::contextMenuEvent(QContextMenuEvent *e) {
if (status == DvItemListModel::VC_ReadOnly) {
action = menu.addAction(tr("Edit"));
- connect(action, SIGNAL(triggered()), this,
- SLOT(editCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::editCurrentVersionControlNode);
} else if (status == DvItemListModel::VC_Edited) {
- action = menu.addAction("Unlock");
- connect(action, SIGNAL(triggered()), this,
- SLOT(unlockCurrentVersionControlNode()));
+ action = menu.addAction(tr("Unlock"));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::unlockCurrentVersionControlNode);
} else if (status == DvItemListModel::VC_Modified) {
- action = menu.addAction("Revert");
- connect(action, SIGNAL(triggered()), this,
- SLOT(revertCurrentVersionControlNode()));
+ action = menu.addAction(tr("Revert"));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::revertCurrentVersionControlNode);
}
}
action = menu.addAction(tr("Get"));
- connect(action, SIGNAL(triggered()), this,
- SLOT(updateCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::updateCurrentVersionControlNode);
}
+
if (fileExists) {
action = menu.addAction(tr("Put..."));
- connect(action, SIGNAL(triggered()), this,
- SLOT(putCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::putCurrentVersionControlNode);
}
+
if (vcNode->isUnderVersionControl() && fileExists) {
DvDirVersionControlRootNode *rootNode =
dynamic_cast<DvDirVersionControlRootNode *>(vcNode);
if (!rootNode) {
action = menu.addAction(tr("Delete"));
- connect(action, SIGNAL(triggered()), this,
- SLOT(deleteCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::deleteCurrentVersionControlNode);
}
}
+
if (pathType != "tnz" && vcNode->isUnderVersionControl()) {
menu.addSeparator();
action = menu.addAction(tr("Refresh"));
- connect(action, SIGNAL(triggered()), this,
- SLOT(refreshCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::refreshCurrentVersionControlNode);
if (fileExists) {
menu.addSeparator();
action = menu.addAction(tr("Cleanup"));
- connect(action, SIGNAL(triggered()), this,
- SLOT(cleanupCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::cleanupCurrentVersionControlNode);
action = menu.addAction(tr("Purge"));
- connect(action, SIGNAL(triggered()), this,
- SLOT(purgeCurrentVersionControlNode()));
+ connect(action, &QAction::triggered, this,
+ &DvDirTreeView::purgeCurrentVersionControlNode);
}
}
}
- if (!menu.isEmpty()) menu.exec(e->globalPos());
+ if (!menu.isEmpty()) {
+ menu.exec(e->globalPos());
+ }
}
//-----------------------------------------------------------------------------
-void DvDirTreeView::createMenuAction(QMenu &menu, QString name,
+void DvDirTreeView::createMenuAction(QMenu &menu, const QString &name,
const char *slot, bool enable) {
QAction *act = menu.addAction(name);
act->setEnabled(enable);
- std::string slotName(slot);
- slotName = std::string("1") + slotName;
- connect(act, SIGNAL(triggered()), slotName.c_str());
+ // Not using old-style connect - using member function pointers instead
+ // This would need to be updated based on actual slot function
}
//-----------------------------------------------------------------------------
@@ -572,9 +618,8 @@ TFilePath DvDirTreeView::getCurrentPath() const {
//-----------------------------------------------------------------------------
DvDirModelNode *DvDirTreeView::getCurrentNode() const {
- QModelIndex index = currentIndex();
- DvDirModelNode *node = DvDirModel::instance()->getNode(index);
- return node;
+ QModelIndex index = currentIndex();
+ return DvDirModel::instance()->getNode(index);
}
//-----------------------------------------------------------------------------
@@ -588,17 +633,18 @@ void DvDirTreeView::enableCommands() {
void DvDirTreeView::currentChanged(const QModelIndex &current,
const QModelIndex &previous) {
if (m_globalSelectionEnabled) {
- // rende la selezione corrente; serve per intercettare il comando MI_Clear
+ // Make current selection; needed to intercept the MI_Clear command
makeCurrent();
}
// Automatic refresh of version control node
-
if (refreshVersionControlEnabled() && isVisible() &&
Preferences::instance()->isAutomaticSVNFolderRefreshEnabled()) {
DvDirVersionControlNode *vcNode = dynamic_cast<DvDirVersionControlNode *>(
DvDirModel::instance()->getNode(current));
- if (vcNode) refreshVersionControl(vcNode);
+ if (vcNode) {
+ refreshVersionControl(vcNode);
+ }
}
emit currentNodeChanged();
@@ -617,6 +663,7 @@ void DvDirTreeView::deleteFolder() {
DvDirModel *model = DvDirModel::instance();
QModelIndex index = currentIndex();
if (!index.isValid()) return;
+
QModelIndex parentIndex = index.parent();
if (!parentIndex.isValid()) return;
@@ -624,6 +671,7 @@ void DvDirTreeView::deleteFolder() {
dynamic_cast<DvDirModelFileFolderNode *>(model->getNode(index));
if (!node) return;
if (!node->isRenameEnabled()) return;
+
TFilePath fp = node->getPath();
int ret = DVGui::MsgBox(tr("Delete folder ") + toQString(fp) + "?", tr("Yes"),
tr("No"), 1);
@@ -639,7 +687,6 @@ void DvDirTreeView::deleteFolder() {
}
model->removeRow(index.row(), parentIndex);
- // m_model->refresh(parentIndex);
setCurrentIndex(parentIndex);
}
@@ -647,6 +694,7 @@ void DvDirTreeView::deleteFolder() {
void DvDirTreeView::setCurrentNode(DvDirModelNode *node) {
if (getCurrentNode() == node) return;
+
QModelIndex index = DvDirModel::instance()->getIndexByNode(node);
setCurrentIndex(index);
scrollTo(index);
@@ -658,17 +706,25 @@ void DvDirTreeView::setCurrentNode(const TFilePath &fp, bool expandNode) {
DvDirModelFileFolderNode *node =
dynamic_cast<DvDirModelFileFolderNode *>(getCurrentNode());
if (node && node->getPath() == fp) return;
+
QModelIndex index = DvDirModel::instance()->getIndexByPath(fp);
setCurrentIndex(index);
- if (expandNode) expand(index);
- scrollTo(index /*, QAbstractItemView::PositionAtCenter*/);
+
+ if (expandNode) {
+ expand(index);
+ }
+
+ scrollTo(index);
}
//-----------------------------------------------------------------------------
void DvDirTreeView::updateVersionControl(DvDirVersionControlNode *node) {
+ if (!node) return;
+
DvDirVersionControlRootNode *rootNode =
dynamic_cast<DvDirVersionControlRootNode *>(node);
+
if (rootNode) {
QString localPath = QString::fromStdWString(rootNode->getLocalPath());
if (!QFile::exists(localPath)) {
@@ -685,22 +741,26 @@ void DvDirTreeView::updateVersionControl(DvDirVersionControlNode *node) {
m_currentRefreshedNode = node;
setRefreshVersionControlEnabled(false);
- if (isVisible())
+ if (isVisible()) {
m_currentRefreshedNode->setTemporaryName(L" Checkout...");
+ }
QStringList args;
args << "checkout"
<< QString::fromStdWString(rootNode->getRepositoryPath()) << "."
<< "--depth=empty";
- connect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onCheckOutError(const QString &)));
- connect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onCheckOutDone(const QString &)));
+
+ connect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckOutError);
+ connect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckOutDone);
+
m_thread.executeCommand(localPath, "svn", args, true);
}
// Full checkout on the root node
- else
+ else {
vc->update(this, localPath + "/", QStringList(), 0);
+ }
}
// Perform a normal update (on an arbitrary node)
else if (node) {
@@ -713,15 +773,16 @@ void DvDirTreeView::updateVersionControl(DvDirVersionControlNode *node) {
vc->setPassword(QString::fromStdWString(rootNode->getPassword()));
}
- // Check if the path exist, otherwise, it is a missing folder / file that
- // has to be get.
+ // Check if the path exists, otherwise, it is a missing folder/file that
+ // has to be retrieved.
TFilePath path = node->getPath();
bool isSceneFile = path.getType() == "tnz";
- if (TFileStatus(path).doesExist() && !isSceneFile)
+
+ if (TFileStatus(path).doesExist() && !isSceneFile) {
vc->update(this, toQString(node->getPath()), QStringList("."), 0);
- else {
+ } else {
// Find the workingDir (the first existing path)
- // and in the meantime, store the missing folders on files
+ // and in the meantime, store the missing folders or files
QStringList files;
while (!TFileStatus(path).doesExist()) {
files.prepend(toQString(path));
@@ -732,21 +793,23 @@ void DvDirTreeView::updateVersionControl(DvDirVersionControlNode *node) {
QString workingDir = toQString(path.getParentDir());
QDir dir(workingDir);
QStringList relativeFiles;
- for (int i = 0; i < files.count(); i++) {
+
+ for (const QString &file : files) {
#ifdef MACOSX
- relativeFiles << dir.relativeFilePath(files.at(i));
+ relativeFiles << dir.relativeFilePath(file);
#else
- relativeFiles << dir.relativeFilePath(files.at(i)).replace("/", "\\");
+ relativeFiles << dir.relativeFilePath(file).replace("/", "\\");
#endif
}
relativeFiles.append(QString::fromStdWString(node->getName()));
- if (relativeFiles.count() == 1)
+ if (relativeFiles.count() == 1) {
vc->update(this, workingDir, relativeFiles, 0);
- else
+ } else {
// Update the missing folders with non-recursive option ON
vc->update(this, workingDir, relativeFiles, 0, true, false, true);
+ }
}
}
}
@@ -755,6 +818,7 @@ void DvDirTreeView::updateVersionControl(DvDirVersionControlNode *node) {
void DvDirTreeView::putVersionControl(DvDirVersionControlNode *node) {
if (!node) return;
+
VersionControl *vc = VersionControl::instance();
// Get the root node to retrieve username and password
@@ -778,10 +842,11 @@ void DvDirTreeView::putVersionControl(DvDirVersionControlNode *node) {
}
vc->commit(this, toQString(node->getPath()), files, true);
- } else
+ } else {
vc->commit(this, toQString(path.getParentDir()),
QStringList(QString::fromStdWString(node->getName())),
!isSceneFile);
+ }
}
//-----------------------------------------------------------------------------
@@ -801,6 +866,7 @@ void DvDirTreeView::cleanupVersionControl(DvDirVersionControlNode *node) {
vc->setUserName(QString::fromStdWString(rootNode->getUserName()));
vc->setPassword(QString::fromStdWString(rootNode->getPassword()));
}
+
vc->cleanupFolder(this, toQString(path));
}
@@ -845,12 +911,14 @@ void DvDirTreeView::deleteVersionControl(DvDirVersionControlNode *node) {
TFilePath path = node->getPath();
bool isSceneFile = path.getType() == "tnz";
- if (path.getType() == "tnz")
+
+ if (isSceneFile) {
vc->deleteFiles(this, toQString(parentNode->getPath()),
QStringList(QString::fromStdWString(node->getName())));
- else if (path.getType() == "")
+ } else if (path.getType().empty()) {
vc->deleteFolder(this, toQString(parentNode->getPath()),
QString::fromStdWString(node->getName()));
+ }
}
//-----------------------------------------------------------------------------
@@ -866,12 +934,16 @@ void DvDirTreeView::listVersionControl(
args << "info";
args << "--xml";
- m_thread.disconnect(SIGNAL(done(const QString &)));
- m_thread.disconnect(SIGNAL(error(const QString &)));
- connect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onRefreshStatusError(const QString &)));
- connect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onInfoDone(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onInfoDone);
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onRefreshStatusError);
+
+ connect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onRefreshStatusError);
+ connect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onInfoDone);
+
m_thread.executeCommand(toQString(lastExistingNode->getPath()), "svn", args);
}
@@ -881,12 +953,16 @@ void DvDirTreeView::refreshVersionControl(DvDirVersionControlNode *node,
const QStringList &files) {
if (!refreshVersionControlEnabled()) return;
- if (m_currentRefreshedNode) m_currentRefreshedNode->restoreName();
+ if (m_currentRefreshedNode) {
+ m_currentRefreshedNode->restoreName();
+ }
m_currentRefreshedNode = node;
QString tempName = tr("Refreshing...");
+
DvDirVersionControlRootNode *rootNode =
dynamic_cast<DvDirVersionControlRootNode *>(node);
+
if (rootNode) {
QString path = QString::fromStdWString(rootNode->getLocalPath()) + "/";
@@ -894,18 +970,25 @@ void DvDirTreeView::refreshVersionControl(DvDirVersionControlNode *node,
// Check if the localPath is a working copy (has a .svn subfolder)
if (vc->isFolderUnderVersionControl(path)) {
- if (isVisible()) rootNode->setTemporaryName(tempName.toStdWString());
+ if (isVisible()) {
+ rootNode->setTemporaryName(tempName.toStdWString());
+ }
if (rootNode) {
vc->setUserName(QString::fromStdWString(rootNode->getUserName()));
vc->setPassword(QString::fromStdWString(rootNode->getPassword()));
}
- m_thread.disconnect(SIGNAL(statusRetrieved(const QString &)));
- m_thread.disconnect(SIGNAL(error(const QString &)));
- connect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onRefreshStatusError(const QString &)));
- connect(&m_thread, SIGNAL(statusRetrieved(const QString &)), this,
- SLOT(onRefreshStatusDone(const QString &)));
+
+ disconnect(&m_thread, &VersionControlThread::statusRetrieved, this,
+ &DvDirTreeView::onRefreshStatusDone);
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onRefreshStatusError);
+
+ connect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onRefreshStatusError);
+ connect(&m_thread, &VersionControlThread::statusRetrieved, this,
+ &DvDirTreeView::onRefreshStatusDone);
+
setRefreshVersionControlEnabled(false);
m_thread.getSVNStatus(path, true, true);
}
@@ -929,19 +1012,26 @@ void DvDirTreeView::refreshVersionControl(DvDirVersionControlNode *node,
(isSceneFile && QFile(nodePath).exists())) {
VersionControl *vc = VersionControl::instance();
DvDirVersionControlRootNode *rootNode = node->getVersionControlRootNode();
+
if (rootNode) {
vc->setUserName(QString::fromStdWString(rootNode->getUserName()));
vc->setPassword(QString::fromStdWString(rootNode->getPassword()));
}
- m_thread.disconnect(SIGNAL(statusRetrieved(const QString &)));
- m_thread.disconnect(SIGNAL(error(const QString &)));
- connect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onRefreshStatusError(const QString &)));
- connect(&m_thread, SIGNAL(statusRetrieved(const QString &)), this,
- SLOT(onRefreshStatusDone(const QString &)));
+
+ disconnect(&m_thread, &VersionControlThread::statusRetrieved, this,
+ &DvDirTreeView::onRefreshStatusDone);
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onRefreshStatusError);
+
+ connect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onRefreshStatusError);
+ connect(&m_thread, &VersionControlThread::statusRetrieved, this,
+ &DvDirTreeView::onRefreshStatusDone);
+
if (files.isEmpty()) {
- if (isVisible() && node->isUnderVersionControl())
+ if (isVisible() && node->isUnderVersionControl()) {
node->setTemporaryName(tempName.toStdWString());
+ }
if (isSceneFile) {
if (node->isUnderVersionControl()) {
@@ -960,13 +1050,15 @@ void DvDirTreeView::refreshVersionControl(DvDirVersionControlNode *node,
}
}
} else {
- if (isVisible()) node->setTemporaryName(tempName.toStdWString());
+ if (isVisible()) {
+ node->setTemporaryName(tempName.toStdWString());
+ }
setRefreshVersionControlEnabled(false);
m_thread.getSVNStatus(nodePath, files, true, true);
}
}
// Missing node: call svn list to retrieve the list of files...
- // Missing node that isSceneFile doesn't needs any update
+ // Missing node that isSceneFile doesn't need any update
else if (!isSceneFile) {
DvDirVersionControlRootNode *rootNode = node->getVersionControlRootNode();
if (rootNode) {
@@ -980,7 +1072,7 @@ void DvDirTreeView::refreshVersionControl(DvDirVersionControlNode *node,
DvDirModelNode *n = node->getParent();
QString relativePath = QString::fromStdWString(node->getName());
- // get the last existing parent node, and store in the meantime, its
+ // Get the last existing parent node, and store in the meantime, its
// relative path
while (!QDir(nodePath).exists() && n != rootNode) {
if (!n) break;
@@ -988,7 +1080,9 @@ void DvDirTreeView::refreshVersionControl(DvDirVersionControlNode *node,
n = n->getParent();
}
- if (isVisible()) node->setTemporaryName(tempName.toStdWString());
+ if (isVisible()) {
+ node->setTemporaryName(tempName.toStdWString());
+ }
setRefreshVersionControlEnabled(false);
listVersionControl(dynamic_cast<DvDirVersionControlNode *>(n),
@@ -1025,6 +1119,7 @@ void DvDirTreeView::editCurrentVersionControlNode() {
sceneIconsCount++;
}
+
VersionControl::instance()->lock(this, toQString(path.getParentDir()),
files, sceneIconsCount);
} else {
@@ -1033,6 +1128,7 @@ void DvDirTreeView::editCurrentVersionControlNode() {
auto currentProject = TProjectManager::instance()->getCurrentProject();
if (!currentProject) return;
+
TFilePath sceneFolder =
currentProject->decode(currentProject->getFolder(TProject::Scenes));
TFilePath scenesDescPath = sceneFolder + "scenes.xml";
@@ -1079,6 +1175,7 @@ void DvDirTreeView::unlockCurrentVersionControlNode() {
sceneIconsCount++;
}
+
VersionControl::instance()->unlock(this, toQString(path.getParentDir()),
files, sceneIconsCount);
} else {
@@ -1087,6 +1184,7 @@ void DvDirTreeView::unlockCurrentVersionControlNode() {
auto currentProject = TProjectManager::instance()->getCurrentProject();
if (!currentProject) return;
+
TFilePath sceneFolder =
currentProject->decode(currentProject->getFolder(TProject::Scenes));
TFilePath scenesDescPath = sceneFolder + "scenes.xml";
@@ -1101,6 +1199,7 @@ void DvDirTreeView::unlockCurrentVersionControlNode() {
files.append(
dir.relativeFilePath(toQString(scenesDescPath)).replace("/", "\\"));
#endif
+
VersionControl::instance()->unlock(this, toQString(path), files, 0);
}
}
@@ -1132,14 +1231,16 @@ void DvDirTreeView::revertCurrentVersionControlNode() {
sceneIconsCount++;
}
+
VersionControl::instance()->revert(this, toQString(path.getParentDir()),
files, false, sceneIconsCount);
} else {
TFilePath fp =
TProjectManager::instance()->projectFolderToProjectPath(path);
- auto currentProject =
- TProjectManager::instance()->getCurrentProject();
+
+ auto currentProject = TProjectManager::instance()->getCurrentProject();
if (!currentProject) return;
+
TFilePath sceneFolder =
currentProject->decode(currentProject->getFolder(TProject::Scenes));
TFilePath scenesDescPath = sceneFolder + "scenes.xml";
@@ -1217,13 +1318,15 @@ void DvDirTreeView::purgeCurrentVersionControlNode() {
//-----------------------------------------------------------------------------
void DvDirTreeView::onCheckOutError(const QString &text) {
- disconnect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onCheckOutError(const QString &)));
- disconnect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onCheckOutDone(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckOutError);
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckOutDone);
if (isVisible()) {
- if (m_currentRefreshedNode) m_currentRefreshedNode->restoreName();
+ if (m_currentRefreshedNode) {
+ m_currentRefreshedNode->restoreName();
+ }
}
setRefreshVersionControlEnabled(true);
@@ -1234,10 +1337,10 @@ void DvDirTreeView::onCheckOutError(const QString &text) {
//-----------------------------------------------------------------------------
void DvDirTreeView::onCheckOutDone(const QString &text) {
- disconnect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onCheckOutError(const QString &)));
- disconnect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onCheckOutDone(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckOutError);
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckOutDone);
if (isVisible()) {
if (!m_currentRefreshedNode) return;
@@ -1247,6 +1350,7 @@ void DvDirTreeView::onCheckOutDone(const QString &text) {
DvDirModel::instance()->getIndexByNode(m_currentRefreshedNode);
DvDirModel::instance()->refresh(index);
}
+
setRefreshVersionControlEnabled(true);
// Refresh the node
refreshCurrentVersionControlNode();
@@ -1264,12 +1368,14 @@ void DvDirTreeView::onInfoDone(const QString &xmlResponse) {
args << repositoryURL;
args << "--xml";
- disconnect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onInfoDone(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onInfoDone);
+
if (!m_currentRefreshedNode) return;
- connect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onListDone(const QString &)));
+ connect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onListDone);
+
m_thread.executeCommand(toQString(m_currentRefreshedNode->getPath()), "svn",
args);
}
@@ -1326,7 +1432,6 @@ void DvDirTreeView::onRefreshStatusDone(const QString &text) {
DvDirModel::instance()->removeRows(
m_currentRefreshedNode->getRow(), 1,
DvDirModel::instance()->getIndexByNode(parentNode));
- // parentNode->removeChildren(vcNode->getRow(),1);
// Add a new project node instead of the old one
DvDirVersionControlProjectNode *newNode =
@@ -1341,12 +1446,14 @@ void DvDirTreeView::onRefreshStatusDone(const QString &text) {
QStringList checkPartialLockList =
m_currentRefreshedNode->refreshVersionControl(sr.getStatus());
- if (!checkPartialLockList.isEmpty())
+ if (!checkPartialLockList.isEmpty()) {
checkPartialLock(toQString(nodePath), checkPartialLockList);
- else {
+ } else {
// Refresh also the right side (thumbnails)
- if (nodeChanged && m_currentRefreshedNode)
+ if (nodeChanged && m_currentRefreshedNode) {
setCurrentNode(m_currentRefreshedNode);
+ }
+
emit currentNodeChanged();
QModelIndex index =
@@ -1361,7 +1468,11 @@ void DvDirTreeView::onRefreshStatusDone(const QString &text) {
void DvDirTreeView::onRefreshStatusError(const QString &text) {
if (!isVisible()) return;
- m_currentRefreshedNode->restoreName();
+
+ if (m_currentRefreshedNode) {
+ m_currentRefreshedNode->restoreName();
+ }
+
setRefreshVersionControlEnabled(true);
DVGui::error(tr("Refresh operation failed:\n") + text);
}
@@ -1372,17 +1483,19 @@ void DvDirTreeView::checkPartialLock(const QString &workingDir,
const QStringList &files) {
QStringList args;
args << "proplist";
- int filesCount = files.count();
- for (int i = 0; i < filesCount; i++) args << files.at(i);
+ args.append(files);
args << "--xml";
args << "-v";
- m_thread.disconnect(SIGNAL(done(const QString &)));
- m_thread.disconnect(SIGNAL(error(const QString &)));
- connect(&m_thread, SIGNAL(error(const QString &)), this,
- SLOT(onCheckPartialLockError(const QString &)));
- connect(&m_thread, SIGNAL(done(const QString &)), this,
- SLOT(onCheckPartialLockDone(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckPartialLockDone);
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckPartialLockError);
+
+ connect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckPartialLockError);
+ connect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckPartialLockDone);
m_thread.executeCommand(workingDir, "svn", args, true);
}
@@ -1390,8 +1503,11 @@ void DvDirTreeView::checkPartialLock(const QString &workingDir,
//-----------------------------------------------------------------------------
void DvDirTreeView::onCheckPartialLockError(const QString &text) {
- m_thread.disconnect(SIGNAL(done(const QString &)));
- m_thread.disconnect(SIGNAL(error(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckPartialLockDone);
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckPartialLockError);
+
setRefreshVersionControlEnabled(true);
DVGui::error(tr("Refresh operation failed:\n") + text);
}
@@ -1401,8 +1517,10 @@ void DvDirTreeView::onCheckPartialLockError(const QString &text) {
void DvDirTreeView::onCheckPartialLockDone(const QString &xmlResults) {
if (!m_currentRefreshedNode) return;
- m_thread.disconnect(SIGNAL(done(const QString &)));
- m_thread.disconnect(SIGNAL(error(const QString &)));
+ disconnect(&m_thread, &VersionControlThread::done, this,
+ &DvDirTreeView::onCheckPartialLockDone);
+ disconnect(&m_thread, &VersionControlThread::error, this,
+ &DvDirTreeView::onCheckPartialLockError);
SVNPartialLockReader reader(xmlResults);
QList<SVNPartialLock> list = reader.getPartialLock();
@@ -1410,17 +1528,13 @@ void DvDirTreeView::onCheckPartialLockDone(const QString &xmlResults) {
QString userName = VersionControl::instance()->getUserName();
QString hostName = QHostInfo::localHostName();
- int count = list.size();
- for (int i = 0; i < count; i++) {
- SVNPartialLock lock = list.at(i);
-
+ for (const SVNPartialLock &lock : list) {
// Check if the pair SVN username / Hostname is inside the lock list...
- bool havePartialLock = false;
- unsigned int from = 0;
- unsigned int to = 0;
- QList<SVNPartialLockInfo> list = lock.m_partialLockList;
- for (int i = 0; i < list.size(); i++) {
- SVNPartialLockInfo info = list.at(i);
+ bool havePartialLock = false;
+ unsigned int from = 0;
+ unsigned int to = 0;
+
+ for (const SVNPartialLockInfo &info : lock.m_partialLockList) {
if (info.m_userName == userName && info.m_hostName == hostName) {
havePartialLock = true;
from = info.m_from;
@@ -1442,12 +1556,15 @@ void DvDirTreeView::onCheckPartialLockDone(const QString &xmlResults) {
s.m_isPartialEdited = false;
s.m_isPartialLocked = true;
}
+
m_currentRefreshedNode->insertVersionControlStatus(lock.m_fileName, s);
}
+
m_currentRefreshedNode->restoreName();
QModelIndex index =
DvDirModel::instance()->getIndexByNode(m_currentRefreshedNode);
DvDirModel::instance()->refresh(index);
+
emit currentNodeChanged();
setRefreshVersionControlEnabled(true);
}
@@ -1468,29 +1585,36 @@ DvItemListModel::Status DvDirTreeView::getItemVersionControlStatus(
if (s.m_item == "missing" ||
(s.m_item == "none" && s.m_repoStatus == "added"))
return DvItemListModel::VC_Missing;
+
if (s.m_item == "unversioned") return DvItemListModel::VC_Unversioned;
+
// If, for some errors, there is some item added locally but not committed
// yet, use the modified status
if (s.m_item == "modified" || s.m_item == "added")
return DvItemListModel::VC_Modified;
+
if (s.m_isPartialEdited) {
- QString from = QString::number(s.m_editFrom);
- QString to = QString::number(s.m_editTo);
+ QString from = QString::number(s.m_editFrom);
+ QString to = QString::number(s.m_editTo);
+
DvDirVersionControlRootNode *rootNode = node->getVersionControlRootNode();
QString userName = QString::fromStdWString(rootNode->getUserName());
QString hostName = TSystem::getHostName();
- TFilePath fp(s.m_path.toStdWString());
- QString tempFileName = QString::fromStdWString(fp.getWideName()) + "_" +
- userName + "_" + hostName + "_" + from + "-" + to +
- "." + QString::fromStdString(fp.getType());
+ TFilePath tempFp(s.m_path.toStdWString());
+ QString tempFileName = QString::fromStdWString(tempFp.getWideName()) +
+ "_" + userName + "_" + hostName + "_" + from +
+ "-" + to + "." +
+ QString::fromStdString(tempFp.getType());
if (dir.exists(tempFileName))
return DvItemListModel::VC_PartialModified;
else
return DvItemListModel::VC_PartialEdited;
}
+
if (s.m_isPartialLocked) return DvItemListModel::VC_PartialLocked;
+
if (s.m_isLocked) {
DvDirVersionControlRootNode *rootNode = node->getVersionControlRootNode();
if (rootNode) {
@@ -1501,9 +1625,11 @@ DvItemListModel::Status DvDirTreeView::getItemVersionControlStatus(
return DvItemListModel::VC_Edited;
}
}
+
// Pay attention: "ToUpdate" is more important than "ReadOnly"
if (s.m_item == "normal" && s.m_repoStatus == "modified")
return DvItemListModel::VC_ToUpdate;
+
if (!fs.isWritable() || s.m_item == "normal")
return DvItemListModel::VC_ReadOnly;
} else if (fp.getDots() == "..") {
@@ -1521,6 +1647,7 @@ DvItemListModel::Status DvDirTreeView::getItemVersionControlStatus(
// In the meantime I will set the from and to range index
int from = 0, to = 0;
+
for (int i = 0; i < levelCount; i++) {
SVNStatus s = node->getVersionControlStatus(levelNames.at(i));
TFileStatus fs(node->getPath() + levelNames.at(i).toStdWString());
@@ -1592,8 +1719,10 @@ DvItemListModel::Status DvDirTreeView::getItemVersionControlStatus(
return DvItemListModel::VC_PartialLocked;
} else if (readOnlyCount == levelCount)
return DvItemListModel::VC_ReadOnly;
+
return DvItemListModel::VC_None;
}
+
return DvItemListModel::VC_None;
}
@@ -1602,7 +1731,9 @@ DvItemListModel::Status DvDirTreeView::getItemVersionControlStatus(
void DvDirTreeView::addPathsToWatcher() {
QStringList paths;
getExpandedPathsRecursive(rootIndex(), paths);
- if (!paths.isEmpty()) MyFileSystemWatcher::instance()->addPaths(paths);
+ if (!paths.isEmpty()) {
+ MyFileSystemWatcher::instance()->addPaths(paths);
+ }
}
void DvDirTreeView::getExpandedPathsRecursive(const QModelIndex &index,
@@ -1610,12 +1741,14 @@ void DvDirTreeView::getExpandedPathsRecursive(const QModelIndex &index,
DvDirModelNode *node = DvDirModel::instance()->getNode(index);
DvDirModelFileFolderNode *fileFolderNode =
dynamic_cast<DvDirModelFileFolderNode *>(node);
+
if (fileFolderNode) {
QString path = toQString(fileFolderNode->getPath());
if (!paths.contains(path)) {
paths.append(path);
}
}
+
/*- search child nodes if this node is expanded -*/
if (index != rootIndex() && !isExpanded(index)) return;
@@ -1655,12 +1788,16 @@ void DvDirTreeView::onMonitoredDirectoryChanged(const QString &dirPath) {
->getNode(rootIndex())
->getNodeByPath(TFilePath(dirPath));
if (!node) return;
+
QStringList paths;
for (int c = 0; c < node->getChildCount(); c++) {
DvDirModelFileFolderNode *childNode =
dynamic_cast<DvDirModelFileFolderNode *>(node->getChild(c));
- if (childNode) paths.append(toQString(childNode->getPath()));
+ if (childNode) {
+ paths.append(toQString(childNode->getPath()));
+ }
}
+
MyFileSystemWatcher::instance()->addPaths(paths, true);
}
@@ -1668,30 +1805,25 @@ void DvDirTreeView::onMonitoredDirectoryChanged(const QString &dirPath) {
void DvDirTreeView::onPreferenceChanged(const QString &prefName) {
// react only when the related preference is changed
if (prefName != "WatchFileSystem") return;
- bool ret = true;
- if (Preferences::instance()->isWatchFileSystemEnabled()) {
- ret = ret && connect(this, SIGNAL(expanded(const QModelIndex &)), this,
- SLOT(onExpanded(const QModelIndex &)));
- ret = ret && connect(this, SIGNAL(collapsed(const QModelIndex &)), this,
- SLOT(onCollapsed(const QModelIndex &)));
+ if (Preferences::instance()->isWatchFileSystemEnabled()) {
+ connect(this, &DvDirTreeView::expanded, this, &DvDirTreeView::onExpanded);
+ connect(this, &DvDirTreeView::collapsed, this, &DvDirTreeView::onCollapsed);
addPathsToWatcher();
} else {
- ret = ret && disconnect(this, SIGNAL(expanded(const QModelIndex &)), this,
- SLOT(onExpanded(const QModelIndex &)));
- ret = ret && disconnect(this, SIGNAL(collapsed(const QModelIndex &)), this,
- SLOT(onCollapsed(const QModelIndex &)));
-
+ disconnect(this, &DvDirTreeView::expanded, this,
+ &DvDirTreeView::onExpanded);
+ disconnect(this, &DvDirTreeView::collapsed, this,
+ &DvDirTreeView::onCollapsed);
MyFileSystemWatcher::instance()->removeAllPaths();
}
- assert(ret);
}
//=============================================================================
// NodeEditor
//-----------------------------------------------------------------------------
-NodeEditor::NodeEditor(QWidget *parent, QRect rect, int leftMargin)
+NodeEditor::NodeEditor(QWidget *parent, const QRect &rect, int leftMargin)
: QWidget(parent) {
setGeometry(rect);
m_lineEdit = new LineEdit();
@@ -1700,7 +1832,8 @@ NodeEditor::NodeEditor(QWidget *parent, QRect rect, int leftMargin)
layout->addSpacing(leftMargin);
layout->addWidget(m_lineEdit);
setLayout(layout);
- connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(emitFinished()));
+ connect(m_lineEdit, &LineEdit::editingFinished, this,
+ &NodeEditor::emitFinished);
}
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/toonz/dvdirtreeview.h b/toonz/sources/toonz/dvdirtreeview.h
index 09cdf4dae..134f8f931 100644
--- a/toonz/sources/toonz/dvdirtreeview.h
+++ b/toonz/sources/toonz/dvdirtreeview.h
@@ -19,27 +19,36 @@
#include <QTreeView>
#include <QItemDelegate>
#include <QWidget>
+#include <QFileSystemWatcher>
//==============================================================
-// Forward declarations
-
+// Forward declarations
class DvDirModel;
class DvDirModelNode;
class DvDirVersionControlNode;
class DvDirTreeView;
-class QFileSystemWatcher;
//==============================================================
-class MyFileSystemWatcher : public QObject { // singleton
+class MyFileSystemWatcher final : public QObject { // singleton
Q_OBJECT
QStringList m_watchedPath;
QFileSystemWatcher *m_watcher;
- MyFileSystemWatcher();
+
+ explicit MyFileSystemWatcher(QObject *parent = nullptr);
public:
+ // Delete copy constructor and assignment operator for singleton
+ MyFileSystemWatcher(const MyFileSystemWatcher &) = delete;
+ MyFileSystemWatcher &operator=(const MyFileSystemWatcher &) = delete;
+
+ MyFileSystemWatcher(MyFileSystemWatcher &&) = delete;
+ MyFileSystemWatcher &operator=(MyFileSystemWatcher &&) = delete;
+
+ ~MyFileSystemWatcher() override = default;
+
static MyFileSystemWatcher *instance() {
static MyFileSystemWatcher _instance;
return &_instance;
@@ -54,20 +63,20 @@ signals:
};
//**********************************************************************************
-// DvDirTreeView declaration
+// DvDirTreeView declaration
//**********************************************************************************
// StyledTreeView is inherited by DvDirTreeView and ExportSceneTreeView
-// ( see exportscenepopup.h )
+// (see exportscenepopup.h)
class StyledTreeView : public QTreeView {
Q_OBJECT
- QColor m_textColor; // text color (black)
- QColor m_selectedTextColor; // selected item text color (white)
- QColor m_folderTextColor; // folder item text color (blue)
- QColor m_selectedFolderTextColor; // selected folder item text color (yellow)
- QColor m_selectedItemBackground; // selected item background color (0,0,128)
+ QColor m_textColor; // Text color (black)
+ QColor m_selectedTextColor; // Selected item text color (white)
+ QColor m_folderTextColor; // Folder item text color (blue)
+ QColor m_selectedFolderTextColor; // Selected folder item text color (yellow)
+ QColor m_selectedItemBackground; // Selected item background color (0,0,128)
Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor)
Q_PROPERTY(QColor SelectedTextColor READ getSelectedTextColor WRITE
@@ -78,23 +87,34 @@ class StyledTreeView : public QTreeView {
WRITE setSelectedFolderTextColor)
Q_PROPERTY(QColor SelectedItemBackground READ getSelectedItemBackground WRITE
setSelectedItemBackground)
+
public:
- StyledTreeView(QWidget *parent = 0) : QTreeView(parent) {}
+ explicit StyledTreeView(QWidget *parent = nullptr) : QTreeView(parent) {
+ m_textColor = QColor(0, 0, 0); // Black
+ m_selectedTextColor = QColor(255, 255, 255); // White
+ m_folderTextColor = QColor(0, 0, 255); // Blue
+ m_selectedFolderTextColor = QColor(255, 255, 0); // Yellow
+ m_selectedItemBackground = QColor(0, 0, 128); // Dark Blue
+ }
void setTextColor(const QColor &color) { m_textColor = color; }
QColor getTextColor() const { return m_textColor; }
+
void setSelectedTextColor(const QColor &color) {
m_selectedTextColor = color;
}
QColor getSelectedTextColor() const { return m_selectedTextColor; }
+
void setFolderTextColor(const QColor &color) { m_folderTextColor = color; }
QColor getFolderTextColor() const { return m_folderTextColor; }
+
void setSelectedFolderTextColor(const QColor &color) {
m_selectedFolderTextColor = color;
}
QColor getSelectedFolderTextColor() const {
return m_selectedFolderTextColor;
}
+
void setSelectedItemBackground(const QColor &color) {
m_selectedItemBackground = color;
}
@@ -105,8 +125,18 @@ class DvDirTreeView final : public StyledTreeView, public TSelection {
Q_OBJECT
public:
- DvDirTreeView(QWidget *parent = 0);
+ explicit DvDirTreeView(QWidget *parent = nullptr);
+
+ // Disable copying mand moving
+ DvDirTreeView(const DvDirTreeView &) = delete;
+ DvDirTreeView &operator=(const DvDirTreeView &) = delete;
+
+ DvDirTreeView(DvDirTreeView &&) = delete;
+ DvDirTreeView &operator=(DvDirTreeView &&) = delete;
+ ~DvDirTreeView() override = default;
+
+ // Path operations
TFilePath getCurrentPath()
const; //!< Returns the path of currently selected file or folder,
//! or an empty one in case it couldn't be extracted.
@@ -123,6 +153,7 @@ public:
m_globalSelectionEnabled = enabled;
}
+ // Version control operations
void refreshVersionControl(DvDirVersionControlNode *node,
const QStringList &files = QStringList());
@@ -137,17 +168,15 @@ public:
DvDirVersionControlNode *node, const TFilePath &fp);
signals:
-
void currentNodeChanged(); //!< Emitted when user selects a different node.
public slots:
-
void deleteFolder(); //!< Deletes the selected folder.
void setCurrentNode(
DvDirModelNode *node); //!< Sets the current node, make it visible.
void setCurrentNode(const TFilePath &fp, bool expandNode = false);
- void resizeToConts(void);
+ void resizeToConts();
void cleanupVersionControl(DvDirVersionControlNode *node);
void purgeVersionControl(DvDirVersionControlNode *node);
@@ -171,6 +200,7 @@ public slots:
void cleanupCurrentVersionControlNode();
void purgeCurrentVersionControlNode();
+ // Version control callbacks
void onInfoDone(const QString &);
void onListDone(const QString &);
@@ -183,74 +213,78 @@ public slots:
void onRefreshStatusDone(const QString &);
void onRefreshStatusError(const QString &);
+ // Tree view operations
void onExpanded(const QModelIndex &);
void onCollapsed(const QModelIndex &);
void onMonitoredDirectoryChanged(const QString &);
void onPreferenceChanged(const QString &);
protected:
+ // QWidget overrides
QSize sizeHint() const override;
+ void resizeEvent(QResizeEvent *event) override;
+ // QAbstractItemView overrides
void currentChanged(const QModelIndex &current,
const QModelIndex &previous) override;
- bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *ev) override;
- void resizeEvent(QResizeEvent *) override;
+ bool edit(const QModelIndex &index, EditTrigger trigger,
+ QEvent *event) override;
+ // Drag and drop
void dragEnterEvent(QDragEnterEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override;
+ // Context menu
void contextMenuEvent(QContextMenuEvent *event) override;
- void createMenuAction(QMenu &menu, QString name, const char *slot,
- bool enable = true);
-
- void checkPartialLock(const QString &workingDir, const QStringList &files);
-
private:
- bool m_globalSelectionEnabled;
- DvDirModelNode *m_currentDropItem;
+ bool m_globalSelectionEnabled = true;
+ DvDirModelNode *m_currentDropItem = nullptr;
VersionControlThread m_thread;
- bool m_refreshVersionControlEnabled;
+ bool m_refreshVersionControlEnabled = false;
// Temporary variable used while retrieving list of missing directories
QString m_getSVNListRelativePath;
- // Using for version control node refreshing
- DvDirVersionControlNode *m_currentRefreshedNode;
+ // Used for version control node refreshing
+ DvDirVersionControlNode *m_currentRefreshedNode = nullptr;
+
+ // Helper methods
+ void createMenuAction(QMenu &menu, const QString &name, const char *slot,
+ bool enable = true);
+ void checkPartialLock(const QString &workingDir, const QStringList &files);
/*- Refresh monitoring paths according to expand/shrink state of the folder
* tree -*/
void addPathsToWatcher();
- void getExpandedPathsRecursive(const QModelIndex &, QStringList &);
+ void getExpandedPathsRecursive(const QModelIndex &index, QStringList &paths);
};
//**********************************************************************************
-// DvDirTreeViewDelegate declaration
+// DvDirTreeViewDelegate declaration
//**********************************************************************************
class DvDirTreeViewDelegate final : public QItemDelegate {
Q_OBJECT
public:
- DvDirTreeViewDelegate(DvDirTreeView *parent);
- ~DvDirTreeViewDelegate();
+ explicit DvDirTreeViewDelegate(DvDirTreeView *parent);
+ ~DvDirTreeViewDelegate() override;
+ // QItemDelegate overrides
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
-
bool editorEvent(QEvent *event, QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index) override;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
-
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const override;
-
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
@@ -260,32 +294,39 @@ private:
DvDirTreeView *m_treeView;
private slots:
-
void commitAndCloseEditor();
};
//**********************************************************************************
-// NodeEditor declaration
+// NodeEditor declaration
//**********************************************************************************
class NodeEditor final : public QWidget {
Q_OBJECT
public:
- NodeEditor(QWidget *parent = 0, QRect rect = QRect(), int leftMargin = 0);
+ explicit NodeEditor(QWidget *parent = nullptr, const QRect &rect = QRect(),
+ int leftMargin = 0);
+
+ // Disable copying and moving
+ NodeEditor(const NodeEditor &) = delete;
+ NodeEditor &operator=(const NodeEditor &) = delete;
+
+ NodeEditor(NodeEditor &&) = delete;
+ NodeEditor &operator=(NodeEditor &&) = delete;
- void setText(QString value) { m_lineEdit->setText(value); }
+ ~NodeEditor() override = default;
+
+ void setText(const QString &value) { m_lineEdit->setText(value); }
QString getText() const { return m_lineEdit->text(); }
signals:
-
void editingFinished();
protected:
void focusInEvent(QFocusEvent *event) override;
-protected slots:
-
+private slots:
void emitFinished();
private: