Perforce: Modernize

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

Change-Id: Iaa9c3bbacbb2be3c96502c52cc169ad4ec7015a5
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2016-02-10 14:14:06 +01:00
parent 84f2875f6d
commit 8b46136b60
24 changed files with 113 additions and 298 deletions

View File

@@ -30,14 +30,12 @@ namespace Internal {
PerforceAnnotationHighlighter::PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers, PerforceAnnotationHighlighter::PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document) : QTextDocument *document) :
VcsBase::BaseAnnotationHighlighter(changeNumbers, document), VcsBase::BaseAnnotationHighlighter(changeNumbers, document)
m_colon(QLatin1Char(':')) { }
{
}
QString PerforceAnnotationHighlighter::changeNumber(const QString &block) const 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(); return pos > 1 ? block.left(pos) : QString();
} }

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef ANNOTATIONHIGHLIGHTER_H #pragma once
#define ANNOTATIONHIGHLIGHTER_H
#include <vcsbase/baseannotationhighlighter.h> #include <vcsbase/baseannotationhighlighter.h>
@@ -37,15 +36,11 @@ class PerforceAnnotationHighlighter : public VcsBase::BaseAnnotationHighlighter
Q_OBJECT Q_OBJECT
public: public:
explicit PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers, explicit PerforceAnnotationHighlighter(const ChangeNumbers &changeNumbers,
QTextDocument *document = 0); QTextDocument *document = nullptr);
private: private:
QString changeNumber(const QString &block) const; QString changeNumber(const QString &block) const override;
const QChar m_colon;
}; };
} // namespace Perforce } // namespace Perforce
} // namespace Internal } // namespace Internal
#endif // ANNOTATIONHIGHLIGHTER_H

View File

@@ -29,8 +29,7 @@
using namespace Perforce::Internal; using namespace Perforce::Internal;
ChangeNumberDialog::ChangeNumberDialog(QWidget *parent) ChangeNumberDialog::ChangeNumberDialog(QWidget *parent) : QDialog(parent)
: QDialog(parent)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.numberLineEdit->setValidator(new QIntValidator(0, 1000000, this)); m_ui.numberLineEdit->setValidator(new QIntValidator(0, 1000000, this));

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef CHANGENUMBERDIALOG_H #pragma once
#define CHANGENUMBERDIALOG_H
#include <QDialog> #include <QDialog>
@@ -38,7 +37,7 @@ class ChangeNumberDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
ChangeNumberDialog(QWidget *parent = 0); ChangeNumberDialog(QWidget *parent = nullptr);
int number() const; int number() const;
private: private:
@@ -48,5 +47,3 @@ private:
} // namespace Perforce } // namespace Perforce
} // namespace Internal } // namespace Internal
#endif // CHANGENUMBERDIALOG_H

View File

@@ -30,8 +30,7 @@
using namespace Perforce::Internal; using namespace Perforce::Internal;
PendingChangesDialog::PendingChangesDialog(const QString &data, QWidget *parent) PendingChangesDialog::PendingChangesDialog(const QString &data, QWidget *parent) : QDialog(parent)
: QDialog(parent)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
if (!data.isEmpty()) { if (!data.isEmpty()) {

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PENDINGCHANGESDIALOG_H #pragma once
#define PENDINGCHANGESDIALOG_H
#include <QDialog> #include <QDialog>
@@ -38,7 +37,7 @@ class PendingChangesDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit PendingChangesDialog(const QString &data, QWidget *parent = 0); explicit PendingChangesDialog(const QString &data, QWidget *parent = nullptr);
int changeNumber() const; int changeNumber() const;
private: private:
@@ -47,6 +46,3 @@ private:
} // namespace Perforce } // namespace Perforce
} // namespace Internal } // namespace Internal
#endif // PENDINGCHANGESDIALOG_H

View File

@@ -8,7 +8,6 @@ HEADERS += \
changenumberdialog.h \ changenumberdialog.h \
perforcesubmiteditor.h \ perforcesubmiteditor.h \
pendingchangesdialog.h \ pendingchangesdialog.h \
perforceconstants.h \
perforceversioncontrol.h \ perforceversioncontrol.h \
perforcesettings.h \ perforcesettings.h \
annotationhighlighter.h \ annotationhighlighter.h \

View File

