Commit 5b3f3618 authored by Lorenz Haas's avatar Lorenz Haas

Beautifier: Modernize, code style, and clean up

Use nullptr and range based for loops, unify initializer list code
style, remove superfluous includes, make private slots private methods,
get rid of QLatin1(Char|String), use initializer lists and some minor
code style issues.

Change-Id: I94ba10fc96bb628239364a8201bde98a66b2c4c1
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
parent d25b88c3
......@@ -31,7 +31,6 @@
#include <coreplugin/icore.h>
#include <utils/fileutils.h>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QXmlStreamReader>
......@@ -39,13 +38,11 @@
namespace Beautifier {
namespace Internal {
AbstractSettings::AbstractSettings(const QString &name, const QString &ending)
: m_version(0)
, m_ending(ending)
, m_styleDir(Core::ICore::userResourcePath() + QLatin1Char('/')
+ QLatin1String(Beautifier::Constants::SETTINGS_DIRNAME) + QLatin1Char('/')
+ name)
, m_name(name)
AbstractSettings::AbstractSettings(const QString &name, const QString &ending) :
m_ending(ending),
m_styleDir(Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME
+ '/' + name),
m_name(name)
{
}
......@@ -163,14 +160,14 @@ void AbstractSettings::save()
{
// Save settings, except styles
QSettings *s = Core::ICore::settings();
s->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
s->beginGroup(Constants::SETTINGS_GROUP);
s->beginGroup(m_name);
QMap<QString, QVariant>::const_iterator iSettings = m_settings.constBegin();
while (iSettings != m_settings.constEnd()) {
s->setValue(iSettings.key(), iSettings.value());
++iSettings;
}
s->setValue(QLatin1String("command"), m_command);
s->setValue("command", m_command);
s->endGroup();
s->endGroup();
......@@ -230,11 +227,11 @@ void AbstractSettings::read()
{
// Read settings, except styles
QSettings *s = Core::ICore::settings();
s->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
s->beginGroup(Constants::SETTINGS_GROUP);
s->beginGroup(m_name);
const QStringList keys = s->allKeys();
foreach (const QString &key, keys) {
if (key == QLatin1String("command"))
for (const QString &key : keys) {
if (key == "command")
setCommand(s->value(key).toString());
else if (m_settings.contains(key))
m_settings[key] = s->value(key);
......@@ -270,7 +267,7 @@ void AbstractSettings::readDocumentation()
QXmlStreamReader xml(&file);
if (!xml.readNextStartElement())
return;
if (xml.name() != QLatin1String(Constants::DOCUMENTATION_XMLROOT)) {
if (xml.name() != Constants::DOCUMENTATION_XMLROOT) {
BeautifierPlugin::showError(tr("The file \"%1\" is not a valid documentation file.")
.arg(filename));
return;
......@@ -285,16 +282,16 @@ void AbstractSettings::readDocumentation()
while (!(xml.atEnd() || xml.hasError())) {
if (xml.readNext() == QXmlStreamReader::StartElement) {
const QStringRef &name = xml.name();
if (name == QLatin1String(Constants::DOCUMENTATION_XMLENTRY)) {
if (name == Constants::DOCUMENTATION_XMLENTRY) {
keys.clear();
} else if (name == QLatin1String(Constants::DOCUMENTATION_XMLKEY)) {
} else if (name == Constants::DOCUMENTATION_XMLKEY) {
if (xml.readNext() == QXmlStreamReader::Characters)
keys << xml.text().toString();
} else if (name == QLatin1String(Constants::DOCUMENTATION_XMLDOC)) {
} else if (name == Constants::DOCUMENTATION_XMLDOC) {
if (xml.readNext() == QXmlStreamReader::Characters) {
m_docu << xml.text().toString();
const int index = m_docu.size() - 1;
foreach (const QString &key, keys)
for (const QString &key : keys)
m_options.insert(key, index);
}
}
......@@ -313,9 +310,9 @@ void AbstractSettings::readStyles()
return;
const QStringList files
= m_styleDir.entryList(QStringList() << QLatin1Char('*') + m_ending,
= m_styleDir.entryList({'*' + m_ending},
QDir::Files | QDir::Readable | QDir::NoDotAndDotDot);
foreach (const QString &filename, files) {
for (const QString &filename : files) {
// do not allow empty file names
if (filename == m_ending)
continue;
......
......@@ -71,7 +71,7 @@ public:
protected:
QMap<QString, QString> m_styles;
QMap<QString, QVariant> m_settings;
int m_version;
int m_version = 0;
QString m_ending;
QDir m_styleDir;
......
......@@ -40,8 +40,6 @@
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
#include <projectexplorer/projecttree.h>
......@@ -71,7 +69,7 @@ ArtisticStyle::~ArtisticStyle()
bool ArtisticStyle::initialize()
{
Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::ArtisticStyle::MENU_ID);
menu->menu()->setTitle(QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME));
menu->menu()->setTitle(Constants::ArtisticStyle::DISPLAY_NAME);
m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this);
menu->addAction(Core::ActionManager::registerAction(m_formatFile,
......@@ -90,8 +88,7 @@ void ArtisticStyle::updateActions(Core::IEditor *editor)
QList<QObject *> ArtisticStyle::autoReleaseObjects()
{
ArtisticStyleOptionsPage *optionsPage = new ArtisticStyleOptionsPage(m_settings, this);
return QList<QObject *>() << optionsPage;
return {new ArtisticStyleOptionsPage(m_settings, this)};
}
void ArtisticStyle::formatFile()
......@@ -99,7 +96,7 @@ void ArtisticStyle::formatFile()
const QString cfgFileName = configurationFile();
if (cfgFileName.isEmpty()) {
BeautifierPlugin::showError(BeautifierPlugin::msgCannotGetConfigurationFile(
QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
Constants::ArtisticStyle::DISPLAY_NAME));
} else {
m_beautifierPlugin->formatCurrentFile(command(cfgFileName));
}
......@@ -114,8 +111,8 @@ QString ArtisticStyle::configurationFile() const
if (const ProjectExplorer::Project *project
= ProjectExplorer::ProjectTree::currentProject()) {
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
foreach (const QString &file, files) {
if (!file.endsWith(QLatin1String(".astylerc")))
for (const QString &file : files) {
if (!file.endsWith(".astylerc"))
continue;
const QFileInfo fi(file);
if (fi.isReadable())
......@@ -126,10 +123,10 @@ QString ArtisticStyle::configurationFile() const
if (m_settings->useHomeFile()) {
const QDir homeDirectory = QDir::home();
QString file = homeDirectory.filePath(QLatin1String(".astylerc"));
QString file = homeDirectory.filePath(".astylerc");
if (QFile::exists(file))
return file;
file = homeDirectory.filePath(QLatin1String("astylerc"));
file = homeDirectory.filePath("astylerc");
if (QFile::exists(file))
return file;
}
......@@ -141,15 +138,15 @@ Command ArtisticStyle::command(const QString &cfgFile) const
{
Command command;
command.setExecutable(m_settings->command());
command.addOption(QLatin1String("-q"));
command.addOption(QLatin1String("--options=") + cfgFile);
command.addOption("-q");
command.addOption("--options=" + cfgFile);
if (m_settings->version() > ArtisticStyleSettings::Version_2_03) {
command.setProcessing(Command::PipeProcessing);
command.setPipeAddsNewline(true);
command.setReturnsCRLF(Utils::HostOsInfo::isWindowsHost());
} else {
command.addOption(QLatin1String("%file"));
command.addOption("%file");
}
return command;
......
......@@ -44,18 +44,16 @@ class ArtisticStyle : public BeautifierAbstractTool
Q_OBJECT
public:
explicit ArtisticStyle(BeautifierPlugin *parent = 0);
explicit ArtisticStyle(BeautifierPlugin *parent = nullptr);
virtual ~ArtisticStyle();
bool initialize() override;
void updateActions(Core::IEditor *editor) override;
QList<QObject *> autoReleaseObjects() override;
private slots:
void formatFile();
private:
void formatFile();
BeautifierPlugin *m_beautifierPlugin;
QAction *m_formatFile;
QAction *m_formatFile = nullptr;
ArtisticStyleSettings *m_settings;
QString configurationFile() const;
Command command(const QString &cfgFile) const;
......
......@@ -29,11 +29,11 @@ namespace Beautifier {
namespace Constants {
namespace ArtisticStyle {
const char DISPLAY_NAME[] = "Artistic Style";
const char ACTION_FORMATFILE[] = "ArtisticStyle.FormatFile";
const char MENU_ID[] = "ArtisticStyle.Menu";
const char OPTION_ID[] = "ArtisticStyle";
const char SETTINGS_NAME[] = "artisticstyle";
const char DISPLAY_NAME[] = "Artistic Style";
const char ACTION_FORMATFILE[] = "ArtisticStyle.FormatFile";
const char MENU_ID[] = "ArtisticStyle.Menu";
const char OPTION_ID[] = "ArtisticStyle";
const char SETTINGS_NAME[] = "artisticstyle";
} // namespace ArtisticStyle
} // namespace Constants
......
......@@ -34,25 +34,22 @@
#include <coreplugin/icore.h>
#include <QTextStream>
namespace Beautifier {
namespace Internal {
namespace ArtisticStyle {
ArtisticStyleOptionsPageWidget::ArtisticStyleOptionsPageWidget(ArtisticStyleSettings *settings,
QWidget *parent)
: QWidget(parent)
, ui(new Ui::ArtisticStyleOptionsPage)
, m_settings(settings)
QWidget *parent) :
QWidget(parent),
ui(new Ui::ArtisticStyleOptionsPage),
m_settings(settings)
{
ui->setupUi(this);
ui->useHomeFile->setText(ui->useHomeFile->text().replace(
QLatin1String("HOME"),
QDir::toNativeSeparators(QDir::home().absolutePath())));
"HOME", QDir::toNativeSeparators(QDir::home().absolutePath())));
ui->command->setExpectedKind(Utils::PathChooser::ExistingCommand);
ui->command->setPromptDialogTitle(BeautifierPlugin::msgCommandPromptDialogTitle(
QLatin1String(Constants::ArtisticStyle::DISPLAY_NAME)));
Constants::ArtisticStyle::DISPLAY_NAME));
connect(ui->command, &Utils::PathChooser::validChanged, ui->options, &QWidget::setEnabled);
ui->configurations->setSettings(m_settings);
}
......@@ -81,18 +78,15 @@ void ArtisticStyleOptionsPageWidget::apply()
m_settings->save();
}
/* ---------------------------------------------------------------------------------------------- */
ArtisticStyleOptionsPage::ArtisticStyleOptionsPage(ArtisticStyleSettings *settings, QObject *parent) :
IOptionsPage(parent),
m_widget(0),
m_settings(settings)
{
setId(Constants::ArtisticStyle::OPTION_ID);
setDisplayName(tr("Artistic Style"));
setCategory(Constants::OPTION_CATEGORY);
setDisplayCategory(QCoreApplication::translate("Beautifier", Constants::OPTION_TR_CATEGORY));
setCategoryIcon(QLatin1String(Constants::OPTION_CATEGORY_ICON));
setCategoryIcon(Constants::OPTION_CATEGORY_ICON);
}
QWidget *ArtisticStyleOptionsPage::widget()
......
......@@ -43,7 +43,8 @@ class ArtisticStyleOptionsPageWidget : public QWidget
Q_OBJECT
public:
explicit ArtisticStyleOptionsPageWidget(ArtisticStyleSettings *settings, QWidget *parent = 0);
explicit ArtisticStyleOptionsPageWidget(ArtisticStyleSettings *settings,
QWidget *parent = nullptr);
virtual ~ArtisticStyleOptionsPageWidget();
void restore();
void apply();
......@@ -58,7 +59,7 @@ class ArtisticStyleOptionsPage : public Core::IOptionsPage
Q_OBJECT
public:
explicit ArtisticStyleOptionsPage(ArtisticStyleSettings *settings, QObject *parent = 0);
explicit ArtisticStyleOptionsPage(ArtisticStyleSettings *settings, QObject *parent = nullptr);
QWidget *widget() override;
void apply() override;
void finish() override;
......
......@@ -44,31 +44,30 @@ namespace Internal {
namespace ArtisticStyle {
namespace {
const char kUseOtherFiles[] = "useOtherFiles";
const char kUseHomeFile[] = "useHomeFile";
const char kUseCustomStyle[] = "useCustomStyle";
const char kCustomStyle[] = "customStyle";
const char USE_OTHER_FILES[] = "useOtherFiles";
const char USE_HOME_FILE[] = "useHomeFile";
const char USE_CUSTOM_STYLE[] = "useCustomStyle";
const char CUSTOM_STYLE[] = "customStyle";
}
ArtisticStyleSettings::ArtisticStyleSettings() :
AbstractSettings(QLatin1String(Constants::ArtisticStyle::SETTINGS_NAME),
QLatin1String(".astyle"))
AbstractSettings(Constants::ArtisticStyle::SETTINGS_NAME, ".astyle")
{
connect(&m_versionWatcher, &QFutureWatcherBase::finished,
this, &ArtisticStyleSettings::helperSetVersion);
setCommand(QLatin1String("astyle"));
m_settings.insert(QLatin1String(kUseOtherFiles), QVariant(true));
m_settings.insert(QLatin1String(kUseHomeFile), QVariant(false));
m_settings.insert(QLatin1String(kUseCustomStyle), QVariant(false));
m_settings.insert(QLatin1String(kCustomStyle), QVariant());
setCommand("astyle");
m_settings.insert(USE_OTHER_FILES, QVariant(true));
m_settings.insert(USE_HOME_FILE, QVariant(false));
m_settings.insert(USE_CUSTOM_STYLE, QVariant(false));
m_settings.insert(CUSTOM_STYLE, QVariant());
read();
}
static int parseVersion(const QString &text)
{
// The version in Artistic Style is printed like "Artistic Style Version 2.04"
const QRegExp rx(QLatin1String("([2-9]{1})\\.([0-9]{2})(\\.[1-9]{1})?$"));
const QRegExp rx("([2-9]{1})\\.([0-9]{2})(\\.[1-9]{1})?$");
if (rx.indexIn(text) != -1) {
const int major = rx.cap(1).toInt() * 100;
const int minor = rx.cap(2).toInt();
......@@ -80,7 +79,7 @@ static int parseVersion(const QString &text)
static int updateVersionHelper(const QString &command)
{
QProcess process;
process.start(command, QStringList() << QLatin1String("--version"));
process.start(command, {"--version"});
if (!process.waitForFinished()) {
process.kill();
return 0;
......@@ -109,56 +108,55 @@ void ArtisticStyleSettings::helperSetVersion()
bool ArtisticStyleSettings::useOtherFiles() const
{
return m_settings.value(QLatin1String(kUseOtherFiles)).toBool();
return m_settings.value(USE_OTHER_FILES).toBool();
}
void ArtisticStyleSettings::setUseOtherFiles(bool useOtherFiles)
{
m_settings.insert(QLatin1String(kUseOtherFiles), QVariant(useOtherFiles));
m_settings.insert(USE_OTHER_FILES, QVariant(useOtherFiles));
}
bool ArtisticStyleSettings::useHomeFile() const
{
return m_settings.value(QLatin1String(kUseHomeFile)).toBool();
return m_settings.value(USE_HOME_FILE).toBool();
}
void ArtisticStyleSettings::setUseHomeFile(bool useHomeFile)
{
m_settings.insert(QLatin1String(kUseHomeFile), QVariant(useHomeFile));
m_settings.insert(USE_HOME_FILE, QVariant(useHomeFile));
}
bool ArtisticStyleSettings::useCustomStyle() const
{
return m_settings.value(QLatin1String(kUseCustomStyle)).toBool();
return m_settings.value(USE_CUSTOM_STYLE).toBool();
}
void ArtisticStyleSettings::setUseCustomStyle(bool useCustomStyle)
{
m_settings.insert(QLatin1String(kUseCustomStyle), QVariant(useCustomStyle));
m_settings.insert(USE_CUSTOM_STYLE, QVariant(useCustomStyle));
}
QString ArtisticStyleSettings::customStyle() const
{
return m_settings.value(QLatin1String(kCustomStyle)).toString();
return m_settings.value(CUSTOM_STYLE).toString();
}
void ArtisticStyleSettings::setCustomStyle(const QString &customStyle)
{
m_settings.insert(QLatin1String(kCustomStyle), QVariant(customStyle));
m_settings.insert(CUSTOM_STYLE, QVariant(customStyle));
}
QString ArtisticStyleSettings::documentationFilePath() const
{
return Core::ICore::userResourcePath() + QLatin1Char('/')
+ QLatin1String(Beautifier::Constants::SETTINGS_DIRNAME) + QLatin1Char('/')
+ QLatin1String(Beautifier::Constants::DOCUMENTATION_DIRNAME) + QLatin1Char('/')
+ QLatin1String(Constants::ArtisticStyle::SETTINGS_NAME) + QLatin1String(".xml");
return Core::ICore::userResourcePath() + '/' + Beautifier::Constants::SETTINGS_DIRNAME + '/'
+ Beautifier::Constants::DOCUMENTATION_DIRNAME + '/'
+ Constants::ArtisticStyle::SETTINGS_NAME + ".xml";
}
void ArtisticStyleSettings::createDocumentationFile() const
{
QProcess process;
process.start(command(), QStringList() << QLatin1String("-h"));
process.start(command(), {"-h"});
process.waitForFinished(2000); // show help should be really fast.
if (process.error() != QProcess::UnknownError)
return;
......@@ -173,43 +171,39 @@ void ArtisticStyleSettings::createDocumentationFile() const
bool contextWritten = false;
QXmlStreamWriter stream(&file);
stream.setAutoFormatting(true);
stream.writeStartDocument(QLatin1String("1.0"), true);
stream.writeComment(QLatin1String("Created ")
+ QDateTime::currentDateTime().toString(Qt::ISODate));
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLROOT));
stream.writeStartDocument("1.0", true);
stream.writeComment("Created " + QDateTime::currentDateTime().toString(Qt::ISODate));
stream.writeStartElement(Constants::DOCUMENTATION_XMLROOT);
// astyle writes its output to 'error'...
const QStringList lines = QString::fromUtf8(process.readAllStandardError())
.split(QLatin1Char('\n'));
.split('\n');
QStringList keys;
QStringList docu;
foreach (QString line, lines) {
for (QString line : lines) {
line = line.trimmed();
if ((line.startsWith(QLatin1String("--")) && !line.startsWith(QLatin1String("---")))
|| line.startsWith(QLatin1String("OR "))) {
QStringList rawKeys = line.split(QLatin1String(" OR "), QString::SkipEmptyParts);
foreach (QString k, rawKeys) {
if ((line.startsWith("--") && !line.startsWith("---")) || line.startsWith("OR ")) {
const QStringList rawKeys = line.split(" OR ", QString::SkipEmptyParts);
for (QString k : rawKeys) {
k = k.trimmed();
k.remove(QLatin1Char('#'));
k.remove('#');
keys << k;
if (k.startsWith(QLatin1String("--")))
if (k.startsWith("--"))
keys << k.right(k.size() - 2);
}
} else {
if (line.isEmpty()) {
if (!keys.isEmpty()) {
// Write entry
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLENTRY));
stream.writeStartElement(QLatin1String(Constants::DOCUMENTATION_XMLKEYS));
foreach (const QString &key, keys)
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLKEY), key);
stream.writeStartElement(Constants::DOCUMENTATION_XMLENTRY);
stream.writeStartElement(Constants::DOCUMENTATION_XMLKEYS);
for (const QString &key : keys)
stream.writeTextElement(Constants::DOCUMENTATION_XMLKEY, key);
stream.writeEndElement();
const QString text = QLatin1String("<p><span class=\"option\">")
+ keys.filter(QRegExp(QLatin1String("^\\-"))).join(QLatin1String(", "))
+ QLatin1String("</span></p><p>")
+ (docu.join(QLatin1Char(' ')).toHtmlEscaped())
+ QLatin1String("</p>");
stream.writeTextElement(QLatin1String(Constants::DOCUMENTATION_XMLDOC), text);
const QString text = "<p><span class=\"option\">"
+ keys.filter(QRegExp("^\\-")).join(", ") + "</span></p><p>"
+ (docu.join(' ').toHtmlEscaped()) + "</p>";
stream.writeTextElement(Constants::DOCUMENTATION_XMLDOC, text);
stream.writeEndElement();
contextWritten = true;
}
......
......@@ -27,7 +27,6 @@
#include "../abstractsettings.h"
#include <QFuture>
#include <QFutureWatcher>
......@@ -63,10 +62,8 @@ public:
QString documentationFilePath() const override;
void createDocumentationFile() const override;
private slots:
void helperSetVersion();
private:
void helperSetVersion();
QFuture<int> m_versionFuture;
QFutureWatcher<int> m_versionWatcher;
};
......
......@@ -38,7 +38,7 @@ class BeautifierAbstractTool : public QObject
Q_OBJECT
public:
explicit BeautifierAbstractTool(QObject *parent = 0) : QObject(parent) {}
explicit BeautifierAbstractTool(QObject *parent = nullptr) : QObject(parent) {}
virtual ~BeautifierAbstractTool() {}
virtual bool initialize() = 0;
......
......@@ -37,20 +37,15 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <diffeditor/differ.h>
#include <texteditor/convenience.h>
#include <texteditor/textdocument.h>
#include <texteditor/textdocumentlayout.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditorconstants.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
#include <QAction>
#include <QDir>
#include <QFileInfo>
#include <QFutureWatcher>
......@@ -59,7 +54,6 @@
#include <QProcess>
#include <QScrollBar>
#include <QTextBlock>
#include <QtPlugin>
using namespace TextEditor;
......@@ -79,7 +73,7 @@ FormatTask format(FormatTask task)
case Command::FileProcessing: {
// Save text to temporary file
const QFileInfo fi(task.filePath);
Utils::TempFileSaver sourceFile(QDir::tempPath() + QLatin1String("/qtc_beautifier_XXXXXXXX.")
Utils::TempFileSaver sourceFile(QDir::tempPath() + "/qtc_beautifier_XXXXXXXX."
+ fi.suffix());
sourceFile.setAutoRemove(true);
sourceFile.write(task.sourceData.toUtf8());
......@@ -92,7 +86,7 @@ FormatTask format(FormatTask task)
// Format temporary file
QProcess process;
QStringList options = task.command.options();
options.replaceInStrings(QLatin1String("%file"), sourceFile.fileName());
options.replaceInStrings("%file", sourceFile.fileName());
process.start(executable, options);
if (!process.waitForFinished(5000)) {
process.kill();
......@@ -103,7 +97,7 @@ FormatTask format(FormatTask task)
}
const QByteArray output = process.readAllStandardError();
if (!output.isEmpty())
task.error = executable + QLatin1String(": ") + QString::fromUtf8(output);
task.error = executable + ": " + QString::fromUtf8(output);
// Read text back
Utils::FileReader reader;
......@@ -114,13 +108,13 @@ FormatTask format(FormatTask task)
}
task.formattedData = QString::fromUtf8(reader.data());
return task;
} break;
}
case Command::PipeProcessing: {
QProcess process;
QStringList options = task.command.options();
options.replaceInStrings(QLatin1String("%filename"), QFileInfo(task.filePath).fileName());
options.replaceInStrings(QLatin1String("%file"), task.filePath);
options.replaceInStrings("%filename", QFileInfo(task.filePath).fileName());
options.replaceInStrings("%file", task.filePath);
process.start(executable, options);
if (!process.waitForStarted(3000)) {
task.error = QObject::tr("Cannot call %1 or some other error occurred.")
......@@ -148,9 +142,9 @@ FormatTask format(FormatTask task)
if (addsNewline || returnsCRLF) {
task.formattedData = QString::fromUtf8(process.readAllStandardOutput());
if (addsNewline)
task.formattedData.remove(QRegExp(QLatin1String("(\\r\\n|\\n)$")));
task.formattedData.remove(QRegExp("(\\r\\n|\\n)$"));
if (returnsCRLF)
task.formattedData.replace(QLatin1String("\r\n"), QLatin1String("\n"));
task.formattedData.replace("\r\n", "\n");
return task;
}
task.formattedData = QString::fromUtf8(process.readAllStandardOutput());
...