Work in progress

This commit is contained in:
Gaute Lindkvist
2019-04-08 14:29:47 +02:00
parent b03e75065c
commit c0f3258f19
25 changed files with 128 additions and 82 deletions

View File

@@ -200,7 +200,7 @@ std::vector<RimWellPath*> RicWellPathExportCompletionDataFeature::selectedWellPa
if (wellPaths.empty())
{
RimWellPathCompletions* completions = caf::SelectionManager::instance()->selectedItemOfType<RimWellPathCompletions>();
RimWellPathCompletions* completions = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPathCompletions>();
if (completions)
{
RimWellPath* wellPath = nullptr;

View File

@@ -886,7 +886,7 @@ QString RimEclipseResultDefinition::diffResultUiName() const
{
diffResult += QString("<b>Base Case</b>: %1").arg(m_differenceCase()->caseUserDescription());
}
return diffResult.join("<br>\n");
return diffResult.join("\n");
}
//--------------------------------------------------------------------------------------------------
@@ -928,7 +928,7 @@ QString RimEclipseResultDefinition::diffResultUiShortNameHTML() const
{
diffResult += QString("Base Time: #%1").arg(m_timeLapseBaseTimestep());
}
return diffResult.join("\n<br>");
return diffResult.join("<br>");
}
//--------------------------------------------------------------------------------------------------
@@ -1317,7 +1317,7 @@ void RimEclipseResultDefinition::defineUiOrdering(QString uiConfigName, caf::Pdm
QString resultPropertyLabel = "Result Property";
if (isTimeDiffResult() || isCaseDiffResult())
{
resultPropertyLabel += QString("<br>\n<br>\n%1").arg(diffResultUiShortNameHTML());
resultPropertyLabel += QString("\n%1").arg(diffResultUiShortName());
}
m_resultVariableUiField.uiCapability()->setUiName(resultPropertyLabel);
}

View File

