Skip to content

Commit 7816c38

Browse files
committed
ENH: Convert signal parameters to be const reference
Refactor signal definitions to use `const` reference types, ensuring improved performance and adherence to modern Qt coding standards ```python import re import sys PRIMITIVE = { "bool","char","signed char","unsigned char", "short","unsigned short","int","unsigned int", "long","unsigned long","long long","unsigned long long", "float","double","long double", "char16_t","char32_t","wchar_t" } signal_proto = re.compile( r'^(?P<indent>\s*)void\s+(?P<function_name>[\w:<>]+)\s*\(\s*(?P<variable_type>[\w:<>]+)\s*(?P<variable_name>[\w:<>]*)\)\s*;\s*$' ) def is_primitive(typ: str) -> bool: t = typ.strip() # ignore parameter names t = re.sub(r'\b\w+\s*$', '', t).strip() return t in PRIMITIVE def process(lines): out = [] in_signals = False for line in lines: if re.match(r'^\s*Q_SIGNALS\s*:', line): # Q_SIGNALS indicates the start of a block in_signals = True out.append(line) continue elif re.match(r'^\s*.*:\s*$', line): in_signals = False out.append(line) continue if in_signals: pm = signal_proto.match(line) if not pm: out.append(line) continue else: indent = pm.group('indent') function_name = pm.group('function_name') variable_type = pm.group('variable_type').strip() variable_name = pm.group('variable_name').strip() if len(variable_name) > 1: variable_name = f" {variable_name}" # insert space before name if variable_type.strip() in PRIMITIVE: out.append(line) continue if "*" in variable_type: # Skip pointers out.append(line) continue if "&" in variable_type: # Skip references out.append(line) continue if pm: new = f"{indent}void {function_name}(const {variable_type} &{variable_name});\n" out.append(new) continue out.append(line) return out def convert(src, dst=None): with open(src) as f: lines = f.readlines() transformed = process(lines) out = open(dst, 'w') if dst else sys.stdout out.writelines(transformed) if dst: out.close() if __name__ == '__main__': if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} <header.h> [<out.h>]") sys.exit(1) convert(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else None) ```
1 parent 37bda40 commit 7816c38

File tree

83 files changed

+336
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+336
-338
lines changed

