Commit 8b46136b authored by Tobias Hunger's avatar Tobias Hunger

Perforce: Modernize

* use pragma once
* remove debug code
* Remove some "slots"
* Use Qt5 style connects (almost everywhere)

Change-Id: Iaa9c3bbacbb2be3c96502c52cc169ad4ec7015a5
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 84f2875f
......@@ -30,14 +30,12 @@ namespace Internal {
PerforceAnnotationHighlighter::PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, document),
m_colon(QLatin1Char(':'))
{
}
VcsBase::BaseAnnotationHighlighter(changeNumbers, document)
{ }
QString PerforceAnnotationHighlighter::changeNumber(const QString &block) const
{
const int pos = block.indexOf(m_colon);
const int pos = block.indexOf(QLatin1Char(':'));
return pos > 1 ? block.left(pos) : QString();
}
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef ANNOTATIONHIGHLIGHTER_H
#define ANNOTATIONHIGHLIGHTER_H
#pragma once
#include <vcsbase/baseannotationhighlighter.h>
......@@ -37,15 +36,11 @@ class PerforceAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
Q_OBJECT
public:
explicit PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document = 0);
QTextDocument *document = nullptr);
private:
QString changeNumber(const QString &block) const;
const QChar m_colon;
QString changeNumber(const QString &block) const override;
};
} // namespace Perforce
} // namespace Internal
#endif // ANNOTATIONHIGHLIGHTER_H
......@@ -29,8 +29,7 @@
using namespace Perforce::Internal;
ChangeNumberDialog::ChangeNumberDialog(QWidget *parent)
: QDialog(parent)
ChangeNumberDialog::ChangeNumberDialog(QWidget *parent) : QDialog(parent)
{
m_ui.setupUi(this);
m_ui.numberLineEdit->setValidator(new QIntValidator(0, 1000000, this));
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef CHANGENUMBERDIALOG_H
#define CHANGENUMBERDIALOG_H
#pragma once
#include <QDialog>
......@@ -38,7 +37,7 @@ class ChangeNumberDialog : public QDialog
{
Q_OBJECT
public:
ChangeNumberDialog(QWidget *parent = 0);
ChangeNumberDialog(QWidget *parent = nullptr);
int number() const;
private:
......@@ -48,5 +47,3 @@ private:
} // namespace Perforce
} // namespace Internal
#endif // CHANGENUMBERDIALOG_H
......@@ -30,8 +30,7 @@
using namespace Perforce::Internal;
PendingChangesDialog::PendingChangesDialog(const QString &data, QWidget *parent)
: QDialog(parent)
PendingChangesDialog::PendingChangesDialog(const QString &data, QWidget *parent) : QDialog(parent)
{
m_ui.setupUi(this);
if (!data.isEmpty()) {
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef PENDINGCHANGESDIALOG_H
#define PENDINGCHANGESDIALOG_H
#pragma once
#include <QDialog>
......@@ -38,7 +37,7 @@ class PendingChangesDialog : public QDialog
Q_OBJECT
public:
explicit PendingChangesDialog(const QString &data, QWidget *parent = 0);
explicit PendingChangesDialog(const QString &data, QWidget *parent = nullptr);
int changeNumber() const;
private:
......@@ -47,6 +46,3 @@ private:
} // namespace Perforce
} // namespace Internal
#endif // PENDINGCHANGESDIALOG_H
......@@ -8,7 +8,6 @@ HEADERS += \
changenumberdialog.h \
perforcesubmiteditor.h \
pendingchangesdialog.h \
perforceconstants.h \
perforceversioncontrol.h \
perforcesettings.h \
annotationhighlighter.h \
......
......@@ -22,7 +22,6 @@ QtcPlugin {
"perforce.qrc",
"perforcechecker.cpp",
"perforcechecker.h",
"perforceconstants.h",
"perforceeditor.cpp",
"perforceeditor.h",
"perforceplugin.cpp",
......
......@@ -24,7 +24,6 @@
****************************************************************************/
#include "perforcechecker.h"
#include "perforceconstants.h"
#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
......@@ -40,12 +39,7 @@
namespace Perforce {
namespace Internal {
PerforceChecker::PerforceChecker(QObject *parent) :
QObject(parent),
m_timeOutMS(-1),
m_timedOut(false),
m_useOverideCursor(false),
m_isOverrideCursor(false)
PerforceChecker::PerforceChecker(QObject *parent) : QObject(parent)
{
connect(&m_process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
this, &PerforceChecker::slotError);
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef PERFORCECHECKER_H
#define PERFORCECHECKER_H
#pragma once
#include <QObject>
#include <QProcess>
......@@ -40,10 +39,9 @@ class PerforceChecker : public QObject
{
Q_OBJECT
public:
explicit PerforceChecker(QObject *parent = 0);
explicit PerforceChecker(QObject *parent = nullptr);
~PerforceChecker();
public slots:
void start(const QString &binary,
const QString &workingDirectory,
const QStringList &basicArgs = QStringList(),
......@@ -72,13 +70,11 @@ private:
QProcess m_process;
QString m_binary;
int m_timeOutMS;
bool m_timedOut;
bool m_useOverideCursor;
bool m_isOverrideCursor;
int m_timeOutMS = -1;
bool m_timedOut = false;
bool m_useOverideCursor = false;
bool m_isOverrideCursor = false;
};
}
}
#endif // PERFORCECHECKER_H
} // namespace Internal
} // namespace Perforce
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#ifndef PERFORCE_CONSTANTS_H
#define PERFORCE_CONSTANTS_H
#include <QtGlobal>
namespace Perforce {
namespace Constants {
enum { debug = 0 };
} // Constants
} // Perforce
#endif // PERFORCE_CONSTANTS_H
......@@ -26,7 +26,6 @@
#include "perforceeditor.h"
#include "annotationhighlighter.h"
#include "perforceconstants.h"
#include "perforceplugin.h"
#include <coreplugin/editormanager/editormanager.h>
......@@ -85,8 +84,6 @@ QSet<QString> PerforceEditorWidget::annotationChanges() const
changes.insert(r.cap(1));
}
}
if (Perforce::Constants::debug)
qDebug() << "PerforceEditor::annotationChanges() returns #" << changes.size();
return changes;
}
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef PERFORCEEDITOR_H
#define PERFORCEEDITOR_H
#pragma once
#include <vcsbase/vcsbaseeditor.h>
......@@ -53,5 +52,3 @@ private:
} // namespace Perforce
} // namespace Internal
#endif // PERFORCEEDITOR_H
......@@ -27,7 +27,6 @@
#include "changenumberdialog.h"
#include "pendingchangesdialog.h"
#include "perforceconstants.h"
#include "perforceeditor.h"
#include "perforcesubmiteditor.h"
#include "perforceversioncontrol.h"
......@@ -115,11 +114,6 @@ static inline const VcsBaseEditorParameters *findType(int ie)
return VcsBaseEditor::findType(editorParameters, sizeof(editorParameters)/sizeof(editorParameters[0]), et);
}
static inline QString debugCodec(const QTextCodec *c)
{
return c ? QString::fromLatin1(c->name()) : QString::fromLatin1("Null codec");
}
// Ensure adding "..." to relative paths which is p4's convention
// for the current directory
static inline QString perforceRelativeFileArguments(const QString &args)
......@@ -177,37 +171,6 @@ PerforceResponse::PerforceResponse() :
PerforcePlugin *PerforcePlugin::m_instance = NULL;
PerforcePlugin::PerforcePlugin() :
m_commandLocator(0),
m_editAction(0),
m_addAction(0),
m_deleteAction(0),
m_openedAction(0),
m_revertFileAction(0),
m_diffFileAction(0),
m_diffProjectAction(0),
m_updateProjectAction(0),
m_revertProjectAction(0),
m_revertUnchangedAction(0),
m_diffAllAction(0),
m_submitProjectAction(0),
m_pendingAction(0),
m_describeAction(0),
m_annotateCurrentAction(0),
m_annotateAction(0),
m_filelogCurrentAction(0),
m_filelogAction(0),
m_logProjectAction(0),
m_logRepositoryAction(0),
m_submitCurrentLogAction(0),
m_updateAllAction(0),
m_submitActionTriggered(false),
m_diffSelectedFiles(0),
m_undoAction(0),
m_redoAction(0)
{
}
static const VcsBaseSubmitEditorParameters submitParameters = {
SUBMIT_MIMETYPE,
PERFORCE_SUBMIT_EDITOR_ID,
......@@ -890,10 +853,6 @@ bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
const PerforceResponse result = runP4Cmd(m_settings.topLevel(), args,
RunFullySynchronous);
if (Perforce::Constants::debug)
qDebug() << "Perforce result:\n" << result.stdOut << "\n---\n" << result.stdErr
<< "\n---\n" << result.message;
managed = result.stdOut.contains(QLatin1String("depotFile"))
|| result.stdErr.contains(QLatin1String("... - no such file(s)"));
} while (false);
......@@ -904,8 +863,6 @@ bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName, bool silently)
{
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::vcsOpen" << workingDir << fileName;
QStringList args;
args << QLatin1String("edit") << QDir::toNativeSeparators(fileName);
......@@ -1053,12 +1010,8 @@ PerforceResponse PerforcePlugin::synchronousProcess(const QString &workingDir,
connect(&process, SIGNAL(stdOutBuffered(QString,bool)), outputWindow, SLOT(append(QString)));
}
}
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::run syncp actual args [" << process.workingDirectory() << ']' << args;
process.setTimeOutMessageBoxEnabled(true);
const SynchronousProcessResponse sp_resp = process.run(settings().p4BinaryPath(), args);
if (Perforce::Constants::debug)
qDebug() << sp_resp;
PerforceResponse response;
response.error = true;
......@@ -1100,9 +1053,6 @@ PerforceResponse PerforcePlugin::fullySynchronousProcess(const QString &workingD
if (!workingDir.isEmpty())
process.setWorkingDirectory(workingDir);
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::run fully syncp actual args [" << process.workingDirectory() << ']' << args;
PerforceResponse response;
process.start(settings().p4BinaryPath(), args);
if (stdInput.isEmpty())
......@@ -1162,9 +1112,6 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QString &workingDir,
const QByteArray &stdInput,
QTextCodec *outputCodec)
{
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::runP4Cmd [" << workingDir << ']' << args << extraArgs << stdInput << debugCodec(outputCodec);
if (!settings().isValid()) {
PerforceResponse invalidConfigResponse;
invalidConfigResponse.error = true;
......@@ -1198,12 +1145,8 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QString &workingDir,
if (flags & ShowBusyCursor)
QApplication::restoreOverrideCursor();
if (response.error) {
if (Perforce::Constants::debug)
qDebug() << response.message;
if (flags & ErrorToWindow)
VcsOutputWindow::appendError(response.message);
}
if (response.error && (flags & ErrorToWindow))
VcsOutputWindow::appendError(response.message);
return response;
}
......@@ -1216,12 +1159,9 @@ IEditor *PerforcePlugin::showOutputInEditor(const QString &title,
const VcsBaseEditorParameters *params = findType(editorType);
QTC_ASSERT(params, return 0);
const Id id = params->id;
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::showOutputInEditor" << title << id.name()
<< "Size= " << output.size() << " Type=" << editorType << debugCodec(codec);
QString s = title;
QString content = output;
const int maxSize = EditorManager::maxTextFileSize() / 2 - 1000; // ~25 MB, 600000 lines
const int maxSize = int(EditorManager::maxTextFileSize() / 2 - 1000L); // ~25 MB, 600000 lines
if (content.size() >= maxSize) {
content = content.left(maxSize);
content += QLatin1Char('\n') + tr("[Only %n MB of output shown]", 0, maxSize / 1024 / 1024);
......@@ -1230,7 +1170,7 @@ IEditor *PerforcePlugin::showOutputInEditor(const QString &title,
QTC_ASSERT(editor, return 0);
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)),
this, SLOT(vcsAnnotate(QString,QString,QString,int)));
PerforceEditorWidget *e = qobject_cast<PerforceEditorWidget*>(editor->widget());
auto e = qobject_cast<PerforceEditorWidget*>(editor->widget());
if (!e)
return 0;
e->setForceReadOnly(true);
......@@ -1326,12 +1266,12 @@ void PerforcePlugin::p4Diff(const PerforceDiffParameters &p)
VcsBaseEditor::getSource(p.workingDir, p.files),
codec);
VcsBaseEditor::tagEditor(editor, tag);
VcsBaseEditorWidget *diffEditorWidget = qobject_cast<VcsBaseEditorWidget *>(editor->widget());
auto diffEditorWidget = qobject_cast<VcsBaseEditorWidget *>(editor->widget());
// Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor.
auto pw = new PerforceDiffParameterWidget(p);
connect(pw, SIGNAL(reRunDiff(Perforce::Internal::PerforceDiffParameters)),
this, SLOT(p4Diff(Perforce::Internal::PerforceDiffParameters)));
connect(pw, &PerforceDiffParameterWidget::reRunDiff,
this, [this](const PerforceDiffParameters &p) { p4Diff(p); });
connect(diffEditorWidget, &VcsBaseEditorWidget::diffChunkReverted,
pw, &PerforceDiffParameterWidget::triggerReRun);
diffEditorWidget->setConfigurationWidget(pw);
......@@ -1372,7 +1312,7 @@ bool PerforcePlugin::submitEditorAboutToClose()
{
if (!isCommitEditorOpen())
return true;
PerforceSubmitEditor *perforceEditor = qobject_cast<PerforceSubmitEditor *>(submitEditor());
auto perforceEditor = qobject_cast<PerforceSubmitEditor *>(submitEditor());
QTC_ASSERT(perforceEditor, return true);
IDocument *editorDocument = perforceEditor->document();
QTC_ASSERT(editorDocument, return true);
......@@ -1437,10 +1377,7 @@ QString PerforcePlugin::clientFilePath(const QString &serverFilePath)
QRegExp r(QLatin1String("\\.\\.\\.\\sclientFile\\s(.+)\n"));
r.setMinimal(true);
const QString path = r.indexIn(response.stdOut) != -1 ? r.cap(1).trimmed() : QString();
if (Perforce::Constants::debug)
qDebug() << "clientFilePath" << serverFilePath << path;
return path;
return r.indexIn(response.stdOut) != -1 ? r.cap(1).trimmed() : QString();
}
QString PerforcePlugin::pendingChangesData()
......@@ -1466,10 +1403,6 @@ QString PerforcePlugin::pendingChangesData()
return dataResponse.error ? QString() : dataResponse.stdOut;
}
PerforcePlugin::~PerforcePlugin()
{
}
const PerforceSettings& PerforcePlugin::settings()
{
return m_instance->m_settings;
......@@ -1526,10 +1459,7 @@ QString PerforcePlugin::fileNameFromPerforceName(const QString& perforceName,
return QString();
}
const QString p4fileSpec = output.mid(output.lastIndexOf(QLatin1Char(' ')) + 1);
const QString rc = m_instance->m_settings.mapToFileSystem(p4fileSpec);
if (Perforce::Constants::debug)
qDebug() << "fileNameFromPerforceName" << perforceName << p4fileSpec << rc;
return rc;
return m_instance->m_settings.mapToFileSystem(p4fileSpec);
}
PerforceVersionControl *PerforcePlugin::perforceVersionControl()
......@@ -1546,15 +1476,11 @@ void PerforcePlugin::setTopLevel(const QString &topLevel)
const QString msg = tr("Perforce repository: %1").arg(QDir::toNativeSeparators(topLevel));
VcsOutputWindow::appendSilently(msg);
if (Perforce::Constants::debug)
qDebug() << "P4: " << topLevel;
}
void PerforcePlugin::slotTopLevelFailed(const QString &errorMessage)
{
VcsOutputWindow::appendSilently(tr("Perforce: Unable to determine the repository: %1").arg(errorMessage));
if (Perforce::Constants::debug)
qDebug() << errorMessage;
}
void PerforcePlugin::getTopLevel(const QString &workingDirectory, bool isSync)
......
......@@ -23,8 +23,7 @@
**
****************************************************************************/
#ifndef PERFORCEPLUGIN_H
#define PERFORCEPLUGIN_H
#pragma once
#include "perforcesettings.h"
......@@ -76,8 +75,7 @@ class PerforcePlugin : public VcsBase::VcsBasePlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Perforce.json")
public:
PerforcePlugin();
~PerforcePlugin();
PerforcePlugin() = default;
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
......@@ -105,19 +103,19 @@ public slots:
void describe(const QString &source, const QString &n);
void vcsAnnotate(const QString &workingDirectory, const QString &file,
const QString &revision, int lineNumber);
void p4Diff(const Perforce::Internal::PerforceDiffParameters &p);
#ifdef WITH_TESTS
private slots:
void testLogResolving();
#endif
protected:
void updateActions(VcsBase::VcsBasePlugin::ActionState);
bool submitEditorAboutToClose();
#ifdef WITH_TESTS
private slots:
void testLogResolving();
#endif
private:
void p4Diff(const PerforceDiffParameters &p);
void openCurrentFile();
void addCurrentFile();
void revertCurrentFile();
......@@ -149,8 +147,7 @@ private:
public:
DirectoryCacheEntry(bool isManaged, const QString &topLevel):
m_isManaged(isManaged), m_topLevel(topLevel)
{
}
{ }
bool m_isManaged;
QString m_topLevel;
......@@ -216,36 +213,36 @@ private:
static PerforceVersionControl *perforceVersionControl();
Core::CommandLocator *m_commandLocator;
Utils::ParameterAction *m_editAction;
Utils::ParameterAction *m_addAction;
Utils::ParameterAction *m_deleteAction;
QAction *m_openedAction;
Utils::ParameterAction *m_revertFileAction;
Utils::ParameterAction *m_diffFileAction;
Utils::ParameterAction *m_diffProjectAction;
Utils::ParameterAction *m_updateProjectAction;
Utils::ParameterAction *m_revertProjectAction;
Utils::ParameterAction *m_revertUnchangedAction;
QAction *m_diffAllAction;
Utils::ParameterAction *m_submitProjectAction;
QAction *m_pendingAction;
QAction *m_describeAction;
Utils::ParameterAction *m_annotateCurrentAction;
QAction *m_annotateAction;
Utils::ParameterAction *m_filelogCurrentAction;
QAction *m_filelogAction;
Utils::ParameterAction *m_logProjectAction;
QAction *m_logRepositoryAction;
QAction *m_submitCurrentLogAction;
QAction *m_updateAllAction;
bool m_submitActionTriggered;
QAction *m_diffSelectedFiles;
Core::CommandLocator *m_commandLocator = nullptr;
Utils::ParameterAction *m_editAction = nullptr;
Utils::ParameterAction *m_addAction = nullptr;
Utils::ParameterAction *m_deleteAction = nullptr;
QAction *m_openedAction = nullptr;
Utils::ParameterAction *m_revertFileAction = nullptr;
Utils::ParameterAction *m_diffFileAction = nullptr;
Utils::ParameterAction *m_diffProjectAction = nullptr;
Utils::ParameterAction *m_updateProjectAction = nullptr;
Utils::ParameterAction *m_revertProjectAction = nullptr;
Utils::ParameterAction *m_revertUnchangedAction = nullptr;
QAction *m_diffAllAction = nullptr;
Utils::ParameterAction *m_submitProjectAction = nullptr;
QAction *m_pendingAction = nullptr;
QAction *m_describeAction = nullptr;
Utils::ParameterAction *m_annotateCurrentAction = nullptr;
QAction *m_annotateAction = nullptr;
Utils::ParameterAction *m_filelogCurrentAction = nullptr;
QAction *m_filelogAction = nullptr;
Utils::ParameterAction *m_logProjectAction = nullptr;
QAction *m_logRepositoryAction = nullptr;
QAction *m_submitCurrentLogAction = nullptr;
QAction *m_updateAllAction = nullptr;
bool m_submitActionTriggered = false;
QAction *m_diffSelectedFiles = nullptr;
QString m_commitMessageFileName;
mutable QString m_tempFilePattern;
QAction *m_undoAction;
QAction *m_redoAction;
QAction *m_menuAction;
QAction *m_undoAction = nullptr;
QAction *m_redoAction = nullptr;
QAction *m_menuAction = nullptr;
static PerforcePlugin *m_instance;
......@@ -255,5 +252,3 @@ private:
} // namespace Perforce
} // namespace Internal
#endif // PERFORCEPLUGIN_H
......@@ -25,13 +25,11 @@
#include "perforcesettings.h"
#include "perforceplugin.h"
#include "perforceconstants.h"
#include <utils/qtcassert.h>
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <QDebug>
#include <QSettings>
#include <QStringList>
#include <QCoreApplication>
......@@ -59,14 +57,8 @@ static QString defaultCommand()