Python: Apply 'static' pattern for singleton members

Plus some cosmetics.

Change-Id: Ia2c8f425f0491fbe6a0bbf2e508857a5550e4d38
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2022-04-26 10:21:12 +02:00
parent 28cfdf388a
commit 0da130c4ef
6 changed files with 18 additions and 15 deletions

View File

@@ -60,16 +60,16 @@ PySideInstaller *PySideInstaller::instance()
return instance;
}
void PySideInstaller::checkPySideInstallation(const Utils::FilePath &python,
void PySideInstaller::checkPySideInstallation(const FilePath &python,
TextEditor::TextDocument *document)
{
document->infoBar()->removeInfo(installPySideInfoBarId);
const QString pySide = importedPySide(document->plainText());
if (pySide == "PySide2" || pySide == "PySide6")
runPySideChecker(python, pySide, document);
instance()->runPySideChecker(python, pySide, document);
}
bool PySideInstaller::missingPySideInstallation(const Utils::FilePath &pythonPath,
bool PySideInstaller::missingPySideInstallation(const FilePath &pythonPath,
const QString &pySide)
{
QTC_ASSERT(!pySide.isEmpty(), return false);
@@ -78,8 +78,7 @@ bool PySideInstaller::missingPySideInstallation(const Utils::FilePath &pythonPat
return false;
QtcProcess pythonProcess;
const CommandLine importPySideCheck(pythonPath, {"-c", "import " + pySide});
pythonProcess.setCommand(importPySideCheck);
pythonProcess.setCommand({pythonPath, {"-c", "import " + pySide}});
pythonProcess.runBlocking();
const bool missing = pythonProcess.result() != ProcessResult::FinishedWithSuccess;
if (!missing)

View File

@@ -40,9 +40,11 @@ namespace Internal {
class PySideInstaller : public QObject
{
Q_DECLARE_TR_FUNCTIONS(Python::Internal::PySideInstaller)
public:
static PySideInstaller *instance();
void checkPySideInstallation(const Utils::FilePath &python, TextEditor::TextDocument *document);
static void checkPySideInstallation(const Utils::FilePath &python,
TextEditor::TextDocument *document);
private:
PySideInstaller();

View File

@@ -118,8 +118,8 @@ public:
if (!python.exists())
return;
PyLSConfigureAssistant::instance()->openDocumentWithPython(python, this);
PySideInstaller::instance()->checkPySideInstallation(python, this);
PyLSConfigureAssistant::openDocumentWithPython(python, this);
PySideInstaller::checkPySideInstallation(python, this);
}
};

View File

@@ -614,7 +614,7 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
QPointer<CheckPylsWatcher> watcher = new CheckPylsWatcher();
// cancel and delete watcher after a 10 second timeout
QTimer::singleShot(10000, this, [watcher]() {
QTimer::singleShot(10000, instance(), [watcher]() {
if (watcher) {
watcher->cancel();
watcher->deleteLater();
@@ -623,11 +623,11 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
connect(watcher,
&CheckPylsWatcher::resultReadyAt,
this,
instance(),
[=, document = QPointer<TextEditor::TextDocument>(document)]() {
if (!document || !watcher)
return;
handlePyLSState(python, watcher->result(), document);
instance()->handlePyLSState(python, watcher->result(), document);
watcher->deleteLater();
});
watcher->setFuture(Utils::runAsync(&checkPythonLanguageServer, python));

View File

@@ -71,9 +71,11 @@ public:
static const LanguageClient::StdIOSettings *languageServerForPython(
const Utils::FilePath &python);
static void updateEditorInfoBars(const Utils::FilePath &python, LanguageClient::Client *client);
void openDocumentWithPython(const Utils::FilePath &python, TextEditor::TextDocument *document);
static void updateEditorInfoBars(const Utils::FilePath &python,
LanguageClient::Client *client);
static void openDocumentWithPython(const Utils::FilePath &python,
TextEditor::TextDocument *document);
private:
explicit PyLSConfigureAssistant(QObject *parent);

View File

@@ -152,8 +152,8 @@ public:
for (FilePath &file : project()->files(Project::AllFiles)) {
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
PyLSConfigureAssistant::instance()->openDocumentWithPython(python, document);
PySideInstaller::instance()->checkPySideInstallation(python, document);
PyLSConfigureAssistant::openDocumentWithPython(python, document);
PySideInstaller::checkPySideInstallation(python, document);
}
}
}