File: adapt-to-qt4-api.pl

package info (click to toggle)
kde-dev-scripts 4%3A18.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,496 kB
  • sloc: perl: 15,466; lisp: 5,627; sh: 4,157; python: 3,892; ruby: 2,158; makefile: 16; sed: 9
file content (285 lines) | stat: -rwxr-xr-x 10,775 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/usr/bin/perl

# Laurent Montel <montel@kde.org> 2005 GPL
# David Faure <faure@kde.org>
# This script ports everything in the current directory (and recursively) to the Qt4 API,
# for things that can be done automatically.
# Note that there are many other scripts for things that require manual tweaking afterwards,
# especially for things that would otherwise compile with QT3_SUPPORT so they don't need
# porting initially.

use File::Basename;
use lib dirname( $0 );
use functionUtilkde;
use strict;

sub addQStringElement
{
    my $result = $_[0];
    if ( $result =~ /^\"/ ) {
	$result = "QString(" . $result . ")";
    }
    return $result;
}

open(my $F, "-|", qw(find . -type f));
my $file;
my $warning;
my @files = ();
while ($file = <$F>) {
    chomp $file;
    next if functionUtilkde::excludeFile( $file);
    my @necessaryIncludes = ();

    my $is_ui_file = 0;
    $is_ui_file = 1 if ( $file =~ /\.ui$/ );

    if (functionUtilkde::substInFile {

    if ( $_ =~ /Q3StyleSheet::escape/ ) {
    	s!Q3StyleSheet::escape!Qt::escape!g;
    	push(@necessaryIncludes, "QTextDocument");
    }
    if ( $_ =~ /Q3StyleSheet::convertFromPlainText/ ) {
        s!Q3StyleSheet::convertFromPlainText!Qt::convertFromPlainText!g;
        s!Q3StyleSheetItem::!Qt::!;
        push(@necessaryIncludes, "QTextDocument");
    }

    s!Qt::WordBreak!Qt::TextWordWrap!;
    s!Qt::SingleLine!Qt::TextSingleLine!;
    s!Qt::DontClip!Qt::TextDontClip!;
    s!Qt::ExpandTabs!Qt::TextExpandTabs!;
    s!Qt::ShowPrefix!Qt::TextShowMnemonic!;
    s!Qt::BreakAnywhere!Qt::TextWrapAnywhere!;
    s!Qt::DontPrint!Qt::TextDontPrint!;
    s!Qt::IncludeTrailingSpaces!Qt::TextIncludeTrailingSpaces!;
    s!Qt::NoAccel!Qt::TextHideMnemonic!;
    s!Qt::Key_BackSpace!Qt::Key_Backspace!;
    s!Qt::Key_BackTab!Qt::Key_Backtab!;
    s!Qt::Key_Prior!Qt::Key_PageUp!;
    s!Qt::Key_Next!Qt::Key_PageDown!;
    s!Qt::Key_MediaPrev([\s*|,])!Qt::Key_MediaPrevious\1!;

    s!Qt::arrowCursor!Qt::ArrowCursor!;
    s!Qt::upArrowCursor!Qt::UpArrowCursor!;
    s!Qt::crossCursor!Qt::CrossCursor!;
    s!Qt::waitCursor!Qt::WaitCursor!;
    s!Qt::ibeamCursor!Qt::IBeamCursor!;
    s!Qt::sizeVerCursor!Qt::SizeVerCursor!;
    s!Qt::sizeHorCursor!Qt::SizeHorCursor!;
    s!Qt::sizeBDiagCursor!Qt::SizeBDiagCursor!;
    s!Qt::sizeFDiagCursor!Qt::SizeFDiagCursor!;
    s!Qt::sizeAllCursor!Qt::SizeAllCursor!;
    s!Qt::blankCursor!Qt::BlankCursor!;
    s!Qt::splitVCursor!Qt::SplitVCursor!;
    s!Qt::splitHCursor!Qt::SplitHCursor!;
    s!Qt::pointingHandCursor!Qt::PointingHandCursor!;
    s!Qt::forbiddenCursor!Qt::ForbiddenCursor!;
    s!Qt::whatsThisCursor!Qt::WhatsThisCursor!;
    s!QScrollBar::Horizontal!Qt::Horizontal!g;
    s!QSlider::Horizontal!Qt::Horizontal!g; 
    s!QScrollBar::Vertical!Qt::Vertical!g;
    s!QSlider::Vertical!Qt::Vertical!g;
    s!QWidget::WheelFocus!Qt::WheelFocus!g;

    s!\bQPen::PenStyle\b!Qt::PenStyle!g;
    s!QSlider::Below!QSlider::TicksBelow!;
    s!QSlider::Above!QSlider::TicksAbove!;

    # Qt3 name class
    #s!QIconSet!QIcon!g;
    s!QWMatrix!QMatrix!g;
    s!QGuardedPtr!QPointer!g;

    # Qt2-compat classes :)
    s!QArray!Q3MemArray!g;

    s!IO_ReadOnly!QIODevice::ReadOnly!;
    s!IO_WriteOnly!QIODevice::WriteOnly!;
    s!IO_ReadWrite!QIODevice::ReadWrite!;
    s!IO_Append!QIODevice::Append!;
    s!IO_Truncate!QIODevice::Truncate!;
    s!IO_Translate!QIODevice::Text!;

    s!Q_INT8!qint8!g;
    s!Q_UINT8!quint8!g;
    s!Q_INT16!qint16!g;
    s!Q_UINT16!quint16!g;
    s!Q_INT32!qint32!g;
    s!Q_UINT32!quint32!g;
    s!Q_INT64!qint64!g;
    s!Q_UINT64!quint64!g;
    s!Q_LLONG!qint64!g;
    s!Q_ULLONG!quint64!g;
    s!\bQMAX\b!qMax!g;
    s!\bQMIN\b!qMin!g;
    s!\bQABS\b!qAbs!g;

    s!QWidget::PaletteBase!Qt::PaletteBase!;
    s!Qt::ShiftButton!Qt::ShiftModifier!;
    s!ShiftButton!Qt::ShiftModifier!;
    s!Qt::ControlButton!Qt::ControlModifier!;
    s!ControlButton!Qt::ControlModifier!;
    s!Qt::AltButton!Qt::AltModifier!;
    s!AltButton!Qt::AltModifier!;
    s!Qt::MetaButton!Qt::MetaModifier!;
    s!MetaButton!Qt::MetaModifier!;
    s!Qt::Keypad!Qt::KeypadModifier!;
    s!\bKeypad\b!Qt::KeypadModifier!;
    s!Qt::KeyButtonMask!Qt::KeyboardModifierMask!;
    s!KeyButtonMask!Qt::KeyboardModifierMask!;

    s!QMouseEvent::LeftButton!Qt::LeftButton!;
    s!QMouseEvent::RightButton!Qt::RightButton!;
    s!QMouseEvent::MidButton!Qt::MidButton!;

    s!QWidget::NoFocus!Qt::NoFocus!g;

    s!convertToAbs!makeAbsolute!;
    s!currentDirPath!currentPath!;
    s!homeDirPath!homePath!;
    s!rootDirPath!rootPath!;
    s!cleanDirPath!cleanPath!;
    s!absFilePath!absoluteFilePath!;
    s!QDir::SortSpec!QDir::SortFlags!;
    s!QDir::All!QDir::TypeMask!;
    s!QDir::DefaultFilter!QDir::NoFilter!;
    s!QDir::DefaultSort!QDir::NoSort!;
    s!simplifyWhiteSpace!simplified!g;
    s!stripWhiteSpace!trimmed!g;

    if ( $_ =~ /(\.ucs2|\-\>ucs2)/ ) {
      s!\bucs2\b!utf16!g;
    }
    s!leftJustify!leftJustified!g;
    s!rightJustify!rightJustified!g;
    s!fromUcs2!fromUtf16!g;
    s!constref!at!g;
    #s!changeInterval!start!g;

    s!Q3TextEdit::PlainText!Qt::PlainText!;
    s!\bQImage::ScaleMin\b!Qt::ScaleMin!;

    # When using qt3to4 with -strict (to avoid some nonsensical replacements of col.red() or enum { Top, Bottom })
    # we are then missing the following safer replacements:
    s!QWidget::WFlags!Qt::WFlags!;
    s!\bWFlags\b!Qt::WFlags! unless (/Qt::WFlags/);
    s!\bWStyle_!Qt::WStyle_!g unless (/Qt::WStyle_/);
    s!\bWType_!Qt::WType_!g unless (/Qt::WType_/);
    s!\bKey_!Qt::Key_!g unless (/Qt::Key_/);
    s!\bCTRL\b!Qt::CTRL!g unless (/Qt::CTRL/ || /_CTRL/ );
    s!\bSHIFT\b!Qt::SHIFT!g unless (/Qt::SHIFT/);
    s!\bLeftButton\b!Qt::LeftButton!g unless (/Qt::LeftButton/);
    s!\bRightButton\b!Qt::RightButton!g unless (/Qt::RightButton/);
    s!\bMidButton\b!Qt::MidButton!g unless (/Qt::MidButton/);
    s!QWidget::TabFocus!Qt::TabFocus!;
    s!\bTabFocus\b!Qt::TabFocus!g unless (/Qt::TabFocus/);
   

    s!QStyle::Style_Enabled!QStyle::State_Enabled!g;
    s!QStyle::Style_On!QStyle::State_On!g;
    s!QStyle::Style_Off!QStyle::State_Off!g; 
    s!QStyle::Style_NoChange!QStyle::State_NoChange!g;

    s!QWidget::StrongFocus!Qt::StrongFocus!g;
    s!QPushButton::StrongFocus!Qt::StrongFocus!g;
    s!StrongFocus!Qt::StrongFocus!g unless (/Qt::StrongFocus/ );

    s!QLabel::AlignLeft!Qt::AlignLeft!g;
    s!QLabel::AlignRight!Qt::AlignRight!g;
    s!QLabel::AlignCenter!Qt::AlignCenter!g;
    s!QLabel::AlignHCenter!Qt::AlignHCenter!g;
    s!QLabel::AlignVCenter!Qt::AlignVCenter!g;
    s!QLabel::AlignTop!Qt::AlignTop!g;
    s!QLabel::AlignBottom!Qt::AlignBottom!g;
    s!\bAlignmentFlags\b!Qt::Alignment!g unless (/Qt::Alignment/);

    if (!$is_ui_file) { # uic/cpp/cppwriteinitialization.cpp prepends Qt:: automatically
        s!\bSolidPattern\b!Qt::SolidPattern!g unless ( /Qt::SolidPattern/ );
        s!Dense1Pattern!Qt::Dense1Pattern!g unless ( /Qt::Dense1Pattern/ );
        s!Dense2Pattern!Qt::Dense2Pattern!g unless ( /Qt::Dense2Pattern/ );
        s!Dense3Pattern!Qt::Dense3Pattern!g unless ( /Qt::Dense3Pattern/ );
        s!Dense4Pattern!Qt::Dense4Pattern!g unless ( /Qt::Dense4Pattern/ );
        s!Dense5Pattern!Qt::Dense5Pattern!g unless ( /Qt::Dense5Pattern/ );
        s!Dense6Pattern!Qt::Dense6Pattern!g unless ( /Qt::Dense6Pattern/ );
        s!Dense7Pattern!Qt::Dense7Pattern!g unless ( /Qt::Dense7Pattern/ );
        s!\bHorPattern\b!Qt::HorPattern!g unless ( /Qt::HorPattern/ );
        s!\bVerPattern\b!Qt::VerPattern!g unless ( /Qt::VerPattern/ );
        s!\bCrossPattern\b!Qt::CrossPattern!g unless ( /Qt::CrossPattern/ );
        s!\bBDiagPattern\b!Qt::BDiagPattern!g unless ( /Qt::BDiagPattern/ );
        s!\bFDiagPattern\b!Qt::FDiagPattern!g unless ( /Qt::FDiagPattern/ );
        s!\bDiagCrossPattern\b!Qt::DiagCrossPattern!g unless ( /Qt::DiagCrossPattern/ );
        s!\bNoBrush\b!Qt::NoBrush!g unless (/Qt::NoBrush/);
    }

    s!\bSolidLine\b!Qt::SolidLine!g unless ( /Qt::SolidLine/ );

    s!QBrush::NoBrush!Qt::NoBrush!g;
    s!QButton::NoChange!QCheckBox::NoChange!g;

    s!QObject::AlignLeft!Qt::AlignLeft!g;
    s!QObject::AlignRight!Qt::AlignRight!g;
    s!QObject::AlignCenter!Qt::AlignCenter!g;
    s!QObject::AlignHCenter!Qt::AlignHCenter!g;
    s!QObject::AlignVCenter!Qt::AlignVCenter!g;
    s!QObject::AlignTop!Qt::AlignTop!g;
    s!QObject::AlignBottom!Qt::AlignBottom!g;

    s!Q3ListViewItem::AlignLeft!Qt::AlignLeft!g;
    s!Q3ListViewItem::AlignRight!Qt::AlignRight!g;
    s!Q3ListViewItem::AlignCenter!Qt::AlignCenter!g;
    s!Q3ListViewItem::AlignHCenter!Qt::AlignHCenter!g;
    s!Q3ListViewItem::AlignVCenter!Qt::AlignVCenter!g;
    s!Q3ListViewItem::AlignTop!Qt::AlignTop!g;
    s!Q3ListViewItem::AlignBottom!Qt::AlignBottom!g;


    s!AlignLeft!Qt::AlignLeft!g unless (/Qt::AlignLeft/ || /"Align/ || /AlignLeft\(.*\)/);
    s!AlignRight!Qt::AlignRight!g unless (/Qt::AlignRight/ || /"Align/ || /AlignRight\(.*\)/);
    s!AlignCenter!Qt::AlignCenter!g unless (/Qt::AlignCenter/ || /"Align/ || /AlignCenter\(.*\)/);
    s!AlignHCenter!Qt::AlignHCenter!g unless (/Qt::AlignHCenter/ || /"Align/ || /AlignHCenter\(.*\)/);
    s!AlignVCenter!Qt::AlignVCenter!g unless (/Qt::AlignVCenter/ || /"Align/ || /AlignVCenter\(.*\)/);
    s!AlignTop!Qt::AlignTop!g unless (/Qt::AlignTop/ || /"Align/ || /AlignTop\(.*\)/);
    s!AlignBottom!Qt::AlignBottom!g unless (/Qt::AlignBottom/ || /"Align/ || /AlignBottom\(.*\)/);
    
    s!QCursor::WaitCursor!Qt::waitCursor!g;
    s!QSplitter::Vertical!Qt::Vertical!g;
    s!QSplitter::Horizontal!Qt::Horizontal!g;

    s!\bQSqlError::Connection\b!QSqlError::ConnectionError!g;
    s!QSqlError::None!QSqlError::NoError!g;
    s!\bQSqlError::Statement\b!QSqlError::StatementError!g;
    s!\bQSqlError::Transaction\b!QSqlError::TransactionError!g;
    s!\bQSqlError::Unknown\b!QSqlError::UnknownError!g;


    if (/app/i) {
	s!flushX!flush!; # QApplication
    }
    s!qt_xdisplay\s*\(\s*\)!QX11Info::display()!;
    s!qt_xrootwin\s*\(\s*\)!QX11Info::appRootWindow()!;
    s!qt_x_time!QX11Info::appTime()!;
    if (/QX11Info/) {
        push(@necessaryIncludes, "QX11Info");
    }
    if (/qHeapSort/) {
	push(@necessaryIncludes, "q3tl.h");
    }

    s!class QWidgetList;!typedef QList<QWidget *> QWidgetList;!;

    # this changes usage of QObjectList, since queryList returns QObjectList and not a pointer in qt4.
    s!QObjectList\s*\*!QObjectList ! if (/queryList/);

    } $file) { push(@files,$file); }

    my %alreadyadded = {};
    foreach my $inc (@necessaryIncludes) {
        next if (defined $alreadyadded{$inc});
        $alreadyadded{$inc} = 1;
        functionUtilkde::addIncludeInFile( $file, $inc );
    }
}
functionUtilkde::diffFile( @files );
warn "Warning: $warning\n" if ($warning != "");