[Kde-bindings] [Bug 149341] New: [Qyoto][PATCH] a dirty hack to enable "using QScintilla; " directive if a ui file use QScintilla Widget

cjacker jzhuang at redflag-linux.com
Wed Aug 29 15:29:52 UTC 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=149341         
           Summary: [Qyoto][PATCH] a dirty hack to enable "using
                    QScintilla;" directive if a ui file use QScintilla
                    Widget
           Product: bindings
           Version: unspecified
          Platform: Compiled Sources
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: general
        AssignedTo: kde-bindings kde org
        ReportedBy: jzhuang redflag-linux com


Version:            (using KDE Devel)
Installed from:    Compiled sources

QScintilla for Qt4 provide a customwidget for Qt4 designer, I can use it to add a special QScintilla Widget in a Form, then get a ui file include QScintilla Widget.

if I use uics to generate the csharp code, it did not add "using QScintilla;" driective automatically. so I had to modify the result by hand.

It is not a good idea to modify a intermediate file.

So I hacked the uics and add a dirty hack here.

dirty but works(uics's codes are also not so clean:-D)

diff -Nur qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/cs/cswriteincludes.cpp qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/cs/cswriteincludes.cpp
--- qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/cs/cswriteincludes.cpp	2007-06-26 23:24:24.000000000 +0800
+++ qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/cs/cswriteincludes.cpp	2007-08-29 22:52:46.000000000 +0800
 @ -55,7 +55,10  @
         ++it;
     }
 }
-
+void WriteIncludes::addScintilla()
+{
+    output << "using QScintilla;\n\n";
+}
 void WriteIncludes::acceptUI(DomUI *node)
 {
 /*    m_includes.clear();
diff -Nur qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/cs/cswriteincludes.h qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/cs/cswriteincludes.h
--- qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/cs/cswriteincludes.h	2007-06-26 23:24:24.000000000 +0800
+++ qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/cs/cswriteincludes.h	2007-08-29 22:52:46.000000000 +0800
 @ -39,6 +39,7  @
     WriteIncludes(Uic *uic);
 
     void acceptUI(DomUI *node);
+    void addScintilla();
     void acceptWidget(DomWidget *node);
     void acceptLayout(DomLayout *node);
     void acceptSpacer(DomSpacer *node);
diff -Nur qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/uic.cpp qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/uic.cpp
--- qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/uic.cpp	2007-06-26 23:24:25.000000000 +0800
+++ qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/uic.cpp	2007-08-29 22:52:33.000000000 +0800
 @ -60,6 +60,50  @
 {
 }
 
+bool Uic::useScintilla()
+{
+    QString fileName = opt.inputFile;
+
+    QFile f;
+    if (fileName.isEmpty())
+        f.open(stdin, QIODevice::ReadOnly);
+    else {
+        f.setFileName(fileName);
+        if (!f.open(QIODevice::ReadOnly))
+            return false;
+    }
+
+    QDomDocument doc;                        // ### generalize. share more code with the other tools!
+    if (!doc.setContent(&f))
+        return false;
+
+    QDomElement root = doc.firstChild().toElement();
+    DomUI *ui = new DomUI();
+    ui->read(root);
+
+    double version = ui->attributeVersion().toDouble();
+    if (version < 4.0) {
+        delete ui;
+
+        fprintf(stderr, "uic: File generated with too old version of Qt Designer\n");
+        return false;
+    }
+
+    if (DomCustomWidgets *customWidgets = ui->elementCustomWidgets()) {
+        foreach (DomCustomWidget *customWidget, customWidgets->elementCustomWidget()) {
+            if (DomHeader *header = customWidget->elementHeader()) {
+                QString file = header->text();
+                if (file.isEmpty())
+                    continue;
+	            if(file.contains("scintilla"))
+                	return true;
+            }
+        }
+    }
+    delete ui;
+    return false;
+}
+
 bool Uic::printDependencies()
 {
     QString fileName = opt.inputFile;
 @ -201,6 +245,8  @
     info.acceptUI(ui);
     cWidgetsInfo.acceptUI(ui);
     WriteIncludes(this).acceptUI(ui);
+	if(useScintilla())
+		WriteIncludes(this).addScintilla();
 
     Validator(this).acceptUI(ui);
 
diff -Nur qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/uic.h qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/uic.h
--- qt4-qyoto-1.0.0/csharp/qyoto/tools/uics/uic.h	2007-06-26 23:24:24.000000000 +0800
+++ qt4-qyoto-1.0.0new/csharp/qyoto/tools/uics/uic.h	2007-08-29 22:52:33.000000000 +0800
 @ -49,6 +49,7  @
     ~Uic();
 
     bool printDependencies();
+    bool useScintilla();
 
     inline Driver *driver() const
     { return drv; }



More information about the Kde-bindings mailing list