【问题标题】:LibreOffice Tree with columns带列的 LibreOffice 树
【发布时间】:2021-12-24 05:48:11
【问题描述】:

我正在为 LibreOffifce 编写扩展程序。 我的侧边栏上需要一棵带有列的树。 (示例 - https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html

我找到了有关树控件和模块“树”的信息,例如这里 https://wiki.openoffice.org/wiki/Treecontrol https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/tree/module-ix.html

但我找不到任何关于编写带有列的树

有一句名言“您可以提供自己的模型,该模型必须至少支持接口 com.sun.star.awt.XTreeModel。”在“树控件”一文中,但我也找不到任何关于提供我自己的模型的信息......

如果可以为 LibreOffice 扩展提供带有列的树,请帮我查找信息和示例。

【问题讨论】:

    标签: libreoffice openoffice.org uno libreoffice-basic pyuno


    【解决方案1】:

    这里有一些 Python-UNO 代码(如您的问题中所标记),展示了如何实现 XTreeDataModel UNO 接口。您必须编写更多代码才能在多列中呈现节点并执行您想要的所有其他操作。可能需要创建另一个实现XTreeNode 的类。

    import uno
    import unohelper
    from com.sun.star.awt.tree import XTreeDataModel
    
    def myTree():
        document = XSCRIPTCONTEXT.getDocument()
        ctx = XSCRIPTCONTEXT.getComponentContext()
        smgr = ctx.getServiceManager()
        dlgprov = smgr.createInstanceWithArgumentsAndContext(
            "com.sun.star.awt.DialogProvider", (document,), ctx)
        dlg = dlgprov.createDialog(
            "vnd.sun.star.script:Standard.Dialog1?location=application")
    
        treeCtrl = dlg.getControl("TreeControl1")
        treeModel = treeCtrl.getModel()
        mutableTreeDataModel = smgr.createInstanceWithContext(
            "com.sun.star.awt.tree.MutableTreeDataModel", ctx)
        rootNode = mutableTreeDataModel.createNode("Root", True)  
        mutableTreeDataModel.setRoot(rootNode)
        myTree = MyTreeDataModel(rootNode)
        model = mutableTreeDataModel
    
        childNode1 = model.createNode("Parent 1", True)
        rootNode.appendChild(childNode1)   
        subChildNode = model.createNode("Child 1", True)
        childNode1.appendChild(subChildNode)
    
        treeModel.setPropertyValue("DataModel", myTree)
        dlg.execute()
        dlg.dispose()
    
    class MyTreeDataModel(unohelper.Base, XTreeDataModel):
        def __init__(self, root):
            self.rootNode = root
      
        def getRoot(self):
            return self.rootNode
    
        def addTreeDataModelListener(self, listener):
            pass
    
        def removeTreeDataModelListener(self, listener):
            pass
    

    有关使用树木的更多信息,请访问https://wiki.openoffice.org/wiki/Going_further_with_Dialog_and_Component#The_New_Tree_Control

    如果事实证明没有方便的方法可以直接使用 UNO 执行此操作,我曾经使用 Java 中的 JTreeTable 执行此操作。 LibreOffice 扩展可以用 Java 编写,所以也许这可以解决您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多