Added enabled state and button to be able to execute a command object

p4#: 22397
This commit is contained in:
Magne Sjaastad 2013-09-13 09:17:57 +02:00
parent 18a05b7bff
commit 32b148ee0e
5 changed files with 63 additions and 5 deletions

View File

@ -51,6 +51,7 @@ RimCommandExecuteScript::RimCommandExecuteScript()
{
CAF_PDM_InitField(&scriptText, "ScriptText", QString(), "ScriptText", "", "" ,"");
scriptText.setUiEditorTypeName(caf::PdmUiTextEditor::uiEditorTypeName());
}
//--------------------------------------------------------------------------------------------------
@ -93,6 +94,18 @@ void RimCommandExecuteScript::undo()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCommandExecuteScript::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
caf::PdmUiTextEditorAttribute* myAttr = dynamic_cast<caf::PdmUiTextEditorAttribute*>(attribute);
if (myAttr)
{
myAttr->showSaveButton = true;
}
}

View File

@ -55,6 +55,8 @@ public:
virtual void redo();
virtual void undo();
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
};

View File

@ -139,6 +139,8 @@ void RiuMainWindow::initializeGuiNewProjectLoaded()
slotRefreshViewActions();
refreshAnimationActions();
refreshDrawStyleActions();
m_processMonitor->slotClearTextEdit();
}
//--------------------------------------------------------------------------------------------------

View File

@ -30,6 +30,7 @@
#include <QTextEdit>
#include <QLabel>
#include <QIntValidator>
#include <QVBoxLayout>
#include <assert.h>
#include "cafFactory.h"
@ -69,6 +70,17 @@ void PdmUiTextEditor::configureAndUpdateUi(const QString& uiConfigName)
field()->ownerObject()->editorAttribute(field(), uiConfigName, &leab);
m_textMode = leab.textMode;
if (leab.showSaveButton)
{
disconnect(m_textEdit, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
m_saveButton->show();
}
else
{
connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
m_saveButton->hide();
}
m_textEdit->blockSignals(true);
switch (leab.textMode)
{
@ -89,9 +101,25 @@ void PdmUiTextEditor::configureAndUpdateUi(const QString& uiConfigName)
//--------------------------------------------------------------------------------------------------
QWidget* PdmUiTextEditor::createEditorWidget(QWidget * parent)
{
m_textEdit = new QTextEdit(parent);
QWidget* containerWidget = new QWidget(parent);
m_textEdit = new QTextEdit(containerWidget);
connect(m_textEdit, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
return m_textEdit;
m_saveButton = new QPushButton("Save changes", containerWidget);
connect(m_saveButton, SIGNAL(clicked()), this, SLOT(slotSaveButtonClicked()));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(m_textEdit);
QHBoxLayout* buttonLayout = new QHBoxLayout;
buttonLayout->insertStretch(0, 10);
buttonLayout->addWidget(m_saveButton);
layout->addLayout(buttonLayout);
containerWidget->setLayout(layout);
return containerWidget;
}
//--------------------------------------------------------------------------------------------------
@ -126,5 +154,13 @@ void PdmUiTextEditor::slotTextChanged()
this->setValueToField(v);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiTextEditor::slotSaveButtonClicked()
{
slotTextChanged();
}
} // end namespace caf

View File

@ -22,6 +22,7 @@
#include <QString>
#include <QWidget>
#include <QPointer>
#include <QPushButton>
#include <QTextEdit>
#include <QLabel>
@ -40,6 +41,7 @@ public:
PdmUiTextEditorAttribute()
{
textMode = PLAIN;
showSaveButton = false;
}
enum TextMode
@ -49,7 +51,8 @@ public:
};
public:
TextMode textMode;
TextMode textMode;
bool showSaveButton;
};
@ -69,10 +72,12 @@ protected:
protected slots:
void slotTextChanged();
void slotSaveButtonClicked();
private:
QPointer<QTextEdit> m_textEdit;
QPointer<QLabel> m_label;
QPointer<QTextEdit> m_textEdit;
QPointer<QPushButton> m_saveButton;
QPointer<QLabel> m_label;
PdmUiTextEditorAttribute::TextMode m_textMode;
};