[+] configuring enum and flags parameters via element properties widget (issue #2: Enum not supported)

This commit is contained in:
Victor Anjin 2015-06-06 23:00:16 +07:00
parent ae8cf31935
commit 8a1759c547
3 changed files with 320 additions and 158 deletions

View file

@ -1,13 +1,13 @@
#include "ElementProperties.h"
#include <QDebug>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QString>
#include <QLabel>
#include <QScrollArea>
#include <QPushButton>
#include <QComboBox>
#include <gst/gst.h>
@ -23,26 +23,8 @@ m_name(name)
}
void ElementProperties::create()
void ElementProperties::addParamEnum(GParamSpec *param, GstElement *element, QGridLayout *play)
{
GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraphManager -> m_pGraph), m_name.toStdString().c_str());
if(!element)
return;
QGridLayout *play = new QGridLayout;
GParamSpec **prop_specs;
guint num_props;
prop_specs = g_object_class_list_properties(G_OBJECT_GET_CLASS (element),
&num_props);
for(std::size_t i = 0; i<num_props; i++)
{
bool readOnly = true;
GParamSpec *param = prop_specs[i];
GValue value = { 0 };
g_value_init (&value, param -> value_type);
@ -54,9 +36,109 @@ void ElementProperties::create()
g_value_copy(valueDef, &value);
}
QString propertyName = g_param_spec_get_name (param);
int propertyValue;
propertyValue = g_value_get_enum(&value);
GParamSpecEnum *penumSpec = G_PARAM_SPEC_ENUM(param);
if(!penumSpec)
return;
QComboBox *pcomBox = new QComboBox;
for(std::size_t i=0; i<penumSpec -> enum_class -> n_values; i++)
{
QVariant var(penumSpec -> enum_class -> values[i].value);
QString valueName = penumSpec -> enum_class -> values[i].value_name;
pcomBox -> addItem(valueName, var);
if(penumSpec -> enum_class -> values[i].value == propertyValue)
pcomBox -> setCurrentIndex(i);
}
int row = play -> rowCount();
play -> addWidget(new QLabel(propertyName), row, 0);
play -> addWidget(pcomBox, row, 1);
m_values.insert(propertyName, pcomBox);
}
void ElementProperties::addParamFlags(GParamSpec *param, GstElement *element, QGridLayout *play)
{
GValue value = { 0 };
g_value_init (&value, param -> value_type);
if(param -> flags & G_PARAM_READABLE)
g_object_get_property (G_OBJECT(element), param -> name, &value);
else
{
const GValue *valueDef = g_param_spec_get_default_value(param);
g_value_copy(valueDef, &value);
}
QString propertyName = g_param_spec_get_name (param);
int propertyValue;
propertyValue = g_value_get_flags(&value);
GParamSpecFlags *pflagsSpec = G_PARAM_SPEC_FLAGS(param);
if(!pflagsSpec)
return;
QComboBox *pcomBox = new QComboBox;
for(std::size_t i=0; i<pflagsSpec -> flags_class -> n_values; i++)
{
QVariant var(pflagsSpec -> flags_class -> values[i].value);
QString valueName = pflagsSpec -> flags_class -> values[i].value_name;
pcomBox -> addItem(valueName, var);
if(pflagsSpec -> flags_class -> values[i].value == propertyValue)
pcomBox -> setCurrentIndex(i);
}
int row = play -> rowCount();
play -> addWidget(new QLabel(propertyName), row, 0);
play -> addWidget(pcomBox, row, 1);
m_values.insert(propertyName, pcomBox);
}
void ElementProperties::addParamSimple(GParamSpec *param, GstElement *element, QGridLayout *play)
{
bool readOnly = true;
if(param->flags & G_PARAM_WRITABLE)
readOnly = false;
GValue value = { 0 };
g_value_init (&value, param -> value_type);
if(param -> flags & G_PARAM_READABLE)
g_object_get_property (G_OBJECT(element), param -> name, &value);
else
{
const GValue *valueDef = g_param_spec_get_default_value(param);
g_value_copy(valueDef, &value);
}
QString propertyName = g_param_spec_get_name (param);
QString propertyValue;
@ -116,6 +198,17 @@ void ElementProperties::create()
propertyValue = QString::number(g_value_get_double(&value));
break;
}
case G_TYPE_CHAR:
{
propertyValue = QString::number(g_value_get_char(&value));
break;
}
case G_TYPE_UCHAR:
{
propertyValue = QString::number(g_value_get_uchar(&value));
break;
}
default:
{
skip = true;
@ -124,15 +217,45 @@ void ElementProperties::create()
}
};
play -> addWidget(new QLabel(propertyName), i, 0);
int row = play -> rowCount();
play -> addWidget(new QLabel(propertyName), row, 0);
QLineEdit *ple = new QLineEdit(propertyValue);
ple -> setReadOnly(readOnly);
play -> addWidget(ple, i, 1);
play -> addWidget(ple, row, 1);
if(!skip)
m_values.insert(propertyName, ple);
else
ple -> setReadOnly(true);
}
void ElementProperties::create()
{
GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraphManager -> m_pGraph), m_name.toStdString().c_str());
if(!element)
return;
QGridLayout *play = new QGridLayout;
GParamSpec **prop_specs;
guint num_props;
prop_specs = g_object_class_list_properties(G_OBJECT_GET_CLASS (element),
&num_props);
for(std::size_t i = 0; i<num_props; i++)
{
GParamSpec *param = prop_specs[i];
if(G_IS_PARAM_SPEC_ENUM(param))
addParamEnum(param, element, play);
else if(G_IS_PARAM_SPEC_FLAGS(param))
addParamFlags(param, element, play);
else
addParamSimple(param, element, play);
}
QVBoxLayout *pvblay = new QVBoxLayout;
@ -176,7 +299,7 @@ void ElementProperties::applyClicked()
if(!element)
return;
QMap<QString, QLineEdit *>::iterator itr = m_values.begin();
QMap<QString, QWidget *>::iterator itr = m_values.begin();
for(;itr != m_values.end(); itr++)
{
@ -192,9 +315,31 @@ void ElementProperties::applyClicked()
if(!(param -> flags & G_PARAM_WRITABLE))
continue;
QString valStr = itr.value() -> text();
QString valStr;
if(dynamic_cast<QLineEdit *>(itr.value()))
valStr = ((QLineEdit *) itr.value()) -> text();
else if(dynamic_cast<QComboBox *>(itr.value()))
{
QComboBox *pcomBox = (QComboBox *) itr.value();
int val = pcomBox -> itemData(pcomBox -> currentIndex()).toInt();
valStr = QString::number(val);
}
std::string tmpStr = itr.key().toStdString();
const char *propName = tmpStr.c_str();
if(G_IS_PARAM_SPEC_ENUM(param) || G_IS_PARAM_SPEC_FLAGS(param))
{
if(dynamic_cast<QComboBox *>(itr.value()))
{
QComboBox *pcomBox = (QComboBox *) itr.value();
int val = pcomBox -> itemData(pcomBox -> currentIndex()).toInt();
g_object_set(G_OBJECT(element), propName, val, NULL);
}
}
else
{
switch (param -> value_type)
{
case G_TYPE_STRING:
@ -256,6 +401,18 @@ void ElementProperties::applyClicked()
g_object_set(G_OBJECT(element), propName, val, NULL);
break;
}
case G_TYPE_CHAR:
{
gchar val = valStr.toInt();
g_object_set(G_OBJECT(element), propName, val, NULL);
break;
}
case G_TYPE_UCHAR:
{
guchar val = valStr.toUInt();
g_object_set(G_OBJECT(element), propName, val, NULL);
break;
}
default:
{
qDebug() << "property " << itr.key() << " not supported";
@ -263,6 +420,7 @@ void ElementProperties::applyClicked()
}
};
}
}
gst_object_unref(element);

View file

@ -6,6 +6,7 @@
#include <QMap>
#include <QString>
#include <QLineEdit>
#include <QGridLayout>
#include "GraphManager.h"
@ -23,10 +24,13 @@ private slots:
private:
QSharedPointer<GraphManager> m_pGraphManager;
QMap<QString, QLineEdit *> m_values;
QMap<QString, QWidget *> m_values;
QString m_name;
void create();
void addParamSimple(GParamSpec *value, GstElement *element, QGridLayout *play);
void addParamEnum(GParamSpec *value, GstElement *element, QGridLayout *play);
void addParamFlags(GParamSpec *value, GstElement *element, QGridLayout *play);
};

View file

@ -486,12 +486,12 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
if(res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED || state == GST_STATE_PLAYING)
isActive = true;
bool hasSelection = false;
int selectedCount = 0;
for(std::size_t i=0; i<m_displayInfo.size(); i++)
if(m_displayInfo[i].m_isSelected)
hasSelection = true;
selectedCount++;
if(hasSelection)
if(selectedCount > 1)
{
QAction *pact = menu.addAction("Remove selected");
if(isActive)