mirror of
https://github.com/OPM/ResInsight.git
synced 2026-09-03 20:53:13 -05:00
Merge pull request #4902 from OPM/summary-text-edit-in-toolbar
Summary text editor in toolbar
This commit is contained in:
@@ -45,6 +45,7 @@ set (MOC_HEADER_FILES
|
||||
cafPdmUniqueIdValidator.h
|
||||
cafPdmDoubleStringValidator.h
|
||||
cafPdmUiPickableLineEditor.h
|
||||
cafPdmUiLabelEditor.h
|
||||
)
|
||||
|
||||
if (CEE_USE_QT5)
|
||||
@@ -99,6 +100,8 @@ set( PROJECT_FILES
|
||||
cafPdmUiTreeSelectionQModel.cpp
|
||||
cafPdmUiFieldEditorHelper.h
|
||||
cafPdmUiFieldEditorHelper.cpp
|
||||
cafPdmUiLabelEditor.cpp
|
||||
|
||||
|
||||
# object editors
|
||||
cafPdmUiDefaultObjectEditor.cpp
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron 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 "cafPdmUiLabelEditor.h"
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiLabelEditor);
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiLabelEditor::PdmUiLabelEditor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiLabelEditor::~PdmUiLabelEditor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiLabelEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
{
|
||||
CAF_ASSERT(!m_label.isNull());
|
||||
|
||||
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiLabelEditor::createEditorWidget(QWidget * parent)
|
||||
{
|
||||
return createLabelWidget(parent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiLabelEditor::createLabelWidget(QWidget * parent)
|
||||
{
|
||||
if (m_label.isNull())
|
||||
{
|
||||
m_label = new QShortenedLabel(parent);
|
||||
}
|
||||
|
||||
return m_label;
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
@@ -0,0 +1,77 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2013 Ceetron 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 "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafQShortenedLabel.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
class QGridLayout;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
/// An editor to show (and possibly edit?) formatted larger portions of text
|
||||
//==================================================================================================
|
||||
class PdmUiLabelEditor : public PdmUiFieldEditorHandle
|
||||
{
|
||||
Q_OBJECT
|
||||
CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT;
|
||||
|
||||
public:
|
||||
PdmUiLabelEditor();
|
||||
~PdmUiLabelEditor() override;
|
||||
|
||||
protected:
|
||||
QWidget* createEditorWidget(QWidget * parent) override;
|
||||
QWidget* createLabelWidget(QWidget * parent) override;
|
||||
void configureAndUpdateUi(const QString& uiConfigName) override;
|
||||
|
||||
private:
|
||||
QPointer<QShortenedLabel> m_label;
|
||||
};
|
||||
|
||||
|
||||
} // end namespace caf
|
||||
@@ -38,29 +38,29 @@
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
|
||||
#include "cafFactory.h"
|
||||
#include "cafQShortenedLabel.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiDefaultObjectEditor.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafPdmUniqueIdValidator.h"
|
||||
#include "cafQShortenedLabel.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QAbstractProxyModel>
|
||||
#include <QApplication>
|
||||
#include <QKeyEvent>
|
||||
#include <QCompleter>
|
||||
#include <QDebug>
|
||||
#include <QIntValidator>
|
||||
#include <QKeyEvent>
|
||||
#include <QLabel>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QPalette>
|
||||
#include <QStatusBar>
|
||||
#include <QString>
|
||||
#include <QCompleter>
|
||||
#include <QStringListModel>
|
||||
#include <QAbstractProxyModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
namespace caf
|
||||
@@ -131,6 +131,16 @@ void PdmUiLineEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
|
||||
m_lineEdit->setAvoidSendingEnterEventToParentWidget(leab.avoidSendingEnterEventToParentWidget);
|
||||
|
||||
if (leab.maximumWidth != -1)
|
||||
{
|
||||
m_lineEdit->setMaximumWidth(leab.maximumWidth);
|
||||
}
|
||||
|
||||
if (!leab.placeholderText.isEmpty())
|
||||
{
|
||||
m_lineEdit->setPlaceholderText(leab.placeholderText);
|
||||
}
|
||||
}
|
||||
|
||||
bool fromMenuOnly = true;
|
||||
|
||||
@@ -64,6 +64,9 @@ public:
|
||||
avoidSendingEnterEventToParentWidget = false;
|
||||
completerCaseSensitivity = Qt::CaseInsensitive;
|
||||
completerFilterMode = Qt::MatchContains;
|
||||
maximumWidth = -1;
|
||||
selectAllOnFocusEvent = false;
|
||||
placeholderText = "";
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -73,6 +76,9 @@ public:
|
||||
// Completer setup
|
||||
Qt::CaseSensitivity completerCaseSensitivity;
|
||||
Qt::MatchFlags completerFilterMode;
|
||||
int maximumWidth;
|
||||
bool selectAllOnFocusEvent;
|
||||
QString placeholderText;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -42,12 +42,14 @@
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmUiFieldEditorHelper.h"
|
||||
#include "cafPdmUiFieldHandle.h"
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
#include "cafPdmUiObjectHandle.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafPdmUiPushButtonEditor.h"
|
||||
#include "cafPdmUiToolButtonEditor.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QToolBar>
|
||||
|
||||
@@ -232,6 +234,47 @@ void PdmUiToolBarEditor::clear()
|
||||
m_actions.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiToolBarEditor::setFocusWidgetFromKeyword(const QString& fieldKeyword)
|
||||
{
|
||||
if (!m_toolbar->isVisible()) return;
|
||||
|
||||
auto fieldView = m_fieldViews.find(fieldKeyword);
|
||||
if (fieldView != m_fieldViews.end() && fieldView->second)
|
||||
{
|
||||
auto editorWidget = fieldView->second->editorWidget();
|
||||
if (editorWidget)
|
||||
{
|
||||
editorWidget->setFocus(Qt::ActiveWindowFocusReason);
|
||||
|
||||
PdmUiLineEditorAttribute attributes;
|
||||
|
||||
for (auto field : m_fields)
|
||||
{
|
||||
if (field->keyword() == fieldKeyword)
|
||||
{
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj(field->ownerObject());
|
||||
if (uiObject)
|
||||
{
|
||||
uiObject->editorAttribute(field, uiEditorConfigName(), &attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attributes.selectAllOnFocusEvent)
|
||||
{
|
||||
auto lineEdit = dynamic_cast<QLineEdit*>(editorWidget);
|
||||
if (lineEdit )
|
||||
{
|
||||
lineEdit->selectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -254,4 +297,38 @@ void PdmUiToolBarEditor::hide()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Special config name used to configure toolbar UI (tooltip etc.)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString PdmUiToolBarEditor::uiEditorConfigName()
|
||||
{
|
||||
return "ToolbarConfigName";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString PdmUiToolBarEditor::keywordForFocusWidget()
|
||||
{
|
||||
QString keyword;
|
||||
|
||||
if (m_toolbar->isVisible())
|
||||
{
|
||||
for (auto fieldViewPair : m_fieldViews)
|
||||
{
|
||||
auto fieldView = fieldViewPair.second;
|
||||
if (fieldView)
|
||||
{
|
||||
auto editorWidget = fieldView->editorWidget();
|
||||
if (editorWidget && editorWidget->hasFocus())
|
||||
{
|
||||
keyword = fieldViewPair.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keyword;
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
|
||||
@@ -64,10 +64,15 @@ public:
|
||||
bool isEditorDataValid(const std::vector<caf::PdmFieldHandle*>& fields) const;
|
||||
void setFields(std::vector<caf::PdmFieldHandle*>& fields);
|
||||
void clear();
|
||||
|
||||
void setFocusWidgetFromKeyword(const QString& fieldKeyword);
|
||||
QString keywordForFocusWidget();
|
||||
|
||||
void show();
|
||||
void hide();
|
||||
|
||||
static QString uiEditorConfigName();
|
||||
|
||||
private:
|
||||
void configureAndUpdateUi(const QString& uiConfigName) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user