mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2083 AppFwk : Add notification when widgets are created
This commit is contained in:
parent
af34f5618e
commit
257a5c18d2
@ -400,5 +400,19 @@ void PdmUiItem::updateUiIconFromState(bool isActive, QString uiConfigName)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<PdmUiEditorHandle*> PdmUiItem::connectedEditors() const
|
||||
{
|
||||
std::vector<PdmUiEditorHandle*> editors;
|
||||
for (auto e : m_editors)
|
||||
{
|
||||
editors.push_back(e);
|
||||
}
|
||||
|
||||
return editors;
|
||||
}
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
|
@ -237,6 +237,9 @@ public:
|
||||
|
||||
void updateUiIconFromState(bool isActive, QString uiConfigName = "");
|
||||
|
||||
std::vector<PdmUiEditorHandle*>
|
||||
connectedEditors() const;
|
||||
|
||||
public: // Pdm-Private only
|
||||
//==================================================================================================
|
||||
/// This method sets the GUI description pointer, which is supposed to be statically allocated
|
||||
|
@ -60,6 +60,10 @@ public: // Virtual
|
||||
virtual QList<caf::PdmOptionItemInfo>
|
||||
calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) { return QList<PdmOptionItemInfo>(); }
|
||||
|
||||
/// Override used to attach application defined slots to caf created widgets
|
||||
/// All field editor widgets are supposed to be created when this function is called
|
||||
virtual void onEditorWidgetsCreated() {}
|
||||
|
||||
protected:
|
||||
/// Override to customize the order and grouping of the Gui.
|
||||
/// Fill up the uiOrdering object with groups and field references to create the gui structure
|
||||
|
@ -15,6 +15,7 @@ set ( QT_MOC_HEADERS
|
||||
WidgetLayoutTest.h
|
||||
ManyGroups.h
|
||||
CustomObjectEditor.h
|
||||
MenuItemProducer.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp( MOC_FILES_CPP
|
||||
@ -60,6 +61,8 @@ set( PROJECT_FILES
|
||||
ManyGroups.h
|
||||
CustomObjectEditor.cpp
|
||||
CustomObjectEditor.h
|
||||
MenuItemProducer.cpp
|
||||
MenuItemProducer.h
|
||||
)
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "CustomObjectEditor.h"
|
||||
#include "ManyGroups.h"
|
||||
#include "WidgetLayoutTest.h"
|
||||
#include "MenuItemProducer.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QTreeView>
|
||||
@ -404,6 +405,7 @@ public:
|
||||
m_longText.capability<caf::PdmUiFieldHandle>()->setUiEditorTypeName(caf::PdmUiTextEditor::uiEditorTypeName());
|
||||
m_longText.capability<caf::PdmUiFieldHandle>()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
|
||||
|
||||
m_menuItemProducer = new MenuItemProducer;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -487,6 +489,9 @@ public:
|
||||
|
||||
|
||||
caf::PdmField<bool> m_toggleField;
|
||||
|
||||
MenuItemProducer* m_menuItemProducer;
|
||||
|
||||
virtual caf::PdmFieldHandle* objectToggleField()
|
||||
{
|
||||
return &m_toggleField;
|
||||
@ -500,6 +505,30 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual void onEditorWidgetsCreated() override
|
||||
{
|
||||
for (auto e : m_longText.uiCapability()->connectedEditors())
|
||||
{
|
||||
caf::PdmUiTextEditor* textEditor = dynamic_cast<caf::PdmUiTextEditor*>(e);
|
||||
if (!textEditor) continue;
|
||||
|
||||
QWidget* containerWidget = textEditor->editorWidget();
|
||||
if (!containerWidget) continue;
|
||||
|
||||
for (auto qObj : containerWidget->children())
|
||||
{
|
||||
QTextEdit* textEdit = dynamic_cast<QTextEdit*>(qObj);
|
||||
if (textEdit)
|
||||
{
|
||||
m_menuItemProducer->attachTextEdit(textEdit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CAF_PDM_SOURCE_INIT(DemoPdmObject, "DemoPdmObject");
|
||||
|
108
Fwk/AppFwk/cafTests/cafTestApplication/MenuItemProducer.cpp
Normal file
108
Fwk/AppFwk/cafTests/cafTestApplication/MenuItemProducer.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "MenuItemProducer.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
#include <QPoint>
|
||||
#include <QTextCursor>
|
||||
#include <QTextEdit>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
MenuItemProducer::MenuItemProducer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void MenuItemProducer::attachTextEdit(QTextEdit* textEdit)
|
||||
{
|
||||
if (m_textEdit != textEdit)
|
||||
{
|
||||
textEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(textEdit, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotMenuItems(QPoint)));
|
||||
}
|
||||
|
||||
m_textEdit = textEdit;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void MenuItemProducer::slotMenuItems(QPoint point)
|
||||
{
|
||||
QMenu menu;
|
||||
QAction act("Testing", this);
|
||||
connect(&act, SIGNAL(triggered()), SLOT(slotShowText()));
|
||||
|
||||
menu.addAction(&act);
|
||||
|
||||
QPoint globalPoint = point;
|
||||
if (m_textEdit)
|
||||
{
|
||||
globalPoint = m_textEdit->mapToGlobal(point);
|
||||
|
||||
m_textPosition = m_textEdit->textCursor().position();
|
||||
}
|
||||
|
||||
menu.exec(globalPoint);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void MenuItemProducer::slotShowText()
|
||||
{
|
||||
if (m_textEdit)
|
||||
{
|
||||
QAction* action = qobject_cast<QAction *>(sender());
|
||||
if (action)
|
||||
{
|
||||
QTextCursor cursor = m_textEdit->textCursor();
|
||||
cursor.setPosition(m_textPosition);
|
||||
|
||||
m_textEdit->setTextCursor(cursor);
|
||||
m_textEdit->insertPlainText(action->text());
|
||||
}
|
||||
}
|
||||
}
|
70
Fwk/AppFwk/cafTests/cafTestApplication/MenuItemProducer.h
Normal file
70
Fwk/AppFwk/cafTests/cafTestApplication/MenuItemProducer.h
Normal file
@ -0,0 +1,70 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QPoint>
|
||||
#include <QPointer>
|
||||
|
||||
class QTextEdit;
|
||||
class QTextCursor;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class MenuItemProducer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MenuItemProducer();
|
||||
|
||||
void attachTextEdit(QTextEdit* textEdit);
|
||||
|
||||
public slots:
|
||||
void slotMenuItems(QPoint point);
|
||||
|
||||
private slots:
|
||||
void slotShowText();
|
||||
|
||||
private:
|
||||
QPointer<QTextEdit> m_textEdit;
|
||||
int m_textPosition;
|
||||
};
|
||||
|
||||
|
||||
|
@ -380,6 +380,13 @@ void caf::PdmUiWidgetBasedObjectEditor::configureAndUpdateUi(const QString& uiCo
|
||||
}
|
||||
}
|
||||
m_groupBoxes = m_newGroupBoxes;
|
||||
|
||||
// Notify pdm object when widgets have been created
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj(pdmObject());
|
||||
if (uiObject)
|
||||
{
|
||||
uiObject->onEditorWidgetsCreated();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user