@@ -20,6 +20,7 @@ set (MOC_HEADER_FILES
cafPdmUiEditorHandle.h
cafPdmUiFieldEditorHandle.h
cafPdmUiSelection3dEditorVisualizer.h
cafQShortenedLabel.h
)
# Run MOC on the headers
@@ -73,6 +74,9 @@ set( PROJECT_FILES
cafSelectionManagerTools.h
cafPdmUiSelection3dEditorVisualizer.h
cafPdmUiSelection3dEditorVisualizer.cpp
cafQShortenedLabel.cpp
cafQShortenedLabel.h
)
add_library( ${PROJECT_NAME}

View File

@@ -145,7 +145,7 @@ void PdmUiFieldEditorHandle::setValueToField(const QVariant& newUiValue)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiFieldEditorHandle::updateLabelFromField(QLabel* label, const QString& uiConfigName) const
void PdmUiFieldEditorHandle::updateLabelFromField(QShortenedLabel* label, const QString& uiConfigName /*= ""*/) const
{
CAF_ASSERT(label);

View File

@@ -35,9 +35,10 @@
//##################################################################################################
#pragma once
#include "cafClassTypeName.h"
#include "cafFactory.h"
#include "cafPdmUiEditorHandle.h"
#include "cafClassTypeName.h"
#include "cafQShortenedLabel.h"
#include <vector>
@@ -109,9 +110,9 @@ protected: // Virtual interface to override
void setValueToField(const QVariant& value);
void updateLabelFromField(QLabel* label, const QString& uiConfigName = "") const;
void updateLabelFromField(QShortenedLabel* label, const QString& uiConfigName = "") const;
virtual QMargins calculateLabelContentMargins() const;
virtual bool isMultiRowEditor() const;
virtual bool isMultiRowEditor() const;
private slots:
void customMenuRequested(QPoint pos);

View File

@@ -38,6 +38,7 @@
#include <QApplication>
#include <QFontMetrics>
#include <QResizeEvent>
#include <QVBoxLayout>
using namespace caf;
@@ -49,25 +50,52 @@ QShortenedLabel::QShortenedLabel(QWidget* parent /*= nullptr*/, Qt::WindowFlags
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::QShortenedLabel::setText(const QString& text)
{
m_fullLengthText = text;
setDisplayText(text);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString QShortenedLabel::fullText() const
{
return m_fullLengthText;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize QShortenedLabel::minimumSizeHint() const
{
int minimumWidth = 0;
int minimumWidth = 20;
QFontMetrics fontMetrics = QApplication::fontMetrics();
QString fullLabelText = fullText();
if (!fullLabelText.isEmpty())
{
minimumWidth = 10;
int maxLineWidth = 0;
int maxFirstWordWidth = 0;
QStringList words = fullLabelText.split(" ");
if (!words.empty())
QStringList labelLines = fullLabelText.split("\n");
for (QString line : labelLines)
{
int textMinimumWidth = std::min(fontMetrics.width(fullLabelText), fontMetrics.width(words.front() + "..."));
minimumWidth = std::max(minimumWidth, textMinimumWidth);
int lineWidth = fontMetrics.width(line);
maxLineWidth = std::max(maxLineWidth, lineWidth);
QStringList words = line.split(" ");
if (!words.empty())
{
int wordWidth = fontMetrics.width(words.front() + "...");
maxFirstWordWidth = std::max(maxFirstWordWidth, wordWidth);
}
}
int minimumTextWidth = std::min(maxLineWidth, maxFirstWordWidth);
minimumWidth = std::max(minimumWidth, minimumTextWidth);
}
QSize minimumSize = QLabel::minimumSizeHint();
minimumSize.setWidth(minimumWidth);
@@ -81,9 +109,15 @@ QSize QShortenedLabel::sizeHint() const
{
QFontMetrics fontMetrics = QApplication::fontMetrics();
QString labelText = fullText();
QSize size = QLabel::sizeHint();
size.setWidth(fontMetrics.width(labelText));
return size;
QStringList labelLines = labelText.split("\n");
int maxLineWidth = 0;
for (const QString& line : labelLines)
{
maxLineWidth = std::max(maxLineWidth, fontMetrics.width(line));
}
return QSize(maxLineWidth, QLabel::sizeHint().height());
}
//--------------------------------------------------------------------------------------------------
@@ -91,42 +125,48 @@ QSize QShortenedLabel::sizeHint() const
//--------------------------------------------------------------------------------------------------
void QShortenedLabel::resizeEvent(QResizeEvent* event)
{
QString labelText = fullText();
QSize paintSize = event->size();
resizeText(paintSize);
QLabel::resizeEvent(event);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::QShortenedLabel::resizeText(QSize paintSize)
{
QString labelText = fullText();
QFontMetrics fontMetrics = QApplication::fontMetrics();
if (fontMetrics.width(labelText) < event->size().width())
QStringList labelLines = labelText.split("\n");
int maxLineWidth = 0;
for (const QString& line : labelLines)
{
maxLineWidth += fontMetrics.width(line);
}
if (maxLineWidth < paintSize.width())
{
setDisplayText(labelText);
}
else
{
int width = std::max(minimumSizeHint().width(), event->size().width());
QString elidedText = fontMetrics.elidedText(labelText, Qt::ElideRight, width);
setDisplayText(elidedText);
int limitWidth = std::max(minimumSizeHint().width(), paintSize.width());
QStringList elidedLines;
for (const QString& line : labelLines)
{
QString elidedLine = fontMetrics.elidedText(line, Qt::ElideRight, limitWidth);
elidedLines.push_back(elidedLine);
}
setDisplayText(elidedLines.join("\n"));
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void QShortenedLabel::setDisplayText(const QString& shortText)
void QShortenedLabel::setDisplayText(const QString& displayText)
{
// Store original text if we haven't already done so.
if (m_fullLengthText.isEmpty())
{
m_fullLengthText = text();
}
setText(shortText);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString QShortenedLabel::fullText() const
{
if (!m_fullLengthText.isEmpty())
{
return m_fullLengthText;
}
return text();
QLabel::setText(displayText);
}

View File

@@ -45,15 +45,17 @@ class QShortenedLabel : public QLabel
public:
explicit QShortenedLabel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
protected:
void resizeEvent(QResizeEvent *event) override;
void setDisplayText(const QString& shortText);
void setText(const QString& text);
QString fullText() const;
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
protected:
void resizeEvent(QResizeEvent *event) override;
void resizeText(QSize paintSize);
void setDisplayText(const QString& shortText);
private:
QString m_fullLengthText;
QString m_fullLengthText;
};
}

View File

@@ -44,7 +44,6 @@ set (MOC_HEADER_FILES
cafPdmUiTreeViewEditor.h
cafUiProcess.h
QMinimizePanel.h
cafQShortenedLabel.h
cafQStyledProgressBar.h
cafPdmUiTreeSelectionEditor.h
cafPdmUiTreeSelectionQModel.h
@@ -151,8 +150,6 @@ set( PROJECT_FILES
cafUiProcess.h
QMinimizePanel.cpp
QMinimizePanel.h
cafQShortenedLabel.cpp
cafQShortenedLabel.h
cafQStyledProgressBar.cpp
cafQStyledProgressBar.h
cafQTreeViewStateSerializer.h

View File

@@ -81,8 +81,8 @@ protected slots:
void slotClicked(bool checked);
private:
QPointer<QCheckBox> m_checkBox;
QPointer<QLabel> m_label;
QPointer<QCheckBox> m_checkBox;
QPointer<QShortenedLabel> m_label;
};

View File

@@ -31,7 +31,7 @@ protected slots:
private:
QPointer<QCheckBox> m_checkBox;
QPointer<QLabel> m_label;
QPointer<QShortenedLabel> m_label;
};

View File

@@ -89,7 +89,7 @@ private:
void setColorOnWidget(const QColor& c);
private:
QPointer<QLabel> m_label;
QPointer<QShortenedLabel> m_label;
QColor m_color;
QPointer<QLabel> m_colorPixmapLabel;

View File

@@ -100,7 +100,7 @@ protected slots:
private:
QPointer<QComboBox> m_comboBox;
QPointer<QLabel> m_label;
QPointer<QShortenedLabel> m_label;
QPointer<QToolButton> m_previousItemButton;
QPointer<QToolButton> m_nextItemButton;

View File

@@ -84,7 +84,7 @@ protected slots:
private:
QPointer<QDateEdit> m_dateEdit;
QPointer<QLabel> m_label;
QPointer<QShortenedLabel> m_label;
PdmUiDateEditorAttribute m_attributes;
};

View File

@@ -103,10 +103,10 @@ private:
double convertFromSliderValue(int sliderValue);
private:
QPointer<QLineEdit> m_lineEdit;
QPointer<QSlider> m_slider;
QPointer<QLabel> m_label;
double m_sliderValue;
QPointer<QLineEdit> m_lineEdit;
QPointer<QSlider> m_slider;
QPointer<QShortenedLabel> m_label;
double m_sliderValue;
PdmUiDoubleSliderEditorAttribute m_attributes;
};

View File

@@ -86,8 +86,8 @@ private:
void writeValueToField();
private:
QPointer<QLineEdit> m_lineEdit;
QPointer<QLabel> m_label;
QPointer<QLineEdit> m_lineEdit;
QPointer<QShortenedLabel> m_label;
PdmUiDoubleValueEditorAttribute m_attributes;
};

View File

@@ -104,9 +104,9 @@ protected slots:
void fileSelectionClicked();
private:
QPointer<QLineEdit> m_lineEdit;
QPointer<QLabel> m_label;
QPointer<QToolButton> m_button;
QPointer<QLineEdit> m_lineEdit;
QPointer<QShortenedLabel> m_label;
QPointer<QToolButton> m_button;
PdmUiFilePathEditorAttribute m_attributes;
};

View File

@@ -117,8 +117,8 @@ private:
bool isMultipleFieldsWithSameKeywordSelected(PdmFieldHandle* editorField) const;
protected:
QPointer<PdmUiLineEdit> m_lineEdit;
QPointer<QLabel> m_label;
QPointer<PdmUiLineEdit> m_lineEdit;
QPointer<QShortenedLabel> m_label;
};

View File

@@ -104,7 +104,7 @@ private:
private:
QPointer<QListViewHeightHint> m_listView;
QPointer<QLabel> m_label;
QPointer<QShortenedLabel> m_label;
QPointer<QStringListModel> m_model;
bool m_isEditOperationsAvailable;

View File

@@ -224,7 +224,9 @@ PdmObjectHandle* PdmUiPropertyView::currentObject()
//--------------------------------------------------------------------------------------------------
QSize PdmUiPropertyView::sizeHint() const
{
return m_scrollArea->sizeHint().expandedTo(m_placeholder->sizeHint());
QSize scrollSize = m_scrollArea->sizeHint();
QSize contentSize = m_placeholder->sizeHint();
return QSize(scrollSize.width(), contentSize.height());
}
//--------------------------------------------------------------------------------------------------

View File

@@ -80,9 +80,9 @@ protected slots:
void slotClicked(bool checked);
private:
QPointer<QPushButton> m_pushButton;
QPointer<QLabel> m_label;
QPointer<QHBoxLayout> m_buttonLayout;
QPointer<QPushButton> m_pushButton;
QPointer<QShortenedLabel> m_label;
QPointer<QHBoxLayout> m_buttonLayout;
};

View File

@@ -91,9 +91,9 @@ private:
void writeValueToField();
private:
QPointer<QSpinBox> m_spinBox;
QPointer<QSlider> m_slider;
QPointer<QLabel> m_label;
QPointer<QSpinBox> m_spinBox;
QPointer<QSlider> m_slider;
QPointer<QShortenedLabel> m_label;
PdmUiSliderEditorAttribute m_attributes;
};

View File

@@ -121,7 +121,7 @@ QWidget* PdmUiTableViewEditor::createLabelWidget(QWidget * parent)
if (m_tableHeadingIcon.isNull())
{
m_tableHeadingIcon = new QShortenedLabel(parent);
m_tableHeadingIcon = new QLabel(parent);
}
QHBoxLayout* layoutForIconLabel = new QHBoxLayout();

View File

@@ -153,8 +153,8 @@ private slots:
private:
friend class FocusEventHandler;
QPointer<QLabel> m_tableHeading;
QPointer<QLabel> m_tableHeadingIcon;
QPointer<QShortenedLabel> m_tableHeading;
QPointer<QLabel> m_tableHeadingIcon;
QTableView* m_tableView;
PdmUiTableViewQModel* m_tableModelPdm;

View File

@@ -133,9 +133,9 @@ private:
QTextOption::WrapMode toQTextOptionWrapMode(PdmUiTextEditorAttribute::WrapMode wrapMode);
private:
QPointer<TextEdit> m_textEdit;
QPointer<QPushButton> m_saveButton;
QPointer<QLabel> m_label;
QPointer<TextEdit> m_textEdit;
QPointer<QPushButton> m_saveButton;
QPointer<QShortenedLabel> m_label;
PdmUiTextEditorAttribute::TextMode m_textMode;
};

View File

@@ -129,7 +129,7 @@ private:
private:
QPointer<QTreeView> m_treeView;
QPointer<QLabel> m_label;
QPointer<QShortenedLabel> m_label;
QPointer<QCheckBox> m_toggleAllCheckBox;
QPointer<QLineEdit> m_textFilterLineEdit;