mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-18 05:11:41 +00:00
Implemented const_string_array editor.
This commit is contained in:
parent
a4ccf0b86c
commit
77b98d796c
8 changed files with 800 additions and 19 deletions
|
@ -20,12 +20,15 @@ SET(OVQT_PLUGIN_WORLD_EDITOR_HDR world_editor_plugin.h
|
||||||
project_settings_dialog.h
|
project_settings_dialog.h
|
||||||
property_editor_widget.h
|
property_editor_widget.h
|
||||||
world_editor_settings_page.h
|
world_editor_settings_page.h
|
||||||
|
const_string_array_property.h
|
||||||
|
const_string_array_editor.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(OVQT_PLUGIN_WORLD_EDITOR_UIS world_editor_window.ui
|
SET(OVQT_PLUGIN_WORLD_EDITOR_UIS world_editor_window.ui
|
||||||
project_settings_dialog.ui
|
project_settings_dialog.ui
|
||||||
property_editor_widget.ui
|
property_editor_widget.ui
|
||||||
world_editor_settings_page.ui
|
world_editor_settings_page.ui
|
||||||
|
const_string_array_editor.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(OVQT_PLUGIN_WORLD_EDITOR_RCS world_editor.qrc)
|
SET(OVQT_PLUGIN_WORLD_EDITOR_RCS world_editor.qrc)
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
// Ryzom Core Studio World Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#include "const_string_array_editor.h"
|
||||||
|
|
||||||
|
ConstStrArrEditDialog::ConstStrArrEditDialog( QDialog *parent ) :
|
||||||
|
QDialog( parent )
|
||||||
|
{
|
||||||
|
setupUi( this );
|
||||||
|
setupConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstStrArrEditDialog::~ConstStrArrEditDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::setStrings( const QStringList &strings )
|
||||||
|
{
|
||||||
|
cb->clear();
|
||||||
|
|
||||||
|
QStringListIterator itr( strings );
|
||||||
|
while( itr.hasNext() )
|
||||||
|
{
|
||||||
|
cb->addItem( itr.next() );
|
||||||
|
}
|
||||||
|
|
||||||
|
cb->setCurrentIndex( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::setValue( const QString &value )
|
||||||
|
{
|
||||||
|
listWidget->clear();
|
||||||
|
|
||||||
|
if( value.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStringList l = value.split( ';' );
|
||||||
|
|
||||||
|
QStringListIterator itr( l );
|
||||||
|
while( itr.hasNext() )
|
||||||
|
{
|
||||||
|
listWidget->addItem( itr.next() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConstStrArrEditDialog::getValue() const
|
||||||
|
{
|
||||||
|
QString value;
|
||||||
|
|
||||||
|
for( int i = 0; i < listWidget->count(); i++ )
|
||||||
|
{
|
||||||
|
QListWidgetItem *item = listWidget->item( i );
|
||||||
|
value += item->text();
|
||||||
|
|
||||||
|
if( i < ( listWidget->count() - 1 ) )
|
||||||
|
value += ';';
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::accept()
|
||||||
|
{
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::reject()
|
||||||
|
{
|
||||||
|
QDialog::reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::onAddClicked()
|
||||||
|
{
|
||||||
|
listWidget->addItem( cb->currentText() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::onRemoveClicked()
|
||||||
|
{
|
||||||
|
QListWidgetItem *item = listWidget->currentItem();
|
||||||
|
if( item == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditDialog::setupConnections()
|
||||||
|
{
|
||||||
|
connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
|
||||||
|
connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
// Ryzom Core Studio World Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CONST_STR_ARR_EDIT_DLG
|
||||||
|
#define CONST_STR_ARR_EDIT_DLG
|
||||||
|
|
||||||
|
#include "ui_const_string_array_editor.h"
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class ConstStrArrEditDialog : public QDialog, public Ui::ConstStrArrEditorDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ConstStrArrEditDialog( QDialog *parent = NULL );
|
||||||
|
~ConstStrArrEditDialog();
|
||||||
|
|
||||||
|
void setStrings( const QStringList &strings );
|
||||||
|
void setValue( const QString &value );
|
||||||
|
QString getValue() const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void accept();
|
||||||
|
void reject();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onAddClicked();
|
||||||
|
void onRemoveClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupConnections();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,130 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ConstStrArrEditorDialog</class>
|
||||||
|
<widget class="QDialog" name="ConstStrArrEditorDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>392</width>
|
||||||
|
<height>293</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QComboBox" name="cb">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="addButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QPushButton" name="removeButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="3">
|
||||||
|
<widget class="QListWidget" name="listWidget"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" colspan="3">
|
||||||
|
<layout class="QHBoxLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
<property name="margin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>131</width>
|
||||||
|
<height>31</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="okButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>OK</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="cancelButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>okButton</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>ConstStrArrEditorDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>278</x>
|
||||||
|
<y>253</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>96</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>cancelButton</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>ConstStrArrEditorDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>369</x>
|
||||||
|
<y>253</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>179</x>
|
||||||
|
<y>282</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -0,0 +1,363 @@
|
||||||
|
// Ryzom Core Studio World Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#include "const_string_array_property.h"
|
||||||
|
#include "const_string_array_editor.h"
|
||||||
|
#include <QMap>
|
||||||
|
#include <QList>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
struct ConstStrArrPropMgrPriv
|
||||||
|
{
|
||||||
|
QMap< const QtProperty*, QString > values;
|
||||||
|
};
|
||||||
|
|
||||||
|
ConstStrArrPropMgr::ConstStrArrPropMgr( QObject *parent ) :
|
||||||
|
QtAbstractPropertyManager( parent )
|
||||||
|
{
|
||||||
|
d_ptr = new ConstStrArrPropMgrPriv();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstStrArrPropMgr::~ConstStrArrPropMgr()
|
||||||
|
{
|
||||||
|
delete d_ptr;
|
||||||
|
d_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConstStrArrPropMgr::value( const QtProperty *p ) const
|
||||||
|
{
|
||||||
|
return valueText( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrPropMgr::setValue( QtProperty *p, const QString &value )
|
||||||
|
{
|
||||||
|
if( !d_ptr->values.contains( p ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( d_ptr->values[ p ] == value )
|
||||||
|
return;
|
||||||
|
|
||||||
|
d_ptr->values[ p ] = value;
|
||||||
|
|
||||||
|
Q_EMIT propertyChanged( p );
|
||||||
|
Q_EMIT valueChanged( p, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrPropMgr::setStrings( QtProperty *p, const QStringList &strings )
|
||||||
|
{
|
||||||
|
Q_EMIT stringsChanged( p, strings );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConstStrArrPropMgr::hasValue( const QtProperty *p ) const
|
||||||
|
{
|
||||||
|
return d_ptr->values.contains( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ConstStrArrPropMgr::valueText( const QtProperty *p ) const
|
||||||
|
{
|
||||||
|
if( !d_ptr->values.contains( p ) )
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return d_ptr->values[ p ];
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrPropMgr::initializeProperty( QtProperty *p )
|
||||||
|
{
|
||||||
|
if( d_ptr->values.contains( p ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
d_ptr->values[ p ] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrPropMgr::uninitializeProperty( QtProperty *p )
|
||||||
|
{
|
||||||
|
d_ptr->values.remove( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ConstStrArrEditorFactoryPriv
|
||||||
|
{
|
||||||
|
QMap< QtProperty*, QList< ConstStrArrEditor* > > createdEditors;
|
||||||
|
QMap< ConstStrArrEditor*, QtProperty* > editorToProperty;
|
||||||
|
QMap< QtProperty*, QStringList > strings;
|
||||||
|
|
||||||
|
~ConstStrArrEditorFactoryPriv()
|
||||||
|
{
|
||||||
|
createdEditors.clear();
|
||||||
|
|
||||||
|
QMap< ConstStrArrEditor*, QtProperty* >::iterator itr = editorToProperty.begin();
|
||||||
|
while( itr != editorToProperty.end() )
|
||||||
|
{
|
||||||
|
delete itr.key();
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
editorToProperty.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addEditor( QtProperty *p, ConstStrArrEditor *editor )
|
||||||
|
{
|
||||||
|
QMap< QtProperty*, QList< ConstStrArrEditor* > >::iterator itr = createdEditors.find( p );
|
||||||
|
|
||||||
|
if( itr != createdEditors.end() )
|
||||||
|
{
|
||||||
|
itr->push_back( editor );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QList< ConstStrArrEditor* > l;
|
||||||
|
l.push_back( editor );
|
||||||
|
createdEditors.insert( p, l );
|
||||||
|
}
|
||||||
|
|
||||||
|
editorToProperty.insert( editor, p );
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeEditor( QObject *o )
|
||||||
|
{
|
||||||
|
// Remove from editorToProperty first
|
||||||
|
QMap< ConstStrArrEditor*, QtProperty* >::iterator itr1 = editorToProperty.begin();
|
||||||
|
while( itr1 != editorToProperty.end() )
|
||||||
|
{
|
||||||
|
if( itr1.key() == o )
|
||||||
|
break;
|
||||||
|
|
||||||
|
++itr1;
|
||||||
|
}
|
||||||
|
if( itr1 != editorToProperty.end() )
|
||||||
|
editorToProperty.erase( itr1 );
|
||||||
|
|
||||||
|
// Then from createdEditors
|
||||||
|
QMap< QtProperty*, QList< ConstStrArrEditor* > >::iterator itr2 = createdEditors.begin();
|
||||||
|
while( itr2 != createdEditors.end() )
|
||||||
|
{
|
||||||
|
QList< ConstStrArrEditor* > &l = *itr2;
|
||||||
|
QList< ConstStrArrEditor* >::iterator itr = l.begin();
|
||||||
|
while( itr != l.end() )
|
||||||
|
{
|
||||||
|
if( *itr == o )
|
||||||
|
{
|
||||||
|
QList< ConstStrArrEditor* >::iterator d = itr;
|
||||||
|
++itr;
|
||||||
|
l.erase( d );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
++itr2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
ConstStrArrEditorFactory::ConstStrArrEditorFactory( QObject *parent ) :
|
||||||
|
QtAbstractEditorFactory( parent )
|
||||||
|
{
|
||||||
|
d_ptr = new ConstStrArrEditorFactoryPriv();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstStrArrEditorFactory::~ConstStrArrEditorFactory()
|
||||||
|
{
|
||||||
|
delete d_ptr;
|
||||||
|
d_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditorFactory::connectPropertyManager( ConstStrArrPropMgr *manager )
|
||||||
|
{
|
||||||
|
connect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
|
||||||
|
connect( manager, SIGNAL( stringsChanged( QtProperty*, const QStringList& ) ), this, SLOT( onStringsChanged( QtProperty*, const QStringList & ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditorFactory::disconnectPropertyManager( ConstStrArrPropMgr *manager )
|
||||||
|
{
|
||||||
|
disconnect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
|
||||||
|
disconnect( manager, SIGNAL( stringsChanged( const QStringList& ) ), this, SLOT( onStringsChanged( const QStringList & ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* ConstStrArrEditorFactory::createEditor( ConstStrArrPropMgr *manager, QtProperty *p, QWidget *parent )
|
||||||
|
{
|
||||||
|
ConstStrArrEditor *editor = new ConstStrArrEditor( parent );
|
||||||
|
editor->setValue( manager->value( p ) );
|
||||||
|
|
||||||
|
QMap< QtProperty*, QStringList >::iterator itr = d_ptr->strings.find( p );
|
||||||
|
if( itr != d_ptr->strings.end() )
|
||||||
|
{
|
||||||
|
editor->setStrings( *itr );
|
||||||
|
}
|
||||||
|
|
||||||
|
connect( editor, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onSetValue( const QString& ) ) );
|
||||||
|
connect( editor, SIGNAL( destroyed( QObject* ) ), this, SLOT( onEditorDestroyed( QObject* ) ) );
|
||||||
|
|
||||||
|
d_ptr->addEditor( p, editor );
|
||||||
|
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditorFactory::onPropertyChanged( QtProperty *p, const QString &value )
|
||||||
|
{
|
||||||
|
QMap< QtProperty*, QList< ConstStrArrEditor* > >::iterator itr = d_ptr->createdEditors.find( p );
|
||||||
|
if( itr == d_ptr->createdEditors.end() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList< ConstStrArrEditor* > &l = *itr;
|
||||||
|
QList< ConstStrArrEditor* >::iterator i = l.begin();
|
||||||
|
while( i != l.end() )
|
||||||
|
{
|
||||||
|
ConstStrArrEditor *editor = *i;
|
||||||
|
|
||||||
|
editor->blockSignals( true );
|
||||||
|
editor->setValue( value );
|
||||||
|
editor->blockSignals( false );
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditorFactory::onStringsChanged( QtProperty *p, const QStringList &strings )
|
||||||
|
{
|
||||||
|
if( p == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
d_ptr->strings[ p ] = strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditorFactory::onSetValue( const QString &value )
|
||||||
|
{
|
||||||
|
QObject *s = sender();
|
||||||
|
ConstStrArrEditor *editor = qobject_cast< ConstStrArrEditor* >( s );
|
||||||
|
if( editor == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMap< ConstStrArrEditor*, QtProperty* >::iterator itr = d_ptr->editorToProperty.find( editor );
|
||||||
|
if( itr == d_ptr->editorToProperty.end() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QtProperty *p = *itr;
|
||||||
|
|
||||||
|
ConstStrArrPropMgr *manager = qobject_cast< ConstStrArrPropMgr* >( p->propertyManager() );
|
||||||
|
if( manager == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
blockSignals( true );
|
||||||
|
manager->setValue( p, value );
|
||||||
|
blockSignals( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditorFactory::onEditorDestroyed( QObject *editor )
|
||||||
|
{
|
||||||
|
d_ptr->removeEditor( editor );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////// Editor //////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ConstStrArrEditor::ConstStrArrEditor( QWidget *parent ) :
|
||||||
|
QWidget( parent )
|
||||||
|
{
|
||||||
|
setupUi();
|
||||||
|
setupConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstStrArrEditor::~ConstStrArrEditor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::setStrings( const QStringList &strings )
|
||||||
|
{
|
||||||
|
this->strings.clear();
|
||||||
|
|
||||||
|
QStringListIterator itr( strings );
|
||||||
|
while( itr.hasNext() )
|
||||||
|
{
|
||||||
|
this->strings.push_back( itr.next() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::setValue( const QString &value )
|
||||||
|
{
|
||||||
|
if( lineEdit->text() == value )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disableConnections();
|
||||||
|
lineEdit->setText( value );
|
||||||
|
setupConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::showEvent( QShowEvent *e )
|
||||||
|
{
|
||||||
|
QWidget::showEvent( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::onToolButtonClicked()
|
||||||
|
{
|
||||||
|
ConstStrArrEditDialog d;
|
||||||
|
d.setStrings( strings );
|
||||||
|
d.setValue( lineEdit->text() );
|
||||||
|
int result = d.exec();
|
||||||
|
if( QDialog::Accepted != result )
|
||||||
|
return;
|
||||||
|
lineEdit->setText( d.getValue() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::onTextChanged( const QString &text )
|
||||||
|
{
|
||||||
|
Q_EMIT valueChanged( text );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::setupConnections()
|
||||||
|
{
|
||||||
|
connect( toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onToolButtonClicked() ) );
|
||||||
|
connect( lineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::disableConnections()
|
||||||
|
{
|
||||||
|
disconnect( toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onToolButtonClicked() ) );
|
||||||
|
disconnect( lineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConstStrArrEditor::setupUi()
|
||||||
|
{
|
||||||
|
lineEdit = new QLineEdit();
|
||||||
|
toolButton = new QToolButton();
|
||||||
|
toolButton->setText( "..." );
|
||||||
|
|
||||||
|
QHBoxLayout *lt = new QHBoxLayout( this );
|
||||||
|
lt->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
lt->setSpacing( 0 );
|
||||||
|
lt->addWidget( lineEdit );
|
||||||
|
lt->addWidget( toolButton );
|
||||||
|
|
||||||
|
setFocusProxy( lineEdit );
|
||||||
|
setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
// Ryzom Core Studio World Editor plugin <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CONST_STR_ARR_PROP_H
|
||||||
|
#define CONST_STR_ARR_PROP_H
|
||||||
|
|
||||||
|
#define QT_QTPROPERTYBROWSER_IMPORT
|
||||||
|
|
||||||
|
#include "3rdparty/qtpropertybrowser/qtpropertybrowser.h"
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct ConstStrArrPropMgrPriv;
|
||||||
|
|
||||||
|
class ConstStrArrPropMgr : public QtAbstractPropertyManager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ConstStrArrPropMgr( QObject *parent = NULL );
|
||||||
|
~ConstStrArrPropMgr();
|
||||||
|
|
||||||
|
QString value( const QtProperty *p ) const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setValue( QtProperty *p, const QString &value );
|
||||||
|
void setStrings( QtProperty *p, const QStringList &strings );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged( QtProperty *p, const QString &value );
|
||||||
|
void stringsChanged( QtProperty *p, const QStringList &strings );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool hasValue( const QtProperty *p ) const;
|
||||||
|
QString valueText( const QtProperty *p ) const;
|
||||||
|
void initializeProperty( QtProperty *p );
|
||||||
|
void uninitializeProperty( QtProperty *p );
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConstStrArrPropMgrPriv *d_ptr;
|
||||||
|
|
||||||
|
Q_DISABLE_COPY( ConstStrArrPropMgr );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////// Factory /////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct ConstStrArrEditorFactoryPriv;
|
||||||
|
|
||||||
|
class ConstStrArrEditorFactory : public QtAbstractEditorFactory< ConstStrArrPropMgr >
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ConstStrArrEditorFactory( QObject *parent = NULL );
|
||||||
|
~ConstStrArrEditorFactory();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void connectPropertyManager( ConstStrArrPropMgr *manager );
|
||||||
|
void disconnectPropertyManager( ConstStrArrPropMgr *manager );
|
||||||
|
|
||||||
|
QWidget* createEditor( ConstStrArrPropMgr *manager, QtProperty *p, QWidget *parent );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onPropertyChanged( QtProperty *p, const QString &value );
|
||||||
|
void onStringsChanged( QtProperty *p, const QStringList &strings );
|
||||||
|
void onSetValue( const QString &value );
|
||||||
|
void onEditorDestroyed( QObject *editor );
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConstStrArrEditorFactoryPriv *d_ptr;
|
||||||
|
|
||||||
|
Q_DISABLE_COPY( ConstStrArrEditorFactory );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////// Editor ///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
class QToolButton;
|
||||||
|
|
||||||
|
class ConstStrArrEditor : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ConstStrArrEditor( QWidget *parent = NULL );
|
||||||
|
~ConstStrArrEditor();
|
||||||
|
void setStrings( const QStringList &strings );
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setValue( const QString &value );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent( QShowEvent *e );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onToolButtonClicked();
|
||||||
|
void onTextChanged( const QString &text );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged( const QString &value );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupUi();
|
||||||
|
void setupConnections();
|
||||||
|
void disableConnections();
|
||||||
|
|
||||||
|
|
||||||
|
QLineEdit *lineEdit;
|
||||||
|
QToolButton *toolButton;
|
||||||
|
QStringList strings;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtCore/QModelIndex>
|
#include <QtCore/QModelIndex>
|
||||||
|
|
||||||
|
#include "const_string_array_property.h"
|
||||||
|
|
||||||
namespace WorldEditor
|
namespace WorldEditor
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -42,6 +44,9 @@ PropertyEditorWidget::PropertyEditorWidget(QWidget *parent)
|
||||||
m_enumManager = new QtEnumPropertyManager(this);
|
m_enumManager = new QtEnumPropertyManager(this);
|
||||||
m_stringArrayManager = new QtTextPropertyManager(this);
|
m_stringArrayManager = new QtTextPropertyManager(this);
|
||||||
|
|
||||||
|
m_constStrArrPropMgr = new ConstStrArrPropMgr(this);
|
||||||
|
m_constStrArrEditorFactory = new ConstStrArrEditorFactory(this);
|
||||||
|
|
||||||
QtLineEditFactory *lineEditFactory = new QtLineEditFactory(this);
|
QtLineEditFactory *lineEditFactory = new QtLineEditFactory(this);
|
||||||
QtCheckBoxFactory *boolFactory = new QtCheckBoxFactory(this);
|
QtCheckBoxFactory *boolFactory = new QtCheckBoxFactory(this);
|
||||||
QtEnumEditorFactory *enumFactory = new QtEnumEditorFactory(this);
|
QtEnumEditorFactory *enumFactory = new QtEnumEditorFactory(this);
|
||||||
|
@ -51,6 +56,7 @@ PropertyEditorWidget::PropertyEditorWidget(QWidget *parent)
|
||||||
m_ui.treePropertyBrowser->setFactoryForManager(m_boolManager, boolFactory);
|
m_ui.treePropertyBrowser->setFactoryForManager(m_boolManager, boolFactory);
|
||||||
m_ui.treePropertyBrowser->setFactoryForManager(m_enumManager, enumFactory);
|
m_ui.treePropertyBrowser->setFactoryForManager(m_enumManager, enumFactory);
|
||||||
m_ui.treePropertyBrowser->setFactoryForManager(m_stringArrayManager, textFactory);
|
m_ui.treePropertyBrowser->setFactoryForManager(m_stringArrayManager, textFactory);
|
||||||
|
m_ui.treePropertyBrowser->setFactoryForManager(m_constStrArrPropMgr, m_constStrArrEditorFactory);
|
||||||
|
|
||||||
m_groupManager = new QtGroupPropertyManager(this);
|
m_groupManager = new QtGroupPropertyManager(this);
|
||||||
|
|
||||||
|
@ -58,6 +64,7 @@ PropertyEditorWidget::PropertyEditorWidget(QWidget *parent)
|
||||||
connect(m_boolManager, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
connect(m_boolManager, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
||||||
connect(m_enumManager, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
connect(m_enumManager, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
||||||
connect(m_stringArrayManager, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
connect(m_stringArrayManager, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
||||||
|
connect(m_constStrArrPropMgr, SIGNAL(propertyChanged(QtProperty *)), this, SLOT(propertyChanged(QtProperty *)));
|
||||||
|
|
||||||
connect(m_boolManager, SIGNAL(resetProperty(QtProperty *)), this, SLOT(resetProperty(QtProperty *)));
|
connect(m_boolManager, SIGNAL(resetProperty(QtProperty *)), this, SLOT(resetProperty(QtProperty *)));
|
||||||
connect(m_stringManager, SIGNAL(resetProperty(QtProperty *)), this, SLOT(resetProperty(QtProperty *)));
|
connect(m_stringManager, SIGNAL(resetProperty(QtProperty *)), this, SLOT(resetProperty(QtProperty *)));
|
||||||
|
@ -326,32 +333,18 @@ QtProperty *PropertyEditorWidget::addConstStringArrayProperty(const NLLIGO::IPro
|
||||||
primitive->getPropertyByName(name.c_str(), value);
|
primitive->getPropertyByName(name.c_str(), value);
|
||||||
|
|
||||||
// Create qt property
|
// Create qt property
|
||||||
// QtProperty *prop = m_enumManager->addProperty(parameter.Name.c_str());
|
QtProperty *prop = m_constStrArrPropMgr->addProperty(parameter.Name.c_str());
|
||||||
QtProperty *prop = m_stringArrayManager->addProperty(parameter.Name.c_str());
|
|
||||||
|
|
||||||
QStringList listEnums = getComboValues(parameter);
|
QStringList listEnums = getComboValues(parameter);
|
||||||
|
|
||||||
if (listEnums.isEmpty())
|
if (listEnums.isEmpty())
|
||||||
{
|
{
|
||||||
// listEnums << QString(value.c_str()) + tr(" (WRN: Check leveldesign!)");
|
|
||||||
// m_enumManager->setEnumNames(prop, listEnums);
|
|
||||||
// m_enumManager->setValue(prop, 0);
|
|
||||||
prop->setEnabled(false);
|
prop->setEnabled(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Fill qt property
|
// Fill qt property
|
||||||
m_enumManager->setEnumNames(prop, listEnums);
|
m_constStrArrPropMgr->setStrings(prop, listEnums);
|
||||||
|
|
||||||
// Find index of current value
|
|
||||||
//for (int i = 0; i < listEnums.size(); i++)
|
|
||||||
//{
|
|
||||||
// if (value == std::string(listEnums[i].toUtf8().constData()))
|
|
||||||
// {
|
|
||||||
// m_enumManager->setValue(prop, i);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
const NLLIGO::IProperty *ligoProperty;
|
const NLLIGO::IProperty *ligoProperty;
|
||||||
std::vector<std::string> vectString;
|
std::vector<std::string> vectString;
|
||||||
|
@ -371,17 +364,16 @@ QtProperty *PropertyEditorWidget::addConstStringArrayProperty(const NLLIGO::IPro
|
||||||
if (i != (vectString.size() - 1))
|
if (i != (vectString.size() - 1))
|
||||||
temp += '\n';
|
temp += '\n';
|
||||||
}
|
}
|
||||||
m_stringArrayManager->setValue(prop, temp.c_str());
|
m_constStrArrPropMgr->setValue(prop, temp.c_str());
|
||||||
prop->setToolTip(temp.c_str());
|
prop->setToolTip(temp.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_stringArrayManager->setValue(prop, "StringArray :(");
|
m_constStrArrPropMgr->setValue(prop, "StringArray :(");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_enumManager->setValue(prop, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return prop;
|
return prop;
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
|
|
||||||
|
class ConstStrArrPropMgr;
|
||||||
|
class ConstStrArrEditorFactory;
|
||||||
|
|
||||||
namespace WorldEditor
|
namespace WorldEditor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -84,6 +87,9 @@ private:
|
||||||
QtGroupPropertyManager *m_groupManager;
|
QtGroupPropertyManager *m_groupManager;
|
||||||
QtTextPropertyManager *m_stringArrayManager;
|
QtTextPropertyManager *m_stringArrayManager;
|
||||||
|
|
||||||
|
ConstStrArrPropMgr *m_constStrArrPropMgr;
|
||||||
|
ConstStrArrEditorFactory *m_constStrArrEditorFactory;
|
||||||
|
|
||||||
Ui::PropertyEditorWidget m_ui;
|
Ui::PropertyEditorWidget m_ui;
|
||||||
}; /* PropertyEditorWidget */
|
}; /* PropertyEditorWidget */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue