Warning, file /sdk/kde-dev-scripts/kf5/convert-kpushbutton.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 # KPushButton => QPushButton 0005 # find -iname "*.cpp" -o -iname "*.h" -o -iname "*.ui" |xargs kde-dev-scripts/kf5/convert-kpushbutton.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 my $modified; 0015 my $needGuiItem; 0016 open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n"; 0017 my @l = map { 0018 my $orig = $_; 0019 my $regexp = qr/ 0020 ^(\s*) # (1) Indentation, possibly "Classname *" (the ? means non-greedy) 0021 (.*?) # (2) Possibly "Classname *" (the ? means non-greedy) 0022 (\w+) # (3) variable name 0023 \s*=\s* # assignment 0024 new\s+KPushButton\s*\((.*)\) # (4) new KPushButton(...,...,...,...); 0025 (.*)$ # (5) afterreg 0026 /x; # /x Enables extended whitespace mode 0027 if (my ($indent, $left, $var, $argument, $afterreg) = $_ =~ $regexp) { 0028 #KPushButton( const KGuiItem &item, QWidget *parent = 0 ); 0029 my ($kguiitem, $parent, $after); 0030 my $constructor_regexp = qr/ 0031 ^(\s*KStandardGuiItem[^,]*)\s* # kguitem 0032 (?:,\s([^,]*))? # parent 0033 (.*)$ # after 0034 /x; 0035 if ( ($kguiitem, $parent, $after) = $argument =~ $constructor_regexp ) { 0036 warn "found a kpushbutton with kguiitem $kguiitem \n"; 0037 if ($parent) { 0038 $_ = $indent . $left . $var . " = new QPushButton($parent);" . $after . "\n"; 0039 } else { 0040 $_ = $indent . $left . $var . " = new QPushButton;" . $after . "\n"; 0041 } 0042 $needGuiItem = 1; 0043 $_ .= $indent . "KGuiItem::assign($var,$kguiitem);" . $after . "\n"; 0044 } 0045 } 0046 0047 # support for ui.addButton->setGuiItem( KStandardGuiItem::add() ); 0048 my $setGuiItemRegex = qr/ 0049 ^(\s*) # (1) Indentation, possibly "Classname *" (the ? means non-greedy) 0050 (.*?)\-\>setGuiItem\( # (2) variable name 0051 \s*(KStandardGuiItem::.*) # (3) kstandardguiitem 0052 (.*)$ # (5) afterreg 0053 /x; # /x Enables extended whitespace mode 0054 if (my ($indent, $var, $kstandardguiitem, $after) = $_ =~ $setGuiItemRegex) { 0055 warn "found setGuiItem \"$kstandardguiitem\" \"$var\"\n"; 0056 $_ = $indent . "KGuiItem::assign($var, $kstandardguiitem" . $after . "\n"; 0057 $needGuiItem = 1; 0058 } 0059 s/\bKPushButton\b/QPushButton/g; 0060 s/\<KPushButton\b\>/\<QPushButton>/ =~ /#include/ ; 0061 s/\<kpushbutton.h\>/\<QPushButton>/ =~ /#include/ ; 0062 0063 $modified ||= $orig ne $_; 0064 $_; 0065 } <$FILE>; 0066 0067 if ($modified) { 0068 open (my $OUT, ">", $file); 0069 print $OUT @l; 0070 close ($OUT); 0071 if ($needGuiItem) { 0072 functionUtilkde::addIncludeInFile($file, "KGuiItem"); 0073 functionUtilkde::addIncludeInFile($file, "KStandardGuiItem"); 0074 } 0075 } 0076 } 0077 0078 functionUtilkde::diffFile( "@ARGV" );