renaming utility: Improve coding style

This commit is contained in:
Martchus 2017-01-06 22:15:39 +01:00
parent 5472c560f3
commit d5c2dd5f5b
4 changed files with 110 additions and 137 deletions

View File

@ -137,7 +137,9 @@ void RenameFilesDialog::showScriptFileSelectionDlg()
void RenameFilesDialog::startGeneratingPreview()
{
if(!m_engine->isBusy()) {
if(m_engine->isBusy()) {
return;
}
QDir selectedDir(directory());
m_ui->notificationLabel->setHidden(false);
if(selectedDir.exists()) {
@ -189,12 +191,13 @@ void RenameFilesDialog::startGeneratingPreview()
m_ui->notificationLabel->setNotificationType(NotificationType::Warning);
}
}
}
void RenameFilesDialog::startApplyChangings()
{
if(!m_engine->isBusy()) {
if(m_engine->isBusy()) {
return;
}
m_ui->notificationLabel->setText(tr("Applying changings ..."));
m_ui->notificationLabel->setNotificationType(NotificationType::Progress);
m_ui->abortClosePushButton->setText(tr("Abort"));
@ -202,7 +205,6 @@ void RenameFilesDialog::startApplyChangings()
m_ui->applyChangingsPushButton->setHidden(true);
m_engine->applyChangings();
}
}
void RenameFilesDialog::showPreviewProgress(int itemsProcessed, int errorsOccured)
{
@ -261,7 +263,10 @@ void RenameFilesDialog::showChangsingsResults()
void RenameFilesDialog::currentItemSelected(const QItemSelection &, const QItemSelection &)
{
if(!m_changingSelection) {
if(m_changingSelection) {
return;
}
m_changingSelection = true;
m_ui->previewTreeView->selectionModel()->clear();
for(const QModelIndex &row : m_ui->currentTreeView->selectionModel()->selectedRows()) {
@ -283,11 +288,13 @@ void RenameFilesDialog::currentItemSelected(const QItemSelection &, const QItemS
}
m_changingSelection = false;
}
}
void RenameFilesDialog::previewItemSelected(const QItemSelection &, const QItemSelection &)
{
if(!m_changingSelection) {
if(m_changingSelection) {
return;
}
m_changingSelection = true;
m_ui->currentTreeView->selectionModel()->clear();
for(const QModelIndex &row : m_ui->previewTreeView->selectionModel()->selectedRows()) {
@ -309,7 +316,6 @@ void RenameFilesDialog::previewItemSelected(const QItemSelection &, const QItemS
}
m_changingSelection = false;
}
}
void RenameFilesDialog::pasteScriptFromFile(const QString &fileName)
{
@ -341,12 +347,13 @@ void RenameFilesDialog::abortClose()
void RenameFilesDialog::pasteScriptFromClipboard()
{
QString script = QApplication::clipboard()->text();
if(!script.isEmpty()) {
m_ui->javaScriptPlainTextEdit->setPlainText(script);
} else {
const QString script = QApplication::clipboard()->text();
if(script.isEmpty()) {
QMessageBox::warning(this, windowTitle(), tr("Clipboard contains no text."));
return;
}
m_ui->javaScriptPlainTextEdit->setPlainText(script);
}
void RenameFilesDialog::pasteDefaultExampleScript()
@ -356,10 +363,10 @@ void RenameFilesDialog::pasteDefaultExampleScript()
void RenameFilesDialog::showTreeViewContextMenu()
{
if(QObject *sender = QObject::sender()) {
if(const QTreeView *sender = qobject_cast<const QTreeView *>(QObject::sender())) {
QMenu menu;
menu.addAction(tr("Expand all"), sender, SLOT(expandAll()));
menu.addAction(tr("Collapse all"), sender, SLOT(collapseAll()));
connect(menu.addAction(tr("Expand all")), &QAction::trigger, sender, &QTreeView::expandAll);
connect(menu.addAction(tr("Collapse all")), &QAction::trigger, sender, &QTreeView::collapseAll);
menu.exec(QCursor::pos());
}
}

View File

@ -2,7 +2,6 @@
#include <QDir>
#include <QCoreApplication>
#include <QDebug>
namespace RenamingUtility {
@ -65,8 +64,6 @@ const QString &FileSystemItem::currentName() const
: emptyStr();
case ItemStatus::Current:
return m_name;
default:
return emptyStr();
}
}
@ -97,8 +94,6 @@ const QString &FileSystemItem::newName() const
: emptyStr();
case ItemStatus::New:
return m_name;
default:
return emptyStr();
}
}
@ -122,8 +117,6 @@ bool FileSystemItem::setNewName(const QString &newName)
case ItemStatus::New:
setName(newName);
return true;
default: // avoid warning
return false;
}
}
@ -206,7 +199,7 @@ bool FileSystemItem::hasSibling(const QString &name) const
{
if(m_parent) {
const QList<FileSystemItem *> &siblings = m_parent->children();
for(FileSystemItem *siblingItem : siblings) {
for(const FileSystemItem *siblingItem : siblings) {
if(siblingItem == this) {
continue;
}

View File

@ -94,16 +94,6 @@ QVariant FileSystemItemModel::data(const QModelIndex &index, int role) const
return QBrush(Qt::gray);
}
break;
/*case Qt::CheckStateRole:
if(item->checkable() && index.column() == 1) {
return item->checked() ? Qt::Checked : Qt::Unchecked;
}
break;
case CheckableRole:
if(index.column() == 1) {
return item->checkable();
}
break;*/
case ErrorStatusRole:
return item->errorOccured();
default:
@ -139,10 +129,6 @@ bool FileSystemItemModel::setData(const QModelIndex &index, const QVariant &valu
default: ;
}
break;
/*case Qt::CheckStateRole:
item->setChecked(value.toInt() == Qt::Checked);
emit dataChanged(index, index, QVector<int>() << role);
return true;*/
case ErrorStatusRole:
item->setErrorOccured(value.toBool());
emit dataChanged(index, index, QVector<int>() << role << Qt::DecorationRole);
@ -155,18 +141,6 @@ bool FileSystemItemModel::setData(const QModelIndex &index, const QVariant &valu
return false;
}
Qt::ItemFlags FileSystemItemModel::flags(const QModelIndex &index) const
{
/*if(index.isValid() && index.column() == 1) {
if(FileSystemItem *item = reinterpret_cast<FileSystemItem *>(index.internalPointer())) {
if(item->checkable()) {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
}
}
}*/
return QAbstractItemModel::flags(index);
}
QVariant FileSystemItemModel::headerData(int section, Qt::Orientation orientation, int role) const
{
switch(orientation) {
@ -253,10 +227,10 @@ QModelIndex FileSystemItemModel::counterpart(const QModelIndex &index, int colum
int FileSystemItemModel::rowCount(const QModelIndex &parent) const
{
if(FileSystemItem *parentItem = parent.isValid()
if(const FileSystemItem *parentItem = (parent.isValid()
? reinterpret_cast<FileSystemItem *>(parent.internalPointer())
: m_rootItem) {
return parentItem->children().length();
: m_rootItem)) {
return parentItem->children().size();
} else {
return 0;
}
@ -264,10 +238,10 @@ int FileSystemItemModel::rowCount(const QModelIndex &parent) const
bool FileSystemItemModel::hasChildren(const QModelIndex &parent) const
{
if(FileSystemItem *parentItem = parent.isValid()
? reinterpret_cast<FileSystemItem *>(parent.internalPointer())
: m_rootItem) {
return parentItem->children().length() > 0;
if(const FileSystemItem *parentItem = (parent.isValid()
? reinterpret_cast<const FileSystemItem *>(parent.internalPointer())
: m_rootItem)) {
return parentItem->children().size() > 0;
} else {
return false;
}

View File

@ -23,7 +23,6 @@ public:
void setRootItem(FileSystemItem *rootItem);
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,