Commit eeddc65e authored by Barth Netterfield's avatar Barth Netterfield
Browse files

Curve Dialog gets a manual Legend Name entry.

This overrides all automatic naming.

BUG: 293230
parent 9db9477d
......@@ -83,7 +83,8 @@ CurveTab::CurveTab(QWidget *parent)
connect(_ignoreAutoScale, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
connect(_xMinusSameAsPlus, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
connect(_yMinusSameAsPlus, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
connect(_manualLegendName, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
connect(_autoLegend, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
}
......@@ -284,6 +285,28 @@ void CurveTab::setPlotMode(PlotItem *plot) {
}
QString CurveTab::manualLegendName() const {
if (_autoLegend->isChecked()) {
return QString();
} else {
return _manualLegendName->text();
}
}
void CurveTab::setManualLegendNameText(const QString &name) {
_manualLegendName->setText(name);
}
void CurveTab::setLegendAuto(bool is_auto) {
_autoLegend->setChecked(is_auto);
}
void CurveTab::setLegendNameVisible(bool visible) {
_autoLegend->setVisible(visible);
_manualLegendName->setVisible(visible);
_legendLabel->setVisible(visible);
}
void CurveTab::updateVectorCombos() {
_xVector->fillVectors();
_yVector->fillVectors();
......@@ -329,14 +352,15 @@ CurveDialog::~CurveDialog() {
//
void CurveDialog::editMultipleMode() {
_curveTab->setLegendNameVisible(false);
_curveTab->clearTabValues();
}
void CurveDialog::editSingleMode() {
_curveTab->setLegendNameVisible(true);
configureTab(dataObject());
}
void CurveDialog::configureTab(ObjectPtr object) {
if (!object) {
_curveTab->curveAppearance()->loadWidgetDefaults();
......@@ -371,6 +395,8 @@ void CurveDialog::configureTab(ObjectPtr object) {
_curveTab->curveAppearance()->setPointDensity(curve->pointDensity());
_curveTab->curveAppearance()->setBarFillColor(curve->barFillColor());
_curveTab->curveAppearance()->setHeadType(curve->headType());
_curveTab->setManualLegendNameText(curve->legendName(true, true));
_curveTab->setLegendAuto(curve->manualLegendName().isEmpty());
_curveTab->hidePlacementOptions();
if (_editMultipleWidget) {
CurveList objects = _document->objectStore()->getObjects<Curve>();
......@@ -430,6 +456,7 @@ ObjectPtr CurveDialog::createNewDataObject() {
curve->setBarFillColor(_curveTab->curveAppearance()->barFillColor());
curve->setHeadType(_curveTab->curveAppearance()->headType());
curve->setIgnoreAutoScale(_curveTab->ignoreAutoScale());
curve->setManualLegendName(_curveTab->manualLegendName());
if (DataDialog::tagStringAuto()) {
curve->setDescriptiveName(QString());
......@@ -595,6 +622,8 @@ ObjectPtr CurveDialog::editExistingDataObject() const {
curve->setPointDensity(_curveTab->curveAppearance()->pointDensity());
curve->setHeadType(_curveTab->curveAppearance()->headType());
curve->setIgnoreAutoScale(_curveTab->ignoreAutoScale());
curve->setManualLegendName(_curveTab->manualLegendName());
if (DataDialog::tagStringAuto()) {
curve->setDescriptiveName(QString());
} else {
......
......@@ -72,6 +72,12 @@ class CurveTab : public DataTab, Ui::CurveTab {
void setToLastX() {_xVector->setToLastX();}
void setPlotMode(PlotItem *plot);
QString manualLegendName() const;
void setManualLegendNameText(const QString &name);
void setLegendAuto(bool is_auto);
void setLegendNameVisible(bool visible);
Q_SIGNALS:
void vectorsChanged();
......
......@@ -2,7 +2,49 @@
<ui version="4.0">
<class>CurveTab</class>
<widget class="QWidget" name="CurveTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>443</width>
<height>250</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="_legendLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Legend Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="_manualLegendName">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="_autoLegend">
<property name="text">
<string>Auto</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="GroupBox">
<property name="title">
......@@ -251,5 +293,22 @@
<tabstop>_curvePlacement</tabstop>
</tabstops>
<resources/>
<connections/>
<connections>
<connection>
<sender>_autoLegend</sender>
<signal>toggled(bool)</signal>
<receiver>_manualLegendName</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>397</x>
<y>21</y>
</hint>
<hint type="destinationlabel">
<x>301</x>
<y>31</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -36,7 +36,7 @@
namespace Kst {
DataDialog::DataDialog(Kst::ObjectPtr dataObject, QWidget *parent, bool edit_multiple)
: Dialog(parent), _dataObject(dataObject), _modified(false) {
: Dialog(parent), _dataObject(dataObject), _modified(false), _coreWindowWidth(0) {
_dataObjectName.clear();
......@@ -216,13 +216,21 @@ void DataDialog::slotEditMultiple() {
int extensionWidth = extensionWidget()->width();
if (extensionWidth<charWidth*20) extensionWidth = charWidth*25; // FIXME: magic number hack...
extensionWidget()->setVisible(!extensionWidget()->isVisible());
if (_coreWindowWidth == 0) {
_coreWindowWidth = currentWidth;
}
if (!extensionWidget()->isVisible()) {
_tagString->setVisible(true);
_shortName->setVisible(true);
_tagStringAuto->setVisible(true);
_nameLabel->setVisible(true);
setMinimumWidth(currentWidth - extensionWidth);
resize(currentWidth - extensionWidth, height());
//setMinimumWidth(currentWidth - extensionWidth);
if (_coreWindowWidth > currentWidth - extensionWidth) {
resize(_coreWindowWidth, height());
} else {
resize(currentWidth - extensionWidth, height());
_coreWindowWidth = currentWidth - extensionWidth;
}
_mode = Edit;
_editMultipleButton->setText(tr("Edit Multiple >>"));
emit editSingleMode();
......@@ -232,7 +240,8 @@ void DataDialog::slotEditMultiple() {
_shortName->setVisible(false);
_tagStringAuto->setVisible(false);
_nameLabel->setVisible(false);
setMinimumWidth(currentWidth + extensionWidth);
_coreWindowWidth = currentWidth;
//setMinimumWidth(currentWidth + extensionWidth);
resize(currentWidth + extensionWidth, height());
_mode = EditMultiple;
_editMultipleButton->setText(tr("<< Edit one %1").arg(_shortName->text()));
......
......@@ -87,6 +87,7 @@ class DataDialog : public Dialog {
ObjectPtr _dataObject;
EditMode _mode;
bool _modified;
int _coreWindowWidth;
};
}
......
......@@ -115,53 +115,33 @@ void LegendItem::paint(QPainter *painter) {
}
}
if (!allAuto) {
for (int i = 0; i<count; i++) {
names.append(legendItems.at(i)->descriptiveName());
}
} else {
for (int i = 0; i<count; i++) {
RelationPtr relation = legendItems.at(i);
QString label = relation->titleInfo().singleRenderItemLabel();
if (label.isEmpty()) {
label_info = relation->yLabelInfo();
QString y_label = label_info.name;
if (!sameYUnits) {
if (!label_info.units.isEmpty()) {
y_label = tr("%1 \\[%2\\]", "axis labels. %1 is quantity, %2 is units. eg Time [s]. '[' must be escaped.").arg(y_label).arg(label_info.units);
}
}
if (!y_label.isEmpty()) {
LabelInfo xlabel_info = relation->xLabelInfo();
if (!sameX) {
label = tr("%1 vs %2", "describes a plot. %1 is X axis. %2 is Y axis").arg(y_label).arg(xlabel_info.name);
} else if (xlabel_info.quantity.isEmpty()) {
label = y_label;
} else if (xlabel_info.quantity != xlabel_info.name) {
label = tr("%1 vs %2", "describes a plot. %1 is X axis. %2 is Y axis").arg(y_label).arg(xlabel_info.name);
} else {
label = y_label;
}
} else {
label = relation->descriptiveName();
}
// if (!allAuto) {
// for (int i = 0; i<count; i++) {
// names.append(legendItems.at(i)->descriptiveName());
// }
// } else {
// FIXME: move most of this into a new function, relation->legend_name
// then create separate [legend_name] and Auto in the relation dialog.
// show relation->legend_name in dialog when [x] Auto
for (int i = 0; i<count; i++) {
RelationPtr relation = legendItems.at(i);
QString label = relation->legendName(sameX, sameYUnits);
int i_dup = names.indexOf(label);
if (i_dup<0) {
names.append(label);
} else {
RelationPtr dup_relation = legendItems.at(i_dup);
if (!dup_relation->yLabelInfo().file.isEmpty()) {
names.replace(i_dup, label + " (" + dup_relation->yLabelInfo().escapedFile() + ')');
}
int i_dup = names.indexOf(label);
if (i_dup<0) {
names.append(label);
} else {
RelationPtr dup_relation = legendItems.at(i_dup);
if (!dup_relation->yLabelInfo().file.isEmpty()) {
names.replace(i_dup, label + " (" + dup_relation->yLabelInfo().escapedFile() + ')');
}
if (!relation->yLabelInfo().file.isEmpty()) {
names.append(label + " (" + relation->yLabelInfo().escapedFile() + ')');
}
if (!relation->yLabelInfo().file.isEmpty()) {
names.append(label + " (" + relation->yLabelInfo().escapedFile() + ')');
}
}
}
QSize legendSize(0, 0);
QSize titleSize(0,0);
Label::Parsed *parsed = Label::parse(_title, _color);
......
......@@ -57,6 +57,8 @@ void Relation::commonConstructor() {
_contextDetails.xLogBase = 0.0;
_contextDetails.yLogBase = 0.0;
_contextDetails.penWidth = 0;
_manualLegendName.clear();
}
......@@ -162,10 +164,20 @@ qint64 Relation::maxInputSerialOfLastChange() const {
return maxSerial;
}
QString Relation::manualLegendName() const
{
return _manualLegendName;
}
void Relation::setManualLegendName(const QString &manualLegendName)
{
_manualLegendName = manualLegendName;
}
void Relation::writeLockInputsAndOutputs() const {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
#ifdef LOCKTRACE
#ifdef LOCKTRACE
qDebug() << (void*)this << this->Name() << ") Relation::writeLockInputsAndOutputs() by tid=" << (int)QThread::currentThread() << endl;
#endif
......@@ -464,6 +476,40 @@ PrimitiveList Relation::inputPrimitives() const {
return primitive_list;
}
QString Relation::legendName(bool sameX, bool sameYUnits) const {
if (_manualLegendName.isEmpty()) {
QString label = titleInfo().singleRenderItemLabel();
if (label.isEmpty()) {
LabelInfo label_info = yLabelInfo();
QString y_label = label_info.name;
if (!sameYUnits) {
if (!label_info.units.isEmpty()) {
y_label = tr("%1 \\[%2\\]", "axis labels. %1 is quantity, %2 is units. eg Time [s]. '[' must be escaped.").arg(y_label).arg(label_info.units);
}
}
if (!y_label.isEmpty()) {
LabelInfo xlabel_info = xLabelInfo();
if (!sameX) {
label = tr("%1 vs %2", "describes a plot. %1 is X axis. %2 is Y axis").arg(y_label).arg(xlabel_info.name);
} else if (xlabel_info.quantity.isEmpty()) {
label = y_label;
} else if (xlabel_info.quantity != xlabel_info.name) {
label = tr("%1 vs %2", "describes a plot. %1 is X axis. %2 is Y axis").arg(y_label).arg(xlabel_info.name);
} else {
label = y_label;
}
} else {
label = descriptiveName();
}
}
return label;
} else {
return _manualLegendName;
}
}
void Relation::replaceInput(PrimitivePtr p, PrimitivePtr new_p) {
if (VectorPtr v = kst_cast<Vector>(p) ) {
if (VectorPtr new_v = kst_cast<Vector>(new_p)) {
......
......@@ -168,7 +168,12 @@ class KSTMATH_EXPORT Relation : public Object {
virtual LabelInfo yLabelInfo() const = 0;
virtual LabelInfo titleInfo() const = 0;
protected:
virtual QString legendName(bool sameX, bool sameYUnits) const;
QString manualLegendName() const;
void setManualLegendName(const QString &manualLegendName);
protected:
virtual void writeLockInputsAndOutputs() const;
virtual void unlockInputsAndOutputs() const;
......@@ -201,6 +206,8 @@ class KSTMATH_EXPORT Relation : public Object {
CurveContextDetails _contextDetails;
bool _redrawRequired;
QString _manualLegendName;
private:
void commonConstructor();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment