uic: support promoted widgets assuming default ctor naming scheme

This commit is contained in:
mappu 2024-10-03 17:22:49 +13:00
parent 2c05d876f9
commit 12b4e083ee
2 changed files with 81 additions and 84 deletions

View File

@ -1,165 +1,168 @@
package main
func constructorFunctionFor(className string) (string, bool) {
func constructorFunctionFor(className string) string {
// Rebuild this list via:
// grep -PRoh 'func New.+\(parent \*QWidget\)' ~/dev/miqt/qt/ | sed -re 's~^func New([^0-9]+)([0-9]*)\(.*~case "\1": return "New\1\2", true~'
// grep -PRoh 'func New.+\(parent \*QWidget\)' ~/dev/miqt/qt/ | sed -re 's~^func New([^0-9]+)([0-9]*)\(.*~case "\1": return "New\1\2"~'
switch className {
// CODEGENERATED LIST START
case "QListWidget":
return "NewQListWidget2", true
return "NewQListWidget2"
case "QAbstractSpinBox":
return "NewQAbstractSpinBox2", true
return "NewQAbstractSpinBox2"
case "QStackedLayout":
return "NewQStackedLayout2", true
return "NewQStackedLayout2"
case "QColumnView":
return "NewQColumnView2", true
return "NewQColumnView2"
case "QProgressDialog":
return "NewQProgressDialog3", true
return "NewQProgressDialog3"
case "QTabWidget":
return "NewQTabWidget2", true
return "NewQTabWidget2"
case "QLabel":
return "NewQLabel3", true
return "NewQLabel3"
case "QKeySequenceEdit":
return "NewQKeySequenceEdit3", true
return "NewQKeySequenceEdit3"
case "QDockWidget":
return "NewQDockWidget5", true
return "NewQDockWidget5"
case "QFontComboBox":
return "NewQFontComboBox2", true
return "NewQFontComboBox2"
case "QTreeView":
return "NewQTreeView2", true
return "NewQTreeView2"
case "QCalendarWidget":
return "NewQCalendarWidget2", true
return "NewQCalendarWidget2"
case "QLineEdit":
return "NewQLineEdit3", true
return "NewQLineEdit3"
case "QMenuBar":
return "NewQMenuBar2", true
return "NewQMenuBar2"
case "QFrame":
return "NewQFrame2", true
return "NewQFrame2"
case "QAbstractScrollArea":
return "NewQAbstractScrollArea2", true
return "NewQAbstractScrollArea2"
case "QSplitter":
return "NewQSplitter3", true
return "NewQSplitter3"
case "QStackedWidget":
return "NewQStackedWidget2", true
return "NewQStackedWidget2"
case "QWizard":
return "NewQWizard2", true
return "NewQWizard2"
case "QWizardPage":
return "NewQWizardPage2", true
return "NewQWizardPage2"
case "QMdiSubWindow":
return "NewQMdiSubWindow2", true
return "NewQMdiSubWindow2"
case "QStatusBar":
return "NewQStatusBar2", true
return "NewQStatusBar2"
case "QToolButton":
return "NewQToolButton2", true
return "NewQToolButton2"
case "QShortcut":
return "NewQShortcut", true
return "NewQShortcut"
case "QSlider":
return "NewQSlider3", true
return "NewQSlider3"
case "QComboBox":
return "NewQComboBox2", true
return "NewQComboBox2"
case "QScrollBar":
return "NewQScrollBar3", true
return "NewQScrollBar3"
case "QTabBar":
return "NewQTabBar2", true
return "NewQTabBar2"
case "QTextBrowser":
return "NewQTextBrowser2", true
return "NewQTextBrowser2"
case "QTreeWidget":
return "NewQTreeWidget2", true
return "NewQTreeWidget2"
case "QDialog":
return "NewQDialog2", true
return "NewQDialog2"
case "QFormLayout":
return "NewQFormLayout2", true
return "NewQFormLayout2"
case "QToolBar":
return "NewQToolBar4", true
return "NewQToolBar4"
case "QWidget":
return "NewQWidget2", true
return "NewQWidget2"
case "QRadioButton":
return "NewQRadioButton3", true
return "NewQRadioButton3"
case "QCheckBox":
return "NewQCheckBox3", true
return "NewQCheckBox3"
case "QSizeGrip":
return "NewQSizeGrip", true
return "NewQSizeGrip"
case "QLCDNumber":
return "NewQLCDNumber3", true
return "NewQLCDNumber3"
case "QFileDialog":
return "NewQFileDialog3", true
return "NewQFileDialog3"
case "QUndoView":
return "NewQUndoView4", true
return "NewQUndoView4"
case "QGraphicsView":
return "NewQGraphicsView3", true
return "NewQGraphicsView3"
case "QPushButton":
return "NewQPushButton4", true
return "NewQPushButton4"
case "QColorDialog":
return "NewQColorDialog3", true
return "NewQColorDialog3"
case "QMessageBox":
return "NewQMessageBox4", true
return "NewQMessageBox4"
case "QSplashScreen":
return "NewQSplashScreen3", true
return "NewQSplashScreen3"
case "QErrorMessage":
return "NewQErrorMessage2", true
return "NewQErrorMessage2"
case "QListView":
return "NewQListView2", true
return "NewQListView2"
case "QDateTimeEdit":
return "NewQDateTimeEdit5", true
return "NewQDateTimeEdit5"
case "QTimeEdit":
return "NewQTimeEdit3", true
return "NewQTimeEdit3"
case "QDateEdit":
return "NewQDateEdit3", true
return "NewQDateEdit3"
case "QMenu":
return "NewQMenu3", true
return "NewQMenu3"
case "QToolBox":
return "NewQToolBox2", true
return "NewQToolBox2"
case "QTableWidget":
return "NewQTableWidget3", true
return "NewQTableWidget3"
case "QFocusFrame":
return "NewQFocusFrame2", true
return "NewQFocusFrame2"
case "QHBoxLayout":
return "NewQHBoxLayout2", true
return "NewQHBoxLayout2"
case "QVBoxLayout":
return "NewQVBoxLayout2", true
return "NewQVBoxLayout2"
case "QInputDialog":
return "NewQInputDialog2", true
return "NewQInputDialog2"
case "QTableView":
return "NewQTableView2", true
return "NewQTableView2"
case "QMdiArea":
return "NewQMdiArea2", true
return "NewQMdiArea2"
case "QSpinBox":
return "NewQSpinBox2", true
return "NewQSpinBox2"
case "QDoubleSpinBox":
return "NewQDoubleSpinBox2", true
return "NewQDoubleSpinBox2"
case "QProgressBar":
return "NewQProgressBar2", true
return "NewQProgressBar2"
case "QTextEdit":
return "NewQTextEdit3", true
return "NewQTextEdit3"
case "QAbstractSlider":
return "NewQAbstractSlider2", true
return "NewQAbstractSlider2"
case "QDialogButtonBox":
return "NewQDialogButtonBox5", true
return "NewQDialogButtonBox5"
case "QFontDialog":
return "NewQFontDialog3", true
return "NewQFontDialog3"
case "QMainWindow":
return "NewQMainWindow2", true
return "NewQMainWindow2"
case "QCommandLinkButton":
return "NewQCommandLinkButton4", true
return "NewQCommandLinkButton4"
case "QDial":
return "NewQDial2", true
return "NewQDial2"
case "QGridLayout":
return "NewQGridLayout", true
return "NewQGridLayout"
case "QPlainTextEdit":
return "NewQPlainTextEdit3", true
return "NewQPlainTextEdit3"
case "QScrollArea":
return "NewQScrollArea2", true
return "NewQScrollArea2"
case "QGroupBox":
return "NewQGroupBox3", true
return "NewQGroupBox3"
// CODEGENERATED LIST END
default:
return "", false
// This class is not known to miqt-uic
// Assume it's a user promoted type from Qt Designer with a matching ctor
// of the form New{Class}(parent *QWidget)
return "New" + className
}

View File

@ -61,10 +61,7 @@ func normalizeEnumName(s string) string {
func generateWidget(w UiWidget, parentName string, parentClass string) (string, error) {
ret := strings.Builder{}
ctor, ok := constructorFunctionFor(w.Class)
if !ok {
return "", fmt.Errorf("No known widget constructor function for %q class %q", w.Name, w.Class)
}
ctor := constructorFunctionFor(w.Class)
ret.WriteString(`
ui.` + w.Name + ` = qt.` + ctor + `(` + qwidgetName(parentName, parentClass) + `)
@ -122,10 +119,7 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
// Layout
if w.Layout != nil {
ctor, ok := constructorFunctionFor(w.Layout.Class)
if !ok {
return "", fmt.Errorf("No known layout constructor function for %q class %q", w.Layout.Name, w.Layout.Class)
}
ctor := constructorFunctionFor(w.Layout.Class)
ret.WriteString(`
ui.` + w.Layout.Name + ` = qt.` + ctor + `(` + qwidgetName("ui."+w.Name, w.Class) + `)