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 package main
func constructorFunctionFor(className string) (string, bool) { func constructorFunctionFor(className string) string {
// Rebuild this list via: // 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 { switch className {
// CODEGENERATED LIST START // CODEGENERATED LIST START
case "QListWidget": case "QListWidget":
return "NewQListWidget2", true return "NewQListWidget2"
case "QAbstractSpinBox": case "QAbstractSpinBox":
return "NewQAbstractSpinBox2", true return "NewQAbstractSpinBox2"
case "QStackedLayout": case "QStackedLayout":
return "NewQStackedLayout2", true return "NewQStackedLayout2"
case "QColumnView": case "QColumnView":
return "NewQColumnView2", true return "NewQColumnView2"
case "QProgressDialog": case "QProgressDialog":
return "NewQProgressDialog3", true return "NewQProgressDialog3"
case "QTabWidget": case "QTabWidget":
return "NewQTabWidget2", true return "NewQTabWidget2"
case "QLabel": case "QLabel":
return "NewQLabel3", true return "NewQLabel3"
case "QKeySequenceEdit": case "QKeySequenceEdit":
return "NewQKeySequenceEdit3", true return "NewQKeySequenceEdit3"
case "QDockWidget": case "QDockWidget":
return "NewQDockWidget5", true return "NewQDockWidget5"
case "QFontComboBox": case "QFontComboBox":
return "NewQFontComboBox2", true return "NewQFontComboBox2"
case "QTreeView": case "QTreeView":
return "NewQTreeView2", true return "NewQTreeView2"
case "QCalendarWidget": case "QCalendarWidget":
return "NewQCalendarWidget2", true return "NewQCalendarWidget2"
case "QLineEdit": case "QLineEdit":
return "NewQLineEdit3", true return "NewQLineEdit3"
case "QMenuBar": case "QMenuBar":
return "NewQMenuBar2", true return "NewQMenuBar2"
case "QFrame": case "QFrame":
return "NewQFrame2", true return "NewQFrame2"
case "QAbstractScrollArea": case "QAbstractScrollArea":
return "NewQAbstractScrollArea2", true return "NewQAbstractScrollArea2"
case "QSplitter": case "QSplitter":
return "NewQSplitter3", true return "NewQSplitter3"
case "QStackedWidget": case "QStackedWidget":
return "NewQStackedWidget2", true return "NewQStackedWidget2"
case "QWizard": case "QWizard":
return "NewQWizard2", true return "NewQWizard2"
case "QWizardPage": case "QWizardPage":
return "NewQWizardPage2", true return "NewQWizardPage2"
case "QMdiSubWindow": case "QMdiSubWindow":
return "NewQMdiSubWindow2", true return "NewQMdiSubWindow2"
case "QStatusBar": case "QStatusBar":
return "NewQStatusBar2", true return "NewQStatusBar2"
case "QToolButton": case "QToolButton":
return "NewQToolButton2", true return "NewQToolButton2"
case "QShortcut": case "QShortcut":
return "NewQShortcut", true return "NewQShortcut"
case "QSlider": case "QSlider":
return "NewQSlider3", true return "NewQSlider3"
case "QComboBox": case "QComboBox":
return "NewQComboBox2", true return "NewQComboBox2"
case "QScrollBar": case "QScrollBar":
return "NewQScrollBar3", true return "NewQScrollBar3"
case "QTabBar": case "QTabBar":
return "NewQTabBar2", true return "NewQTabBar2"
case "QTextBrowser": case "QTextBrowser":
return "NewQTextBrowser2", true return "NewQTextBrowser2"
case "QTreeWidget": case "QTreeWidget":
return "NewQTreeWidget2", true return "NewQTreeWidget2"
case "QDialog": case "QDialog":
return "NewQDialog2", true return "NewQDialog2"
case "QFormLayout": case "QFormLayout":
return "NewQFormLayout2", true return "NewQFormLayout2"
case "QToolBar": case "QToolBar":
return "NewQToolBar4", true return "NewQToolBar4"
case "QWidget": case "QWidget":
return "NewQWidget2", true return "NewQWidget2"
case "QRadioButton": case "QRadioButton":
return "NewQRadioButton3", true return "NewQRadioButton3"
case "QCheckBox": case "QCheckBox":
return "NewQCheckBox3", true return "NewQCheckBox3"
case "QSizeGrip": case "QSizeGrip":
return "NewQSizeGrip", true return "NewQSizeGrip"
case "QLCDNumber": case "QLCDNumber":
return "NewQLCDNumber3", true return "NewQLCDNumber3"
case "QFileDialog": case "QFileDialog":
return "NewQFileDialog3", true return "NewQFileDialog3"
case "QUndoView": case "QUndoView":
return "NewQUndoView4", true return "NewQUndoView4"
case "QGraphicsView": case "QGraphicsView":
return "NewQGraphicsView3", true return "NewQGraphicsView3"
case "QPushButton": case "QPushButton":
return "NewQPushButton4", true return "NewQPushButton4"
case "QColorDialog": case "QColorDialog":
return "NewQColorDialog3", true return "NewQColorDialog3"
case "QMessageBox": case "QMessageBox":
return "NewQMessageBox4", true return "NewQMessageBox4"
case "QSplashScreen": case "QSplashScreen":
return "NewQSplashScreen3", true return "NewQSplashScreen3"
case "QErrorMessage": case "QErrorMessage":
return "NewQErrorMessage2", true return "NewQErrorMessage2"
case "QListView": case "QListView":
return "NewQListView2", true return "NewQListView2"
case "QDateTimeEdit": case "QDateTimeEdit":
return "NewQDateTimeEdit5", true return "NewQDateTimeEdit5"
case "QTimeEdit": case "QTimeEdit":
return "NewQTimeEdit3", true return "NewQTimeEdit3"
case "QDateEdit": case "QDateEdit":
return "NewQDateEdit3", true return "NewQDateEdit3"
case "QMenu": case "QMenu":
return "NewQMenu3", true return "NewQMenu3"
case "QToolBox": case "QToolBox":
return "NewQToolBox2", true return "NewQToolBox2"
case "QTableWidget": case "QTableWidget":
return "NewQTableWidget3", true return "NewQTableWidget3"
case "QFocusFrame": case "QFocusFrame":
return "NewQFocusFrame2", true return "NewQFocusFrame2"
case "QHBoxLayout": case "QHBoxLayout":
return "NewQHBoxLayout2", true return "NewQHBoxLayout2"
case "QVBoxLayout": case "QVBoxLayout":
return "NewQVBoxLayout2", true return "NewQVBoxLayout2"
case "QInputDialog": case "QInputDialog":
return "NewQInputDialog2", true return "NewQInputDialog2"
case "QTableView": case "QTableView":
return "NewQTableView2", true return "NewQTableView2"
case "QMdiArea": case "QMdiArea":
return "NewQMdiArea2", true return "NewQMdiArea2"
case "QSpinBox": case "QSpinBox":
return "NewQSpinBox2", true return "NewQSpinBox2"
case "QDoubleSpinBox": case "QDoubleSpinBox":
return "NewQDoubleSpinBox2", true return "NewQDoubleSpinBox2"
case "QProgressBar": case "QProgressBar":
return "NewQProgressBar2", true return "NewQProgressBar2"
case "QTextEdit": case "QTextEdit":
return "NewQTextEdit3", true return "NewQTextEdit3"
case "QAbstractSlider": case "QAbstractSlider":
return "NewQAbstractSlider2", true return "NewQAbstractSlider2"
case "QDialogButtonBox": case "QDialogButtonBox":
return "NewQDialogButtonBox5", true return "NewQDialogButtonBox5"
case "QFontDialog": case "QFontDialog":
return "NewQFontDialog3", true return "NewQFontDialog3"
case "QMainWindow": case "QMainWindow":
return "NewQMainWindow2", true return "NewQMainWindow2"
case "QCommandLinkButton": case "QCommandLinkButton":
return "NewQCommandLinkButton4", true return "NewQCommandLinkButton4"
case "QDial": case "QDial":
return "NewQDial2", true return "NewQDial2"
case "QGridLayout": case "QGridLayout":
return "NewQGridLayout", true return "NewQGridLayout"
case "QPlainTextEdit": case "QPlainTextEdit":
return "NewQPlainTextEdit3", true return "NewQPlainTextEdit3"
case "QScrollArea": case "QScrollArea":
return "NewQScrollArea2", true return "NewQScrollArea2"
case "QGroupBox": case "QGroupBox":
return "NewQGroupBox3", true return "NewQGroupBox3"
// CODEGENERATED LIST END // CODEGENERATED LIST END
default: 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) { func generateWidget(w UiWidget, parentName string, parentClass string) (string, error) {
ret := strings.Builder{} ret := strings.Builder{}
ctor, ok := constructorFunctionFor(w.Class) ctor := constructorFunctionFor(w.Class)
if !ok {
return "", fmt.Errorf("No known widget constructor function for %q class %q", w.Name, w.Class)
}
ret.WriteString(` ret.WriteString(`
ui.` + w.Name + ` = qt.` + ctor + `(` + qwidgetName(parentName, parentClass) + `) ui.` + w.Name + ` = qt.` + ctor + `(` + qwidgetName(parentName, parentClass) + `)
@ -122,10 +119,7 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
// Layout // Layout
if w.Layout != nil { if w.Layout != nil {
ctor, ok := constructorFunctionFor(w.Layout.Class) ctor := constructorFunctionFor(w.Layout.Class)
if !ok {
return "", fmt.Errorf("No known layout constructor function for %q class %q", w.Layout.Name, w.Layout.Class)
}
ret.WriteString(` ret.WriteString(`
ui.` + w.Layout.Name + ` = qt.` + ctor + `(` + qwidgetName("ui."+w.Name, w.Class) + `) ui.` + w.Layout.Name + ` = qt.` + ctor + `(` + qwidgetName("ui."+w.Name, w.Class) + `)