ResourceEditor: Modernize

modernize-*

Change-Id: Ib9411aa2478a762854e4f5f23900a8cf6c0c2d41
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Alessandro Portale
2018-11-24 19:14:33 +01:00
parent 5242f58173
commit d137b33a42
10 changed files with 53 additions and 69 deletions

View File

@@ -40,11 +40,10 @@ using namespace ResourceEditor::Internal;
QrcEditor::QrcEditor(RelativeResourceModel *model, QWidget *parent) QrcEditor::QrcEditor(RelativeResourceModel *model, QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_treeview(new ResourceView(model, &m_history)), m_treeview(new ResourceView(model, &m_history))
m_addFileAction(0)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
QHBoxLayout *layout = new QHBoxLayout; auto layout = new QHBoxLayout;
layout->setSpacing(0); layout->setSpacing(0);
layout->setMargin(0); layout->setMargin(0);
m_ui.centralWidget->setLayout(layout); m_ui.centralWidget->setLayout(layout);
@@ -56,7 +55,7 @@ QrcEditor::QrcEditor(RelativeResourceModel *model, QWidget *parent)
this, &QrcEditor::onRemoveNonExisting); this, &QrcEditor::onRemoveNonExisting);
// 'Add' button with menu // 'Add' button with menu
QMenu *addMenu = new QMenu(this); auto addMenu = new QMenu(this);
m_addFileAction = addMenu->addAction(tr("Add Files")); m_addFileAction = addMenu->addAction(tr("Add Files"));
connect(m_addFileAction, &QAction::triggered, this, &QrcEditor::onAddFiles); connect(m_addFileAction, &QAction::triggered, this, &QrcEditor::onAddFiles);
connect(addMenu->addAction(tr("Add Prefix")), &QAction::triggered, connect(addMenu->addAction(tr("Add Prefix")), &QAction::triggered,
@@ -92,7 +91,7 @@ QrcEditor::QrcEditor(RelativeResourceModel *model, QWidget *parent)
connect(&m_history, &QUndoStack::canRedoChanged, this, &QrcEditor::updateHistoryControls); connect(&m_history, &QUndoStack::canRedoChanged, this, &QrcEditor::updateHistoryControls);
connect(&m_history, &QUndoStack::canUndoChanged, this, &QrcEditor::updateHistoryControls); connect(&m_history, &QUndoStack::canUndoChanged, this, &QrcEditor::updateHistoryControls);
Aggregation::Aggregate * agg = new Aggregation::Aggregate; auto agg = new Aggregation::Aggregate;
agg->add(m_treeview); agg->add(m_treeview);
agg->add(new Core::ItemViewFind(m_treeview)); agg->add(new Core::ItemViewFind(m_treeview));
@@ -100,9 +99,7 @@ QrcEditor::QrcEditor(RelativeResourceModel *model, QWidget *parent)
updateCurrent(); updateCurrent();
} }
QrcEditor::~QrcEditor() QrcEditor::~QrcEditor() = default;
{
}
void QrcEditor::loaded(bool success) void QrcEditor::loaded(bool success)
{ {
@@ -161,8 +158,6 @@ void QrcEditor::updateHistoryControls()
// When the user does a multiselection of files, this requires popping // When the user does a multiselection of files, this requires popping
// up the dialog several times in a row. // up the dialog several times in a row.
struct ResolveLocationContext { struct ResolveLocationContext {
ResolveLocationContext() : copyButton(0), skipButton(0), abortButton(0) {}
QAbstractButton *execLocationMessageBox(QWidget *parent, QAbstractButton *execLocationMessageBox(QWidget *parent,
const QString &file, const QString &file,
bool wantSkipButton); bool wantSkipButton);
@@ -173,9 +168,9 @@ struct ResolveLocationContext {
QScopedPointer<QMessageBox> messageBox; QScopedPointer<QMessageBox> messageBox;
QScopedPointer<QFileDialog> copyFileDialog; QScopedPointer<QFileDialog> copyFileDialog;
QPushButton *copyButton; QPushButton *copyButton = nullptr;
QPushButton *skipButton; QPushButton *skipButton = nullptr;
QPushButton *abortButton; QPushButton *abortButton = nullptr;
}; };
QAbstractButton *ResolveLocationContext::execLocationMessageBox(QWidget *parent, QAbstractButton *ResolveLocationContext::execLocationMessageBox(QWidget *parent,

View File

@@ -79,7 +79,7 @@ private:
Ui::QrcEditor m_ui; Ui::QrcEditor m_ui;
QUndoStack m_history; QUndoStack m_history;
ResourceView *m_treeview; ResourceView *m_treeview;
QAction *m_addFileAction; QAction *m_addFileAction = nullptr;
QString m_currentAlias; QString m_currentAlias;
QString m_currentPrefix; QString m_currentPrefix;

View File

@@ -174,7 +174,7 @@ Core::IDocument::OpenResult ResourceFile::load()
const QString language = relt.attribute(QLatin1String("lang")); const QString language = relt.attribute(QLatin1String("lang"));
const int idx = indexOfPrefix(prefix, language); const int idx = indexOfPrefix(prefix, language);
Prefix * p = 0; Prefix *p = nullptr;
if (idx == -1) { if (idx == -1) {
p = new Prefix(prefix, language); p = new Prefix(prefix, language);
m_prefix_list.append(p); m_prefix_list.append(p);
@@ -473,8 +473,7 @@ bool ResourceFile::contains(int pref_idx, const QString &file) const
{ {
const QChar slash = QLatin1Char('/'); const QChar slash = QLatin1Char('/');
QString result = QString(slash); QString result = QString(slash);
for (int i = 0; i < prefix.size(); ++i) { for (const QChar c : prefix) {
const QChar c = prefix.at(i);
if (c == slash && result.at(result.size() - 1) == slash) if (c == slash && result.at(result.size() - 1) == slash)
continue; continue;
result.append(c); result.append(c);
@@ -584,10 +583,10 @@ QModelIndex ResourceModel::index(int row, int column, const QModelIndex &parent)
if (column != 0) if (column != 0)
return QModelIndex(); return QModelIndex();
void * internalPointer = 0; void *internalPointer = nullptr;
if (parent.isValid()) { if (parent.isValid()) {
void * const pip = parent.internalPointer(); void * const pip = parent.internalPointer();
if (pip == 0) if (!pip)
return QModelIndex(); return QModelIndex();
// File node // File node
@@ -615,7 +614,7 @@ QModelIndex ResourceModel::parent(const QModelIndex &index) const
return QModelIndex(); return QModelIndex();
void * const internalPointer = index.internalPointer(); void * const internalPointer = index.internalPointer();
if (internalPointer == 0) if (!internalPointer)
return QModelIndex(); return QModelIndex();
Node * const node = reinterpret_cast<Node *>(internalPointer); Node * const node = reinterpret_cast<Node *>(internalPointer);
Prefix * const prefix = node->prefix(); Prefix * const prefix = node->prefix();
@@ -1121,12 +1120,12 @@ QString ResourceModel::resourcePath(const QString &prefix, const QString &file)
QMimeData *ResourceModel::mimeData(const QModelIndexList &indexes) const QMimeData *ResourceModel::mimeData(const QModelIndexList &indexes) const
{ {
if (indexes.size() != 1) if (indexes.size() != 1)
return 0; return nullptr;
QString prefix, file; QString prefix, file;
getItem(indexes.front(), prefix, file); getItem(indexes.front(), prefix, file);
if (prefix.isEmpty() || file.isEmpty()) if (prefix.isEmpty() || file.isEmpty())
return 0; return nullptr;
// DnD format of Designer 4.4 // DnD format of Designer 4.4
QDomDocument doc; QDomDocument doc;
@@ -1135,7 +1134,7 @@ QMimeData *ResourceModel::mimeData(const QModelIndexList &indexes) const
elem.setAttribute(QLatin1String("file"), resourcePath(prefix, file)); elem.setAttribute(QLatin1String("file"), resourcePath(prefix, file));
doc.appendChild(elem); doc.appendChild(elem);
QMimeData *rc = new QMimeData; auto rc = new QMimeData;
rc->setText(doc.toString()); rc->setText(doc.toString());
return rc; return rc;
} }
@@ -1157,7 +1156,7 @@ public:
const QString &fileName, const QString &alias) const QString &fileName, const QString &alias)
: EntryBackup(model, prefixIndex, fileName), m_fileIndex(fileIndex), : EntryBackup(model, prefixIndex, fileName), m_fileIndex(fileIndex),
m_alias(alias) { } m_alias(alias) { }
void restore() const; void restore() const override;
}; };
void FileEntryBackup::restore() const void FileEntryBackup::restore() const
@@ -1180,7 +1179,7 @@ public:
PrefixEntryBackup(ResourceModel &model, int prefixIndex, const QString &prefix, PrefixEntryBackup(ResourceModel &model, int prefixIndex, const QString &prefix,
const QString &language, const QList<FileEntryBackup> &files) const QString &language, const QList<FileEntryBackup> &files)
: EntryBackup(model, prefixIndex, prefix), m_language(language), m_files(files) { } : EntryBackup(model, prefixIndex, prefix), m_language(language), m_files(files) { }
void restore() const; void restore() const override;
}; };
void PrefixEntryBackup::restore() const void PrefixEntryBackup::restore() const
@@ -1240,6 +1239,6 @@ EntryBackup * RelativeResourceModel::removeEntry(const QModelIndex &index)
Core::FileUtils::removeFile(fileNameBackup, removeFileDialog.isDeleteFileChecked()); Core::FileUtils::removeFile(fileNameBackup, removeFileDialog.isDeleteFileChecked());
return new FileEntryBackup(*this, prefixIndex.row(), index.row(), fileNameBackup, aliasBackup); return new FileEntryBackup(*this, prefixIndex.row(), index.row(), fileNameBackup, aliasBackup);
} }
return 0; return nullptr;
} }
} }

View File

@@ -116,7 +116,7 @@ struct Prefix : public Node
QString lang; QString lang;
FileList file_list; FileList file_list;
}; };
typedef QList<Prefix *> PrefixList; using PrefixList = QList<Prefix *>;
/*! /*!
\class ResourceFile \class ResourceFile
@@ -294,7 +294,7 @@ protected:
public: public:
virtual void restore() const = 0; virtual void restore() const = 0;
virtual ~EntryBackup() { } virtual ~EntryBackup() = default;
}; };
class RelativeResourceModel : public ResourceModel class RelativeResourceModel : public ResourceModel

View File

@@ -61,9 +61,7 @@ ResourceView::ResourceView(RelativeResourceModel *model, QUndoStack *history, QW
connect(this, &QAbstractItemView::activated, this, &ResourceView::onItemActivated); connect(this, &QAbstractItemView::activated, this, &ResourceView::onItemActivated);
} }
ResourceView::~ResourceView() ResourceView::~ResourceView() = default;
{
}
void ResourceView::findSamePlacePostDeletionModelIndex(int &row, QModelIndex &parent) const void ResourceView::findSamePlacePostDeletionModelIndex(int &row, QModelIndex &parent) const
{ {

View File

@@ -34,15 +34,13 @@ ViewCommand::ViewCommand(ResourceView *view)
: m_view(view) : m_view(view)
{ } { }
ViewCommand::~ViewCommand() ViewCommand::~ViewCommand() = default;
{ }
ModelIndexViewCommand::ModelIndexViewCommand(ResourceView *view) ModelIndexViewCommand::ModelIndexViewCommand(ResourceView *view)
: ViewCommand(view) : ViewCommand(view)
{ } { }
ModelIndexViewCommand::~ModelIndexViewCommand() ModelIndexViewCommand::~ModelIndexViewCommand() = default;
{ }
void ModelIndexViewCommand::storeIndex(const QModelIndex &index) void ModelIndexViewCommand::storeIndex(const QModelIndex &index)
{ {
@@ -112,7 +110,7 @@ void ModifyPropertyCommand::redo()
} }
RemoveEntryCommand::RemoveEntryCommand(ResourceView *view, const QModelIndex &index) RemoveEntryCommand::RemoveEntryCommand(ResourceView *view, const QModelIndex &index)
: ModelIndexViewCommand(view), m_entry(0), m_isExpanded(true) : ModelIndexViewCommand(view), m_entry(nullptr), m_isExpanded(true)
{ {
storeIndex(index); storeIndex(index);
} }
@@ -132,9 +130,9 @@ void RemoveEntryCommand::redo()
void RemoveEntryCommand::undo() void RemoveEntryCommand::undo()
{ {
if (m_entry != 0) { if (m_entry != nullptr) {
m_entry->restore(); m_entry->restore();
Q_ASSERT(m_view != 0); Q_ASSERT(m_view != nullptr);
const QModelIndex index = makeIndex(); const QModelIndex index = makeIndex();
m_view->setExpanded(index, m_isExpanded); m_view->setExpanded(index, m_isExpanded);
m_view->setCurrentIndex(index); m_view->setCurrentIndex(index);
@@ -145,7 +143,7 @@ void RemoveEntryCommand::undo()
void RemoveEntryCommand::freeEntry() void RemoveEntryCommand::freeEntry()
{ {
delete m_entry; delete m_entry;
m_entry = 0; m_entry = nullptr;
} }
RemoveMultipleEntryCommand::RemoveMultipleEntryCommand(ResourceView *view, const QList<QModelIndex> &list) RemoveMultipleEntryCommand::RemoveMultipleEntryCommand(ResourceView *view, const QList<QModelIndex> &list)

View File

@@ -25,6 +25,8 @@
#pragma once #pragma once
#include <QtGlobal>
namespace ResourceEditor { namespace ResourceEditor {
namespace Constants { namespace Constants {

View File

@@ -76,7 +76,7 @@ public:
: QDialog(parent) : QDialog(parent)
{ {
setWindowTitle(title); setWindowTitle(title);
QFormLayout *layout = new QFormLayout(this); auto layout = new QFormLayout(this);
m_prefixLineEdit = new QLineEdit(this); m_prefixLineEdit = new QLineEdit(this);
m_prefixLineEdit->setText(prefix); m_prefixLineEdit->setText(prefix);
layout->addRow(tr("Prefix:"), m_prefixLineEdit); layout->addRow(tr("Prefix:"), m_prefixLineEdit);
@@ -111,11 +111,7 @@ private:
QLineEdit *m_langLineEdit; QLineEdit *m_langLineEdit;
}; };
ResourceEditorPlugin::ResourceEditorPlugin() : ResourceEditorPlugin::ResourceEditorPlugin() = default;
m_redoAction(0),
m_undoAction(0)
{
}
bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage) bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{ {
@@ -141,7 +137,7 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FOLDERCONTEXT); Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FOLDERCONTEXT);
Core::ActionContainer *fileContextMenu = Core::ActionContainer *fileContextMenu =
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT); Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
Core::Command *command = 0; Core::Command *command = nullptr;
m_addPrefix = new QAction(tr("Add Prefix..."), this); m_addPrefix = new QAction(tr("Add Prefix..."), this);
command = Core::ActionManager::registerAction(m_addPrefix, Constants::C_ADD_PREFIX, projectTreeContext); command = Core::ActionManager::registerAction(m_addPrefix, Constants::C_ADD_PREFIX, projectTreeContext);
@@ -338,7 +334,7 @@ void ResourceEditorPlugin::updateContextActions()
bool enableRemove = false; bool enableRemove = false;
if (isResourceNode) { if (isResourceNode) {
FolderNode *parent = node ? node->parentFolderNode() : 0; FolderNode *parent = node ? node->parentFolderNode() : nullptr;
enableRename = parent && parent->supportsAction(Rename, node); enableRename = parent && parent->supportsAction(Rename, node);
enableRemove = parent && parent->supportsAction(RemoveFile, node); enableRemove = parent && parent->supportsAction(RemoveFile, node);
} }
@@ -392,9 +388,8 @@ void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
ResourceEditorW * ResourceEditorPlugin::currentEditor() const ResourceEditorW * ResourceEditorPlugin::currentEditor() const
{ {
ResourceEditorW * const focusEditor = qobject_cast<ResourceEditorW *>( auto const focusEditor = qobject_cast<ResourceEditorW *>(Core::EditorManager::currentEditor());
Core::EditorManager::currentEditor()); QTC_ASSERT(focusEditor, return nullptr);
QTC_ASSERT(focusEditor, return 0);
return focusEditor; return focusEditor;
} }

View File

@@ -77,25 +77,25 @@ private:
ResourceEditorW * currentEditor() const; ResourceEditorW * currentEditor() const;
private: private:
QAction *m_redoAction; QAction *m_redoAction = nullptr;
QAction *m_undoAction; QAction *m_undoAction = nullptr;
QAction *m_refreshAction; QAction *m_refreshAction = nullptr;
// project tree's folder context menu // project tree's folder context menu
QAction *m_addPrefix; QAction *m_addPrefix = nullptr;
QAction *m_removePrefix; QAction *m_removePrefix = nullptr;
QAction *m_renamePrefix; QAction *m_renamePrefix = nullptr;
QAction *m_removeNonExisting; QAction *m_removeNonExisting = nullptr;
QAction *m_renameResourceFile; QAction *m_renameResourceFile = nullptr;
QAction *m_removeResourceFile; QAction *m_removeResourceFile = nullptr;
QAction *m_openInEditor; QAction *m_openInEditor = nullptr;
QMenu *m_openWithMenu; QMenu *m_openWithMenu = nullptr;
// file context menu // file context menu
Utils::ParameterAction *m_copyPath; Utils::ParameterAction *m_copyPath = nullptr;
Utils::ParameterAction *m_copyUrl; Utils::ParameterAction *m_copyUrl = nullptr;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -84,7 +84,7 @@ private:
class PrefixFolderLang class PrefixFolderLang
{ {
public: public:
PrefixFolderLang(QString prefix, QString folder, QString lang) PrefixFolderLang(const QString &prefix, const QString &folder, const QString &lang)
: m_prefix(prefix) : m_prefix(prefix)
, m_folder(folder) , m_folder(folder)
, m_lang(lang) , m_lang(lang)
@@ -317,7 +317,7 @@ void ResourceTopLevelNode::addInternalNodes()
folderNodes.insert(prefixId, fn.get()); folderNodes.insert(prefixId, fn.get());
addNode(std::move(fn)); addNode(std::move(fn));
} }
ResourceFolderNode *currentPrefixNode = static_cast<ResourceFolderNode*>(folderNodes[prefixId]); auto currentPrefixNode = static_cast<ResourceFolderNode*>(folderNodes[prefixId]);
QSet<QString> fileNames; QSet<QString> fileNames;
int filecount = file.fileCount(i); int filecount = file.fileCount(i);
@@ -508,10 +508,7 @@ ResourceFolderNode::ResourceFolderNode(const QString &prefix, const QString &lan
} }
ResourceFolderNode::~ResourceFolderNode() ResourceFolderNode::~ResourceFolderNode() = default;
{
}
bool ResourceFolderNode::supportsAction(ProjectAction action, const Node *node) const bool ResourceFolderNode::supportsAction(ProjectAction action, const Node *node) const
{ {