Commit 89c06ada authored by Timothee Chabat's avatar Timothee Chabat
Browse files

TextureSelector: add option for disabling 'Load' entry

Allow plugins and PV based application to easily define a texture drop down list
programmatically.
parent 61c68073
......@@ -49,15 +49,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QFileInfo>
//-----------------------------------------------------------------------------
pqTextureComboBox::pqTextureComboBox(vtkSMProxyGroupDomain* domain, QWidget* parent)
pqTextureComboBox::pqTextureComboBox(vtkSMProxyGroupDomain* domain, bool canLoad, QWidget* parent)
: Superclass(parent)
, Domain(domain)
, GroupName("")
, CanLoad(canLoad)
{
if (!this->Domain || this->Domain->GetNumberOfGroups() != 1)
{
qCritical() << "pqTextureSelectorPropertyWidget can only be used with a ProxyProperty"
" with a ProxyGroupDomain containing a single domain with a name.";
return;
}
else
{
......@@ -77,6 +79,12 @@ pqTextureComboBox::pqTextureComboBox(vtkSMProxyGroupDomain* domain, QWidget* par
this, SLOT(proxyUnRegistered(const QString&, const QString&, vtkSMProxy*)));
}
//-----------------------------------------------------------------------------
pqTextureComboBox::pqTextureComboBox(vtkSMProxyGroupDomain* domain, QWidget* parent)
: pqTextureComboBox(domain, true, parent)
{
}
//-----------------------------------------------------------------------------
void pqTextureComboBox::updateFromTexture(vtkSMProxy* texture)
{
......@@ -116,7 +124,10 @@ void pqTextureComboBox::updateTextures()
this->clear();
this->addItem("None", QVariant("NONE"));
this->addItem("Load ...", QVariant("LOAD"));
if (this->CanLoad)
{
this->addItem("Load ...", QVariant("LOAD"));
}
for (unsigned int i = 0; i < this->Domain->GetNumberOfProxies(); i++)
{
......@@ -131,18 +142,18 @@ void pqTextureComboBox::updateTextures()
//-----------------------------------------------------------------------------
void pqTextureComboBox::onCurrentIndexChanged(int index)
{
switch (index)
if (index == 0)
{
Q_EMIT textureChanged(nullptr);
}
else if (index == 1 && this->CanLoad)
{
this->loadTexture();
}
else
{
case 0:
Q_EMIT textureChanged(nullptr);
break;
case 1:
this->loadTexture();
break;
default:
vtkSMProxy* texture = reinterpret_cast<vtkSMProxy*>(this->currentData().value<void*>());
Q_EMIT textureChanged(texture);
break;
vtkSMProxy* texture = reinterpret_cast<vtkSMProxy*>(this->currentData().value<void*>());
Q_EMIT textureChanged(texture);
}
}
......
......@@ -51,6 +51,7 @@ class PQCOMPONENTS_EXPORT pqTextureComboBox : public QComboBox
typedef QComboBox Superclass;
public:
pqTextureComboBox(vtkSMProxyGroupDomain* domain, bool canLoad, QWidget* parent = nullptr);
pqTextureComboBox(vtkSMProxyGroupDomain* domain, QWidget* parent = nullptr);
~pqTextureComboBox() override = default;
......@@ -83,6 +84,7 @@ private:
vtkSMProxyGroupDomain* Domain;
vtkNew<vtkEventQtSlotConnect> VTKConnector;
QString GroupName;
bool CanLoad;
};
#endif
......@@ -63,7 +63,18 @@ pqTextureSelectorPropertyWidget::pqTextureSelectorPropertyWidget(
// Create the combobox selector and set its value
auto* domain = smProperty->FindDomain<vtkSMProxyGroupDomain>();
this->Selector = new pqTextureComboBox(domain, this);
bool canLoad = true;
if (auto* hints = smProperty->GetHints())
{
auto* texHint = hints->FindNestedElementByName("TextureSelector");
QString attr = texHint ? texHint->GetAttributeOrEmpty("can_load_new") : "";
if (!attr.isEmpty())
{
canLoad = static_cast<bool>(attr.toInt());
}
}
this->Selector = new pqTextureComboBox(domain, canLoad, this);
this->onPropertyChanged();
l->addWidget(this->Selector);
this->setLayout(l);
......
......@@ -308,3 +308,26 @@ The snippet below shows these hints in use.
<HideResetButton/>
</Hints>
</DoubleVectorProperty>
TextureSelectorPropertyWidget
-------------------------------
Customize the `pqTextureSelectorPropertyWidget` with the `TextureSelector` hint using the following attribute:
* `can_load_new` - if 0 then user will not be able to load new texture from the drop down. Default to 1.
The snippet below shows these hints in use.
```xml
<ProxyProperty command="SetTexture"
name="Texture"
panel_widget="texture_selector"
null_on_empty="1" >
<ProxyGroupDomain name="groups">
<Group name="textures" />
</ProxyGroupDomain>
<Hints>
<TextureSelector can_load_new="0" />
</Hints>
</ProxyProperty>
```
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