Applications/ctkEventBusDemo/ctkEventBusDemoMainWindow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class ctkEventDemo : public QObject {
1414
Q_OBJECT
1515

1616
Q_SIGNALS:
17-
void receiveEventSignal(QVariantList l);
18-
void updateMessageSignal(QString message);
17+
void receiveEventSignal(const QVariantList &l);
18+
void updateMessageSignal(const QString & message);
1919

2020
public Q_SLOTS:
2121
void receiveEvent(QVariantList l);

Libs/Core/ctkAbstractJob.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ class CTK_CORE_EXPORT ctkAbstractJob : public QObject
196196
void failed();
197197
void finished();
198198
void jobUIDChanged();
199-
void statusChanged(ctkAbstractJob::JobStatus status);
199+
void statusChanged(const ctkAbstractJob::JobStatus & status);
200200
void isPersistentChanged(bool persistent);
201201
void retryCounterChanged(bool retryCounter);
202202
void maximumConcurrentJobsPerTypeChanged(bool maximumConcurrentJobsPerType);
203203
void maximumNumberOfRetryChanged(int maximumNumberOfRetry);
204204
void retryDelayChanged(int retryDelay);
205-
void priorityChanged(QThread::Priority priority);
206-
void runningThreadIDChanged(QString runningThreadID);
205+
void priorityChanged(const QThread::Priority & priority);
206+
void runningThreadIDChanged(const QString & runningThreadID);
207207
void destroyAfterUseChanged(bool destroyAfterUse);
208208

209209
protected:

Libs/Core/ctkCoreSettings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class CTK_CORE_EXPORT ctkCoreSettings : public QSettings
6262
Q_PROPERTY(QString applicationHomePlaceholder READ applicationHomePlaceholder WRITE setApplicationHomePlaceholder NOTIFY applicationHomePlaceholderChanged);
6363

6464
Q_SIGNALS:
65-
void applicationHomeDirectoryChanged(QString);
66-
void applicationHomePlaceholderChanged(QString);
65+
void applicationHomeDirectoryChanged(const QString &);
66+
void applicationHomePlaceholderChanged(const QString &);
6767
public:
6868
/// \see QSettings::QSettings(const QString& ,const QString& , QObject* )
6969
ctkCoreSettings(

Libs/Core/ctkErrorLogAbstractModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public Q_SLOTS:
163163
/// Since an entryAdded() signal with more parameters was added, this signal is somewhat redundant,
164164
/// but it is kept for backward compatibility.
165165
/// \sa addEntry()
166-
void entryAdded(ctkErrorLogLevel::LogLevel logLevel);
166+
void entryAdded(const ctkErrorLogLevel::LogLevel & logLevel);
167167

168168
/// Called when an entry is added.
169169
/// \sa addEntry()
@@ -178,7 +178,7 @@ public Q_SLOTS:
178178
const QString& origin, const ctkErrorLogContext& context, const QString& text);
179179

180180
void logEntryGroupingChanged(bool);
181-
void terminalOutputsChanged(ctkErrorLogTerminalOutput::TerminalOutputs);
181+
void terminalOutputsChanged(const ctkErrorLogTerminalOutput::TerminalOutputs &);
182182
void asynchronousLoggingChanged(bool);
183183
void filePathChanged(const QString& filePath);
184184
void numberOfFilesToKeepChanged(int);

Libs/Core/ctkFileLogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CTK_CORE_EXPORT ctkFileLogger : public QObject
4040

4141
Q_SIGNALS:
4242
void enabledChanged(bool);
43-
void filePathChanged(QString);
43+
void filePathChanged(const QString &);
4444
public:
4545
typedef QObject Superclass;
4646
typedef ctkFileLogger Self;

Libs/Core/ctkJobScheduler.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ class CTK_CORE_EXPORT ctkJobScheduler : public QObject
117117
QSharedPointer<QThreadPool> threadPoolShared() const;
118118

119119
Q_SIGNALS:
120-
void jobInitialized(QVariant);
121-
void jobQueued(QVariant);
122-
void jobStarted(QList<QVariant>);
123-
void jobUserStopped(QList<QVariant>);
124-
void jobFinished(QList<QVariant>);
125-
void jobAttemptFailed(QList<QVariant>);
126-
void jobFailed(QList<QVariant>);
127-
void progressJobDetail(QList<QVariant>);
120+
void jobInitialized(const QVariant &);
121+
void jobQueued(const QVariant &);
122+
void jobStarted(const QList<QVariant> &);
123+
void jobUserStopped(const QList<QVariant> &);
124+
void jobFinished(const QList<QVariant> &);
125+
void jobAttemptFailed(const QList<QVariant> &);
126+
void jobFailed(const QList<QVariant> &);
127+
void progressJobDetail(const QList<QVariant> &);
128128
void freezeJobsSchedulingChanged(bool);
129129
void maximumThreadCountChanged(int);
130130
void maximumNumberOfRetryChanged(int);

Libs/Core/ctkLogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CTK_CORE_EXPORT ctkLogger : public QObject
3737
Q_OBJECT
3838
Q_PROPERTY(ctkErrorLogLevel::LogLevel level READ logLevel WRITE setLogLevel NOTIFY logLevelChanged);
3939
Q_SIGNALS:
40-
void logLevelChanged(ctkErrorLogLevel::LogLevel newlevel);
40+
void logLevelChanged(const ctkErrorLogLevel::LogLevel & newlevel);
4141
public:
4242
typedef QObject Superclass;
4343

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
1-
/*==============================================================================
2-
3-
Library: CTK
4-
5-
Copyright (c) Pixel Medical Inc. 2021
6-
7-
Licensed under the Apache License, Version 2.0 (the "License");
8-
you may not use this file except in compliance with the License.
9-
You may obtain a copy of the License at
10-
11-
http://www.apache.org/licenses/LICENSE-2.0.txt
12-
13-
Unless required by applicable law or agreed to in writing, software
14-
distributed under the License is distributed on an "AS IS" BASIS,
15-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
See the License for the specific language governing permissions and
17-
limitations under the License.
18-
19-
==============================================================================*/
20-
21-
#ifndef __ctkDICOMDisplayedFieldGeneratorRuleFactory_h_
22-
#define __ctkDICOMDisplayedFieldGeneratorRuleFactory_h_
23-
24-
#include "ctkDICOMCoreExport.h"
25-
26-
// Qt includes
27-
#include <QObject>
28-
#include <QList>
29-
30-
class ctkDICOMDatabase;
31-
class ctkDICOMDisplayedFieldGeneratorAbstractRule;
32-
class ctkDICOMDisplayedFieldGeneratorRuleFactoryCleanup;
33-
34-
/// \ingroup SlicerRt_QtModules_Segmentations
35-
/// \class ctkDICOMDisplayedFieldGeneratorRuleFactory
36-
/// \brief Singleton class managing displayed field generator rules
37-
class CTK_DICOM_CORE_EXPORT ctkDICOMDisplayedFieldGeneratorRuleFactory : public QObject
38-
{
39-
Q_OBJECT
40-
41-
public:
42-
/// Instance getter for the singleton class
43-
/// \return Instance object
44-
Q_INVOKABLE static ctkDICOMDisplayedFieldGeneratorRuleFactory* instance();
45-
46-
public:
47-
/// Register a displayed field generator rule. The factory takes ownership of the object (caller must not delete it).
48-
/// \return True if rule is registered successfully, false otherwise
49-
Q_INVOKABLE bool registerDisplayedFieldGeneratorRule(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule);
50-
51-
/// Return the list of displayed field generator rules registered.
52-
Q_INVOKABLE const QList<ctkDICOMDisplayedFieldGeneratorAbstractRule*>& displayedFieldGeneratorRules()
53-
{ return this->DisplayedFieldGeneratorRules; }
54-
55-
/// Return a list with the copies of displayed field generator rules that are enabled according to the database.
56-
/// \param database DICOM database in which the DisplayedFieldGeneratorRules table is used to decide if a rule is
57-
/// enabled or not. If the table itself or an entry with a particular rule name is missing then the rule is treated as enabled.
58-
Q_INVOKABLE QList<ctkDICOMDisplayedFieldGeneratorAbstractRule*> copyEnabledDisplayedFieldGeneratorRules(ctkDICOMDatabase* database);
59-
60-
signals:
61-
void displayedFieldGeneratorRuleRegistered();
62-
void displayedFieldGeneratorRuleUnregistered();
63-
64-
protected:
65-
QList<ctkDICOMDisplayedFieldGeneratorAbstractRule*> DisplayedFieldGeneratorRules;
66-
67-
private:
68-
/// Allows cleanup of the singleton at application exit
69-
static void cleanup();
70-
71-
private:
72-
ctkDICOMDisplayedFieldGeneratorRuleFactory(QObject* parent=nullptr);
73-
~ctkDICOMDisplayedFieldGeneratorRuleFactory() override;
74-
75-
Q_DISABLE_COPY(ctkDICOMDisplayedFieldGeneratorRuleFactory);
76-
friend class ctkDICOMDisplayedFieldGeneratorRuleFactoryCleanup;
77-
friend class PythonQtWrapper_ctkDICOMDisplayedFieldGeneratorRuleFactory; // Allow Python wrapping without enabling direct instantiation
78-
79-
private:
80-
/// Instance of the singleton
81-
static ctkDICOMDisplayedFieldGeneratorRuleFactory* Instance;
82-
};
83-
84-
#endif // __ctkDICOMDisplayedFieldGeneratorRuleFactory_h_
1+
/*==============================================================================
2+
3+
Library: CTK
4+
5+
Copyright (c) Pixel Medical Inc. 2021
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0.txt
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
==============================================================================*/
20+
21+
#ifndef __ctkDICOMDisplayedFieldGeneratorRuleFactory_h_
22+
#define __ctkDICOMDisplayedFieldGeneratorRuleFactory_h_
23+
24+
#include "ctkDICOMCoreExport.h"
25+
26+
// Qt includes
27+
#include <QObject>
28+
#include <QList>
29+
30+
class ctkDICOMDatabase;
31+
class ctkDICOMDisplayedFieldGeneratorAbstractRule;
32+
class ctkDICOMDisplayedFieldGeneratorRuleFactoryCleanup;
33+
34+
/// \ingroup SlicerRt_QtModules_Segmentations
35+
/// \class ctkDICOMDisplayedFieldGeneratorRuleFactory
36+
/// \brief Singleton class managing displayed field generator rules
37+
class CTK_DICOM_CORE_EXPORT ctkDICOMDisplayedFieldGeneratorRuleFactory : public QObject
38+
{
39+
Q_OBJECT
40+
41+
public:
42+
/// Instance getter for the singleton class
43+
/// \return Instance object
44+
Q_INVOKABLE static ctkDICOMDisplayedFieldGeneratorRuleFactory* instance();
45+
46+
public:
47+
/// Register a displayed field generator rule. The factory takes ownership of the object (caller must not delete it).
48+
/// \return True if rule is registered successfully, false otherwise
49+
Q_INVOKABLE bool registerDisplayedFieldGeneratorRule(ctkDICOMDisplayedFieldGeneratorAbstractRule* rule);
50+
51+
/// Return the list of displayed field generator rules registered.
52+
Q_INVOKABLE const QList<ctkDICOMDisplayedFieldGeneratorAbstractRule*>& displayedFieldGeneratorRules()
53+
{ return this->DisplayedFieldGeneratorRules; }
54+
55+
/// Return a list with the copies of displayed field generator rules that are enabled according to the database.
56+
/// \param database DICOM database in which the DisplayedFieldGeneratorRules table is used to decide if a rule is
57+
/// enabled or not. If the table itself or an entry with a particular rule name is missing then the rule is treated as enabled.
58+
Q_INVOKABLE QList<ctkDICOMDisplayedFieldGeneratorAbstractRule*> copyEnabledDisplayedFieldGeneratorRules(ctkDICOMDatabase* database);
59+
60+
signals:
61+
void displayedFieldGeneratorRuleRegistered();
62+
void displayedFieldGeneratorRuleUnregistered();
63+
64+
protected:
65+
QList<ctkDICOMDisplayedFieldGeneratorAbstractRule*> DisplayedFieldGeneratorRules;
66+
67+
private:
68+
/// Allows cleanup of the singleton at application exit
69+
static void cleanup();
70+
71+
private:
72+
ctkDICOMDisplayedFieldGeneratorRuleFactory(QObject* parent=nullptr);
73+
~ctkDICOMDisplayedFieldGeneratorRuleFactory() override;
74+
75+
Q_DISABLE_COPY(ctkDICOMDisplayedFieldGeneratorRuleFactory);
76+
friend class ctkDICOMDisplayedFieldGeneratorRuleFactoryCleanup;
77+
friend class PythonQtWrapper_ctkDICOMDisplayedFieldGeneratorRuleFactory; // Allow Python wrapping without enabling direct instantiation
78+
79+
private:
80+
/// Instance of the singleton
81+
static ctkDICOMDisplayedFieldGeneratorRuleFactory* Instance;
82+
};
83+
84+
#endif // __ctkDICOMDisplayedFieldGeneratorRuleFactory_h_

Libs/DICOM/Core/ctkDICOMEcho.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMEcho : public QObject
4747
Q_PROPERTY(QString jobUID READ jobUID WRITE setJobUID NOTIFY jobUIDChanged);
4848

4949
Q_SIGNALS:
50-
void connectionNameChanged(QString);
51-
void callingAETitleChanged(QString);
52-
void calledAETitleChanged(QString);
53-
void hostChanged(QString);
50+
void connectionNameChanged(const QString &);
51+
void callingAETitleChanged(const QString &);
52+
void calledAETitleChanged(const QString &);
53+
void hostChanged(const QString &);
5454
void portChanged(int);
5555
void connectionTimeoutChanged(int);
56-
void jobUIDChanged(QString);
56+
void jobUIDChanged(const QString &);
5757
public:
5858
explicit ctkDICOMEcho(QObject* parent = 0);
5959
virtual ~ctkDICOMEcho();

Libs/DICOM/Core/ctkDICOMIndexer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMIndexer : public QObject
123123

124124
Q_SIGNALS:
125125
/// Description of current phase of the indexing (parsing, importing, ...)
126-
void progressStep(QString);
126+
void progressStep(const QString &);
127127
/// Detailed information about the current progress (e.g., name of currently processed file)
128-
void progressDetail(QString);
128+
void progressDetail(const QString &);
129129
/// Progress in percentage
130130
void progress(int);
131131
/// Indexing is completed.
@@ -153,4 +153,4 @@ protected Q_SLOTS:
153153

154154
};
155155

156-
#endif
156+
#endif

0 commit comments

Comments
 (0)