Warning, file /sdk/kde-dev-scripts/kf5/convert-kvbox.pl was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #!/usr/bin/perl -w 0002 0003 # Laurent Montel <montel@kde.org> (2014) 0004 # K[V|H]Box -> QWidget + QH|VBoxLayout 0005 # find -iname "*.cpp" -o -iname "*.h"|xargs kde-dev-scripts/kf5/convert-kvbox.pl 0006 0007 use strict; 0008 use File::Basename; 0009 use lib dirname($0); 0010 use functionUtilkde; 0011 0012 foreach my $file (@ARGV) { 0013 0014 # Key = variable name of the parent QWidget 0015 # Value = variable name of the associated layout 0016 my %varname = (); 0017 0018 my $modified; 0019 my $needQHBoxLayout; 0020 my $needQVBoxLayout; 0021 open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n"; 0022 my @l = map { 0023 my $orig = $_; 0024 my $regexp = qr/ 0025 ^(\s*) # (1) Indentation 0026 (.*?) # (2) Possibly "Classname *" (the ? means non-greedy) 0027 (\w+) # (3) variable name 0028 \s*=\s* # assignment 0029 new\s+ # new 0030 (K[HV]Box)\s* # (4) KHBox or KVBox 0031 /x; # /x Enables extended whitespace mode 0032 if (my ($indent, $left, $var, $classname) = $_ =~ $regexp) { 0033 s/K[HV]Box/QWidget/g; 0034 my $mylayoutname = $classname eq "KHBox" ? "${var}HBoxLayout" : "${var}VBoxLayout"; 0035 $mylayoutname =~ s/^m?_//; # coding style: this is a local var 0036 my $mylayoutclass = $classname eq "KHBox" ? "QHBoxLayout" : "QVBoxLayout"; 0037 if ( defined $varname{$var}) { 0038 $_ .= $indent . "${mylayoutname} = new $mylayoutclass($var);" . "\n"; 0039 } else { 0040 $_ .= $indent . $mylayoutclass . " *${mylayoutname} = new $mylayoutclass($var);" . "\n"; 0041 } 0042 $_ .= $indent . "${mylayoutname}->setMargin(0);\n"; 0043 $varname{$var} = ${mylayoutname}; 0044 if ($mylayoutclass eq "QHBoxLayout") { 0045 $needQHBoxLayout = 1; 0046 } else { 0047 $needQVBoxLayout = 1; 0048 } 0049 } 0050 my $widget_regexp = qr/ 0051 ^(\s*) # (1) Indentation 0052 (.*?) # (2) Possibly "Classname *" (the ? means non-greedy) 0053 (\w+) # (3) variable name 0054 \s*=\s* # assignment 0055 new\s+ # new 0056 (\w+)\s* # (4) classname 0057 ${functionUtilkde::paren_begin}5${functionUtilkde::paren_end} # (5) (args) 0058 /x; # /x Enables extended whitespace mode 0059 if (my ($indent, $left, $var, $classname, $args) = $_ =~ $widget_regexp) { 0060 # Extract last argument 0061 #print STDERR "left=$left var=$var classname=$classname args=$args\n"; 0062 my $extract_parent_regexp = qr/ 0063 ^\( 0064 (?:.*?) # args before the parent (not captured, not greedy) 0065 \s*(\w+)\s* # (1) parent 0066 (?:,\s*\"[^\"]*\"\s*)? # optional: object name 0067 \)$ 0068 /x; # /x Enables extended whitespace mode 0069 if (my ($lastArg) = $args =~ $extract_parent_regexp) { 0070 print STDERR "extracted parent=" . $lastArg . "\n"; 0071 my $mylayoutname = $varname{$lastArg}; 0072 if (defined $mylayoutname) { 0073 $_ .= $indent . $mylayoutname . "->addWidget(" . $var . ");" . "\n"; 0074 } 0075 } else { 0076 #warn $functionUtilkde::current_file . ":" . $functionUtilkde::current_line . ": couldn't extract last argument from " . $args . "\n"; 0077 } 0078 } 0079 0080 if (/(\w+)->setSpacing\s*\(.*/) { 0081 my $var = $1; 0082 my $mylayoutname = $varname{$var}; 0083 if ( defined $mylayoutname ) { 0084 s/$var->setSpacing/$mylayoutname->setSpacing/; 0085 } 0086 } 0087 if (/(\w+)->setMargin\s*\(.*/) { 0088 my $var = $1; 0089 my $mylayoutname = $varname{$var}; 0090 if ( defined $mylayoutname ) { 0091 s/$var->setMargin/$mylayoutname->setMargin/; 0092 } 0093 } 0094 if (/(\w+)->setStretchFactor\s*\(.*/) { 0095 my $var = $1; 0096 my $mylayoutname = $varname{$var}; 0097 if ( defined $mylayoutname ) { 0098 s/$var->setStretchFactor/$mylayoutname->setStretchFactor/; 0099 } 0100 } 0101 0102 0103 0104 s/#include <khbox\.h>/#include <QHBoxLayout>/; 0105 s/#include <kvbox\.h>/#include <QVBoxLayout>/; 0106 s/#include <KHBox>/#include <QHBoxLayout>/; 0107 s/#include <KVBox>/#include <QVBoxLayout>/; 0108 s/class KVBox;//; 0109 s/class KHBox;//; 0110 s/KVBox\s*\*/QWidget */; 0111 s/KHBox\s*\*/QWidget */; 0112 0113 0114 0115 0116 $modified ||= $orig ne $_; 0117 $_; 0118 } <$FILE>; 0119 0120 if ($modified) { 0121 open (my $OUT, ">", $file); 0122 print $OUT @l; 0123 close ($OUT); 0124 if ( $needQVBoxLayout) { 0125 functionUtilkde::addIncludeInFile($file, "QVBoxLayout"); 0126 } 0127 if ( $needQHBoxLayout) { 0128 functionUtilkde::addIncludeInFile($file, "QHBoxLayout"); 0129 } 0130 } 0131 } 0132 0133 functionUtilkde::diffFile( "@ARGV" );