#!/usr/bin/env python3 """ Fix QtGui includes for geometry classes - they belong to QtCore in Qt6 """ import os import re import sys # Geometry classes that belong to QtCore, NOT QtGui GEOMETRY_CLASSES = [ 'QPointF', 'QPoint', 'QRect', 'QRectF', 'QSize', 'QSizeF', 'QLine', 'QLineF', 'QPolygon', 'QPolygonF', 'QRegion', 'QTransform', 'QMatrix', 'QPainterPath', 'QPainterPathStroker' ] def fix_qtgui_geometry_includes(filepath): """Replace QtGui/geometry with QtCore/geometry""" with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() original = content fixes = [] for cls in GEOMETRY_CLASSES: pattern = r'#include\s*' replacement = f'#include ' if re.search(pattern, content): content = re.sub(pattern, replacement, content) fixes.append(cls) if fixes: with open(filepath, 'w', encoding='utf-8') as f: f.write(content) return fixes return [] def main(): base_dir = '/home/torsten/swy/sandbox/qt-migration-legatus/qt6-after/qt6-migrated-legatus' total_files = 0 total_fixes = 0 all_fixes = {} for root, dirs, files in os.walk(base_dir): # Skip build directories if 'build' in root or '.git' in root: continue for file in files: if file.endswith(('.h', '.cpp', '.hpp', '.cc', '.cxx')): filepath = os.path.join(root, file) fixes = fix_qtgui_geometry_includes(filepath) if fixes: total_files += 1 total_fixes += len(fixes) all_fixes[filepath] = fixes print(f"Fixed {len(fixes)}: {filepath}") for fix in fixes: print(f" - QtGui/{fix} → QtCore/{fix}") print(f"\n{'='*80}") print(f"Total files fixed: {total_files}") print(f"Total fixes: {total_fixes}") print(f"{'='*80}") if __name__ == '__main__': main()