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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -84,7 +84,7 @@ private:
class PrefixFolderLang
{
public:
PrefixFolderLang(QString prefix, QString folder, QString lang)
PrefixFolderLang(const QString &prefix, const QString &folder, const QString &lang)
: m_prefix(prefix)
, m_folder(folder)
, m_lang(lang)
@@ -317,7 +317,7 @@ void ResourceTopLevelNode::addInternalNodes()
folderNodes.insert(prefixId, fn.get());
addNode(std::move(fn));
}
ResourceFolderNode *currentPrefixNode = static_cast<ResourceFolderNode*>(folderNodes[prefixId]);
auto currentPrefixNode = static_cast<ResourceFolderNode*>(folderNodes[prefixId]);
QSet<QString> fileNames;
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
{