@@ -22,7 +22,6 @@ QtcPlugin {
"perforce.qrc", "perforce.qrc",
"perforcechecker.cpp", "perforcechecker.cpp",
"perforcechecker.h", "perforcechecker.h",
"perforceconstants.h",
"perforceeditor.cpp", "perforceeditor.cpp",
"perforceeditor.h", "perforceeditor.h",
"perforceplugin.cpp", "perforceplugin.cpp",

View File

@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "perforcechecker.h" #include "perforcechecker.h"
#include "perforceconstants.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/synchronousprocess.h> #include <utils/synchronousprocess.h>
@@ -40,12 +39,7 @@
namespace Perforce { namespace Perforce {
namespace Internal { namespace Internal {
PerforceChecker::PerforceChecker(QObject *parent) : PerforceChecker::PerforceChecker(QObject *parent) : QObject(parent)
QObject(parent),
m_timeOutMS(-1),
m_timedOut(false),
m_useOverideCursor(false),
m_isOverrideCursor(false)
{ {
connect(&m_process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), connect(&m_process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
this, &PerforceChecker::slotError); this, &PerforceChecker::slotError);

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCECHECKER_H #pragma once
#define PERFORCECHECKER_H
#include <QObject> #include <QObject>
#include <QProcess> #include <QProcess>
@@ -40,10 +39,9 @@ class PerforceChecker : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PerforceChecker(QObject *parent = 0); explicit PerforceChecker(QObject *parent = nullptr);
~PerforceChecker(); ~PerforceChecker();
public slots:
void start(const QString &binary, void start(const QString &binary,
const QString &workingDirectory, const QString &workingDirectory,
const QStringList &basicArgs = QStringList(), const QStringList &basicArgs = QStringList(),
@@ -72,13 +70,11 @@ private:
QProcess m_process; QProcess m_process;
QString m_binary; QString m_binary;
int m_timeOutMS; int m_timeOutMS = -1;
bool m_timedOut; bool m_timedOut = false;
bool m_useOverideCursor; bool m_useOverideCursor = false;
bool m_isOverrideCursor; bool m_isOverrideCursor = false;
}; };
} } // namespace Internal
} } // namespace Perforce
#endif // PERFORCECHECKER_H

View File

@@ -1,39 +0,0 @@
/****************************************************************************
**
** 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

View File

@@ -26,7 +26,6 @@
#include "perforceeditor.h" #include "perforceeditor.h"
#include "annotationhighlighter.h" #include "annotationhighlighter.h"
#include "perforceconstants.h"
#include "perforceplugin.h" #include "perforceplugin.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
@@ -85,8 +84,6 @@ QSet<QString> PerforceEditorWidget::annotationChanges() const
changes.insert(r.cap(1)); changes.insert(r.cap(1));
} }
} }
if (Perforce::Constants::debug)
qDebug() << "PerforceEditor::annotationChanges() returns #" << changes.size();
return changes; return changes;
} }

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCEEDITOR_H #pragma once
#define PERFORCEEDITOR_H
#include <vcsbase/vcsbaseeditor.h> #include <vcsbase/vcsbaseeditor.h>
@@ -53,5 +52,3 @@ private:
} // namespace Perforce } // namespace Perforce
} // namespace Internal } // namespace Internal
#endif // PERFORCEEDITOR_H

View File

@@ -27,7 +27,6 @@
#include "changenumberdialog.h" #include "changenumberdialog.h"
#include "pendingchangesdialog.h" #include "pendingchangesdialog.h"
#include "perforceconstants.h"
#include "perforceeditor.h" #include "perforceeditor.h"
#include "perforcesubmiteditor.h" #include "perforcesubmiteditor.h"
#include "perforceversioncontrol.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); 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 // Ensure adding "..." to relative paths which is p4's convention
// for the current directory // for the current directory
static inline QString perforceRelativeFileArguments(const QString &args) static inline QString perforceRelativeFileArguments(const QString &args)
@@ -177,37 +171,6 @@ PerforceResponse::PerforceResponse() :
PerforcePlugin *PerforcePlugin::m_instance = NULL; 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 = { static const VcsBaseSubmitEditorParameters submitParameters = {
SUBMIT_MIMETYPE, SUBMIT_MIMETYPE,
PERFORCE_SUBMIT_EDITOR_ID, PERFORCE_SUBMIT_EDITOR_ID,
@@ -890,10 +853,6 @@ bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
const PerforceResponse result = runP4Cmd(m_settings.topLevel(), args, const PerforceResponse result = runP4Cmd(m_settings.topLevel(), args,
RunFullySynchronous); 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")) managed = result.stdOut.contains(QLatin1String("depotFile"))
|| result.stdErr.contains(QLatin1String("... - no such file(s)")); || result.stdErr.contains(QLatin1String("... - no such file(s)"));
} while (false); } while (false);
@@ -904,8 +863,6 @@ bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName, bool silently) bool PerforcePlugin::vcsOpen(const QString &workingDir, const QString &fileName, bool silently)
{ {
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::vcsOpen" << workingDir << fileName;
QStringList args; QStringList args;
args << QLatin1String("edit") << QDir::toNativeSeparators(fileName); 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))); 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); process.setTimeOutMessageBoxEnabled(true);
const SynchronousProcessResponse sp_resp = process.run(settings().p4BinaryPath(), args); const SynchronousProcessResponse sp_resp = process.run(settings().p4BinaryPath(), args);
if (Perforce::Constants::debug)
qDebug() << sp_resp;
PerforceResponse response; PerforceResponse response;
response.error = true; response.error = true;
@@ -1100,9 +1053,6 @@ PerforceResponse PerforcePlugin::fullySynchronousProcess(const QString &workingD
if (!workingDir.isEmpty()) if (!workingDir.isEmpty())
process.setWorkingDirectory(workingDir); process.setWorkingDirectory(workingDir);
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::run fully syncp actual args [" << process.workingDirectory() << ']' << args;
PerforceResponse response; PerforceResponse response;
process.start(settings().p4BinaryPath(), args); process.start(settings().p4BinaryPath(), args);
if (stdInput.isEmpty()) if (stdInput.isEmpty())
@@ -1162,9 +1112,6 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QString &workingDir,
const QByteArray &stdInput, const QByteArray &stdInput,
QTextCodec *outputCodec) QTextCodec *outputCodec)
{ {
if (Perforce::Constants::debug)
qDebug() << "PerforcePlugin::runP4Cmd [" << workingDir << ']' << args << extraArgs << stdInput << debugCodec(outputCodec);
if (!settings().isValid()) { if (!settings().isValid()) {
PerforceResponse invalidConfigResponse; PerforceResponse invalidConfigResponse;
invalidConfigResponse.error = true; invalidConfigResponse.error = true;
@@ -1198,12 +1145,8 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QString &workingDir,
if (flags & ShowBusyCursor) if (flags & ShowBusyCursor)
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
if (response.error) { if (response.error && (flags & ErrorToWindow))
if (Perforce::Constants::debug) VcsOutputWindow::appendError(response.message);
qDebug() << response.message;
if (flags & ErrorToWindow)
VcsOutputWindow::appendError(response.message);
}
return response; return response;
} }
@@ -1216,12 +1159,9 @@ IEditor *PerforcePlugin::showOutputInEditor(const QString &title,
const VcsBaseEditorParameters *params = findType(editorType); const VcsBaseEditorParameters *params = findType(editorType);
QTC_ASSERT(params, return 0); QTC_ASSERT(params, return 0);
const Id id = params->id; 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 s = title;
QString content = output; 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) { if (content.size() >= maxSize) {
content = content.left(maxSize); content = content.left(maxSize);
content += QLatin1Char('\n') + tr("[Only %n MB of output shown]", 0, maxSize / 1024 / 1024); 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); QTC_ASSERT(editor, return 0);
connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)), connect(editor, SIGNAL(annotateRevisionRequested(QString,QString,QString,int)),
this, SLOT(vcsAnnotate(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) if (!e)
return 0; return 0;
e->setForceReadOnly(true); e->setForceReadOnly(true);
@@ -1326,12 +1266,12 @@ void PerforcePlugin::p4Diff(const PerforceDiffParameters &p)
VcsBaseEditor::getSource(p.workingDir, p.files), VcsBaseEditor::getSource(p.workingDir, p.files),
codec); codec);
VcsBaseEditor::tagEditor(editor, tag); 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 // Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor. // parameter change and 'revert' from inside the diff editor.
auto pw = new PerforceDiffParameterWidget(p); auto pw = new PerforceDiffParameterWidget(p);
connect(pw, SIGNAL(reRunDiff(Perforce::Internal::PerforceDiffParameters)), connect(pw, &PerforceDiffParameterWidget::reRunDiff,
this, SLOT(p4Diff(Perforce::Internal::PerforceDiffParameters))); this, [this](const PerforceDiffParameters &p) { p4Diff(p); });
connect(diffEditorWidget, &VcsBaseEditorWidget::diffChunkReverted, connect(diffEditorWidget, &VcsBaseEditorWidget::diffChunkReverted,
pw, &PerforceDiffParameterWidget::triggerReRun); pw, &PerforceDiffParameterWidget::triggerReRun);
diffEditorWidget->setConfigurationWidget(pw); diffEditorWidget->setConfigurationWidget(pw);
@@ -1372,7 +1312,7 @@ bool PerforcePlugin::submitEditorAboutToClose()
{ {
if (!isCommitEditorOpen()) if (!isCommitEditorOpen())
return true; return true;
PerforceSubmitEditor *perforceEditor = qobject_cast<PerforceSubmitEditor *>(submitEditor()); auto perforceEditor = qobject_cast<PerforceSubmitEditor *>(submitEditor());
QTC_ASSERT(perforceEditor, return true); QTC_ASSERT(perforceEditor, return true);
IDocument *editorDocument = perforceEditor->document(); IDocument *editorDocument = perforceEditor->document();
QTC_ASSERT(editorDocument, return true); QTC_ASSERT(editorDocument, return true);
@@ -1437,10 +1377,7 @@ QString PerforcePlugin::clientFilePath(const QString &serverFilePath)
QRegExp r(QLatin1String("\\.\\.\\.\\sclientFile\\s(.+)\n")); QRegExp r(QLatin1String("\\.\\.\\.\\sclientFile\\s(.+)\n"));
r.setMinimal(true); r.setMinimal(true);
const QString path = r.indexIn(response.stdOut) != -1 ? r.cap(1).trimmed() : QString(); return r.indexIn(response.stdOut) != -1 ? r.cap(1).trimmed() : QString();
if (Perforce::Constants::debug)
qDebug() << "clientFilePath" << serverFilePath << path;
return path;
} }
QString PerforcePlugin::pendingChangesData() QString PerforcePlugin::pendingChangesData()
@@ -1466,10 +1403,6 @@ QString PerforcePlugin::pendingChangesData()
return dataResponse.error ? QString() : dataResponse.stdOut; return dataResponse.error ? QString() : dataResponse.stdOut;
} }
PerforcePlugin::~PerforcePlugin()
{
}
const PerforceSettings& PerforcePlugin::settings() const PerforceSettings& PerforcePlugin::settings()
{ {
return m_instance->m_settings; return m_instance->m_settings;
@@ -1526,10 +1459,7 @@ QString PerforcePlugin::fileNameFromPerforceName(const QString& perforceName,
return QString(); return QString();
} }
const QString p4fileSpec = output.mid(output.lastIndexOf(QLatin1Char(' ')) + 1); const QString p4fileSpec = output.mid(output.lastIndexOf(QLatin1Char(' ')) + 1);
const QString rc = m_instance->m_settings.mapToFileSystem(p4fileSpec); return m_instance->m_settings.mapToFileSystem(p4fileSpec);
if (Perforce::Constants::debug)
qDebug() << "fileNameFromPerforceName" << perforceName << p4fileSpec << rc;
return rc;
} }
PerforceVersionControl *PerforcePlugin::perforceVersionControl() PerforceVersionControl *PerforcePlugin::perforceVersionControl()
@@ -1546,15 +1476,11 @@ void PerforcePlugin::setTopLevel(const QString &topLevel)
const QString msg = tr("Perforce repository: %1").arg(QDir::toNativeSeparators(topLevel)); const QString msg = tr("Perforce repository: %1").arg(QDir::toNativeSeparators(topLevel));
VcsOutputWindow::appendSilently(msg); VcsOutputWindow::appendSilently(msg);
if (Perforce::Constants::debug)
qDebug() << "P4: " << topLevel;
} }
void PerforcePlugin::slotTopLevelFailed(const QString &errorMessage) void PerforcePlugin::slotTopLevelFailed(const QString &errorMessage)
{ {
VcsOutputWindow::appendSilently(tr("Perforce: Unable to determine the repository: %1").arg(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) void PerforcePlugin::getTopLevel(const QString &workingDirectory, bool isSync)

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCEPLUGIN_H #pragma once
#define PERFORCEPLUGIN_H
#include "perforcesettings.h" #include "perforcesettings.h"
@@ -76,8 +75,7 @@ class PerforcePlugin : public VcsBase::VcsBasePlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Perforce.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Perforce.json")
public: public:
PerforcePlugin(); PerforcePlugin() = default;
~PerforcePlugin();
bool initialize(const QStringList &arguments, QString *errorMessage); bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized(); void extensionsInitialized();
@@ -105,19 +103,19 @@ public slots:
void describe(const QString &source, const QString &n); void describe(const QString &source, const QString &n);
void vcsAnnotate(const QString &workingDirectory, const QString &file, void vcsAnnotate(const QString &workingDirectory, const QString &file,
const QString &revision, int lineNumber); const QString &revision, int lineNumber);
void p4Diff(const Perforce::Internal::PerforceDiffParameters &p);
protected:
void updateActions(VcsBase::VcsBasePlugin::ActionState);
bool submitEditorAboutToClose();
#ifdef WITH_TESTS #ifdef WITH_TESTS
private slots: private slots:
void testLogResolving(); void testLogResolving();
#endif #endif
protected:
void updateActions(VcsBase::VcsBasePlugin::ActionState);
bool submitEditorAboutToClose();
private: private:
void p4Diff(const PerforceDiffParameters &p);
void openCurrentFile(); void openCurrentFile();
void addCurrentFile(); void addCurrentFile();
void revertCurrentFile(); void revertCurrentFile();
@@ -149,8 +147,7 @@ private:
public: public:
DirectoryCacheEntry(bool isManaged, const QString &topLevel): DirectoryCacheEntry(bool isManaged, const QString &topLevel):
m_isManaged(isManaged), m_topLevel(topLevel) m_isManaged(isManaged), m_topLevel(topLevel)
{ { }
}
bool m_isManaged; bool m_isManaged;
QString m_topLevel; QString m_topLevel;
@@ -216,36 +213,36 @@ private:
static PerforceVersionControl *perforceVersionControl(); static PerforceVersionControl *perforceVersionControl();
Core::CommandLocator *m_commandLocator; Core::CommandLocator *m_commandLocator = nullptr;
Utils::ParameterAction *m_editAction; Utils::ParameterAction *m_editAction = nullptr;
Utils::ParameterAction *m_addAction; Utils::ParameterAction *m_addAction = nullptr;
Utils::ParameterAction *m_deleteAction; Utils::ParameterAction *m_deleteAction = nullptr;
QAction *m_openedAction; QAction *m_openedAction = nullptr;
Utils::ParameterAction *m_revertFileAction; Utils::ParameterAction *m_revertFileAction = nullptr;
Utils::ParameterAction *m_diffFileAction; Utils::ParameterAction *m_diffFileAction = nullptr;
Utils::ParameterAction *m_diffProjectAction; Utils::ParameterAction *m_diffProjectAction = nullptr;
Utils::ParameterAction *m_updateProjectAction; Utils::ParameterAction *m_updateProjectAction = nullptr;
Utils::ParameterAction *m_revertProjectAction; Utils::ParameterAction *m_revertProjectAction = nullptr;
Utils::ParameterAction *m_revertUnchangedAction; Utils::ParameterAction *m_revertUnchangedAction = nullptr;
QAction *m_diffAllAction; QAction *m_diffAllAction = nullptr;
Utils::ParameterAction *m_submitProjectAction; Utils::ParameterAction *m_submitProjectAction = nullptr;
QAction *m_pendingAction; QAction *m_pendingAction = nullptr;
QAction *m_describeAction; QAction *m_describeAction = nullptr;
Utils::ParameterAction *m_annotateCurrentAction; Utils::ParameterAction *m_annotateCurrentAction = nullptr;
QAction *m_annotateAction; QAction *m_annotateAction = nullptr;
Utils::ParameterAction *m_filelogCurrentAction; Utils::ParameterAction *m_filelogCurrentAction = nullptr;
QAction *m_filelogAction; QAction *m_filelogAction = nullptr;
Utils::ParameterAction *m_logProjectAction; Utils::ParameterAction *m_logProjectAction = nullptr;
QAction *m_logRepositoryAction; QAction *m_logRepositoryAction = nullptr;
QAction *m_submitCurrentLogAction; QAction *m_submitCurrentLogAction = nullptr;
QAction *m_updateAllAction; QAction *m_updateAllAction = nullptr;
bool m_submitActionTriggered; bool m_submitActionTriggered = false;
QAction *m_diffSelectedFiles; QAction *m_diffSelectedFiles = nullptr;
QString m_commitMessageFileName; QString m_commitMessageFileName;
mutable QString m_tempFilePattern; mutable QString m_tempFilePattern;
QAction *m_undoAction; QAction *m_undoAction = nullptr;
QAction *m_redoAction; QAction *m_redoAction = nullptr;
QAction *m_menuAction; QAction *m_menuAction = nullptr;
static PerforcePlugin *m_instance; static PerforcePlugin *m_instance;
@@ -255,5 +252,3 @@ private:
} // namespace Perforce } // namespace Perforce
} // namespace Internal } // namespace Internal
#endif // PERFORCEPLUGIN_H

View File

@@ -25,13 +25,11 @@
#include "perforcesettings.h" #include "perforcesettings.h"
#include "perforceplugin.h" #include "perforceplugin.h"
#include "perforceconstants.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <QDebug>
#include <QSettings> #include <QSettings>
#include <QStringList> #include <QStringList>
#include <QCoreApplication> #include <QCoreApplication>
@@ -59,14 +57,8 @@ static QString defaultCommand()
namespace Perforce { namespace Perforce {
namespace Internal { namespace Internal {
Settings::Settings() : Settings::Settings() : logCount(defaultLogCount), timeOutS(defaultTimeOutS)
logCount(defaultLogCount), { }
defaultEnv(true),
timeOutS(defaultTimeOutS),
promptToSubmit(true),
autoOpen(true)
{
}
bool Settings::equals(const Settings &rhs) const bool Settings::equals(const Settings &rhs) const
{ {
@@ -93,12 +85,9 @@ QStringList Settings::commonP4Arguments() const
} }
// --------------------PerforceSettings // --------------------PerforceSettings
PerforceSettings::PerforceSettings()
{
}
PerforceSettings::~PerforceSettings() PerforceSettings::~PerforceSettings()
{ {
delete m_topLevelDir;
} }
void PerforceSettings::fromSettings(QSettings *settings) void PerforceSettings::fromSettings(QSettings *settings)
@@ -220,21 +209,20 @@ void PerforceSettings::setTopLevel(const QString &t)
} else { } else {
m_topLevelSymLinkTarget = m_topLevel = t; m_topLevelSymLinkTarget = m_topLevel = t;
} }
m_topLevelDir.reset(new QDir(m_topLevelSymLinkTarget)); m_topLevelDir = new QDir(m_topLevelSymLinkTarget);
if (Perforce::Constants::debug)
qDebug() << "PerforceSettings::setTopLevel" << m_topLevel << m_topLevelSymLinkTarget;
} }
} }
void PerforceSettings::clearTopLevel() void PerforceSettings::clearTopLevel()
{ {
m_topLevelDir.reset(); delete m_topLevelDir;
m_topLevelDir = nullptr;
m_topLevel.clear(); m_topLevel.clear();
} }
QString PerforceSettings::relativeToTopLevel(const QString &dir) const QString PerforceSettings::relativeToTopLevel(const QString &dir) const
{ {
QTC_ASSERT(!m_topLevelDir.isNull(), return QLatin1String("../") + dir); QTC_ASSERT(m_topLevelDir, return QLatin1String("../") + dir);
return m_topLevelDir->relativeFilePath(dir); return m_topLevelDir->relativeFilePath(dir);
} }

View File

@@ -23,11 +23,9 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCESETTINGS_H #pragma once
#define PERFORCESETTINGS_H
#include <QString> #include <QString>
#include <QScopedPointer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QSettings; class QSettings;
@@ -55,10 +53,10 @@ struct Settings {
QString p4User; QString p4User;
QString errorString; QString errorString;
int logCount; int logCount;
bool defaultEnv; bool defaultEnv = true;
int timeOutS; int timeOutS;
bool promptToSubmit; bool promptToSubmit = true;
bool autoOpen; bool autoOpen = true;
}; };
inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); } inline bool operator==(const Settings &s1, const Settings &s2) { return s1.equals(s2); }
@@ -80,11 +78,10 @@ inline bool operator!=(const Settings &s1, const Settings &s2) { return !s1.equa
class PerforceSettings class PerforceSettings
{ {
Q_DISABLE_COPY(PerforceSettings)
public: public:
PerforceSettings(); PerforceSettings() = default;
~PerforceSettings(); ~PerforceSettings();
PerforceSettings(const PerforceSettings &other) = delete;
inline bool isValid() const inline bool isValid() const
{ {
@@ -139,10 +136,8 @@ private:
Settings m_settings; Settings m_settings;
QString m_topLevel; QString m_topLevel;
QString m_topLevelSymLinkTarget; QString m_topLevelSymLinkTarget;
QScopedPointer<QDir> m_topLevelDir; QDir *m_topLevelDir = nullptr;
}; };
} // Internal } // namespace Internal
} // Perforce } // namespace Perforce
#endif // PERFORCESETTINGS_H

View File

@@ -26,14 +26,11 @@
#include "perforcesubmiteditor.h" #include "perforcesubmiteditor.h"
#include "perforcesubmiteditorwidget.h" #include "perforcesubmiteditorwidget.h"
#include "perforceplugin.h" #include "perforceplugin.h"
#include "perforceconstants.h"
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <vcsbase/submitfilemodel.h> #include <vcsbase/submitfilemodel.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QDebug>
namespace Perforce { namespace Perforce {
namespace Internal { namespace Internal {
@@ -62,15 +59,11 @@ QByteArray PerforceSubmitEditor::fileContents() const
it.next(); it.next();
out << it.key() << ":" << it.value(); out << it.key() << ":" << it.value();
} }
if (Perforce::Constants::debug)
qDebug() << Q_FUNC_INFO << text;
return text.toLocal8Bit(); return text.toLocal8Bit();
} }
bool PerforceSubmitEditor::setFileContents(const QByteArray &contents) bool PerforceSubmitEditor::setFileContents(const QByteArray &contents)
{ {
if (Perforce::Constants::debug)
qDebug() << Q_FUNC_INFO << contents;
if (!parseText(QString::fromUtf8(contents))) if (!parseText(QString::fromUtf8(contents)))
return false; return false;
updateFields(); updateFields();

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCESUBMITEDITOR_H #pragma once
#define PERFORCESUBMITEDITOR_H
#include <vcsbase/vcsbasesubmiteditor.h> #include <vcsbase/vcsbasesubmiteditor.h>
@@ -75,5 +74,3 @@ private:
} // namespace Internal } // namespace Internal
} // namespace Perforce } // namespace Perforce
#endif // PERFORCESUBMITEDITOR_H

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCESUBMITEDITORWIDGET_H #pragma once
#define PERFORCESUBMITEDITORWIDGET_H
#include "ui_submitpanel.h" #include "ui_submitpanel.h"
#include <vcsbase/submiteditorwidget.h> #include <vcsbase/submiteditorwidget.h>
@@ -48,5 +47,3 @@ private:
} // namespace Internal } // namespace Internal
} // namespace Perforce } // namespace Perforce
#endif // PERFORCESUBMITEDITORWIDGET_H

View File

@@ -25,7 +25,6 @@
#include "perforceversioncontrol.h" #include "perforceversioncontrol.h"
#include "perforceplugin.h" #include "perforceplugin.h"
#include "perforceconstants.h"
#include "perforcesettings.h" #include "perforcesettings.h"
#include <vcsbase/vcsbaseconstants.h> #include <vcsbase/vcsbaseconstants.h>
@@ -38,8 +37,7 @@ namespace Internal {
PerforceVersionControl::PerforceVersionControl(PerforcePlugin *plugin) : PerforceVersionControl::PerforceVersionControl(PerforcePlugin *plugin) :
m_plugin(plugin) m_plugin(plugin)
{ { }
}
QString PerforceVersionControl::displayName() const QString PerforceVersionControl::displayName() const
{ {
@@ -140,14 +138,7 @@ QString PerforceVersionControl::vcsMakeWritableText() const
bool PerforceVersionControl::managesDirectory(const QString &directory, QString *topLevel) const bool PerforceVersionControl::managesDirectory(const QString &directory, QString *topLevel) const
{ {
const bool rc = m_plugin->managesDirectory(directory, topLevel); return m_plugin->managesDirectory(directory, topLevel);
if (Perforce::Constants::debug) {
QDebug nsp = qDebug().nospace();
nsp << "managesDirectory" << directory << rc;
if (topLevel)
nsp << topLevel;
}
return rc;
} }
bool PerforceVersionControl::managesFile(const QString &workingDirectory, const QString &fileName) const bool PerforceVersionControl::managesFile(const QString &workingDirectory, const QString &fileName) const

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef PERFORCEVERSIONCONTROL_H #pragma once
#define PERFORCEVERSIONCONTROL_H
#include <coreplugin/iversioncontrol.h> #include <coreplugin/iversioncontrol.h>
@@ -66,7 +65,5 @@ private:
PerforcePlugin *m_plugin; PerforcePlugin *m_plugin;
}; };
} // Internal } // namespace Internal
} // Perforce } // namespace Perforce
#endif // PERFORCEVERSIONCONTROL_H

View File

@@ -49,13 +49,18 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
connect(m_ui.testPushButton, &QPushButton::clicked, this, &SettingsPageWidget::slotTest); connect(m_ui.testPushButton, &QPushButton::clicked, this, &SettingsPageWidget::slotTest);
} }
SettingsPageWidget::~SettingsPageWidget()
{
delete m_checker;
}
void SettingsPageWidget::slotTest() void SettingsPageWidget::slotTest()
{ {
if (!m_checker) { if (!m_checker) {
m_checker = new PerforceChecker(this); m_checker = new PerforceChecker(this);
m_checker->setUseOverideCursor(true); m_checker->setUseOverideCursor(true);
connect(m_checker.data(), &PerforceChecker::failed, this, &SettingsPageWidget::setStatusError); connect(m_checker, &PerforceChecker::failed, this, &SettingsPageWidget::setStatusError);
connect(m_checker.data(), &PerforceChecker::succeeded, this, &SettingsPageWidget::testSucceeded); connect(m_checker, &PerforceChecker::succeeded, this, &SettingsPageWidget::testSucceeded);
} }
if (m_checker->isRunning()) if (m_checker->isRunning())
@@ -118,6 +123,11 @@ SettingsPage::SettingsPage()
setDisplayName(tr("Perforce")); setDisplayName(tr("Perforce"));
} }
SettingsPage::~SettingsPage()
{
delete m_widget;
}
QWidget *SettingsPage::widget() QWidget *SettingsPage::widget()
{ {
if (!m_widget) { if (!m_widget) {
@@ -135,4 +145,5 @@ void SettingsPage::apply()
void SettingsPage::finish() void SettingsPage::finish()
{ {
delete m_widget; delete m_widget;
m_widget = nullptr;
} }

View File

@@ -23,10 +23,8 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef SETTINGSPAGE_H #pragma once
#define SETTINGSPAGE_H
#include <QPointer>
#include <QWidget> #include <QWidget>
#include <vcsbase/vcsbaseoptionspage.h> #include <vcsbase/vcsbaseoptionspage.h>
@@ -46,6 +44,7 @@ class SettingsPageWidget : public QWidget
public: public:
explicit SettingsPageWidget(QWidget *parent = 0); explicit SettingsPageWidget(QWidget *parent = 0);
~SettingsPageWidget() override;
void setSettings(const PerforceSettings &); void setSettings(const PerforceSettings &);
Settings settings() const; Settings settings() const;
@@ -57,7 +56,7 @@ private:
void testSucceeded(const QString &repo); void testSucceeded(const QString &repo);
Ui::SettingsPage m_ui; Ui::SettingsPage m_ui;
QPointer<PerforceChecker> m_checker; PerforceChecker *m_checker = nullptr;
}; };
class SettingsPage : public VcsBase::VcsBaseOptionsPage class SettingsPage : public VcsBase::VcsBaseOptionsPage
@@ -66,16 +65,15 @@ class SettingsPage : public VcsBase::VcsBaseOptionsPage
public: public:
SettingsPage(); SettingsPage();
~SettingsPage() override;
QWidget *widget(); QWidget *widget() override;
void apply(); void apply() override;
void finish(); void finish() override;
private: private:
QPointer<SettingsPageWidget> m_widget; SettingsPageWidget *m_widget = nullptr;
}; };
} // namespace Internal } // namespace Internal
} // namespace Perforce } // namespace Perforce
#endif // SETTINGSPAGE_H