Merge
commit
822d255aa7
@ -0,0 +1,271 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 "dfn_browser_ctrl.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qteditorfactory.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qtpropertymanager.h"
|
||||||
|
|
||||||
|
#include "filepath_property_manager.h"
|
||||||
|
|
||||||
|
#include "nel/georges/form_dfn.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
enum EntryEnum
|
||||||
|
{
|
||||||
|
ENTRY_TYPE,
|
||||||
|
ENTRY_DFN,
|
||||||
|
ENTRY_VIRTUAL_DFN,
|
||||||
|
ENTRY_TYPE_ARRAY,
|
||||||
|
ENTRY_DFN_ARRAY
|
||||||
|
};
|
||||||
|
|
||||||
|
QString enumToString( int value )
|
||||||
|
{
|
||||||
|
QString s;
|
||||||
|
|
||||||
|
switch( value )
|
||||||
|
{
|
||||||
|
case ENTRY_TYPE: s = "type"; break;
|
||||||
|
case ENTRY_DFN: s = "dfn"; break;
|
||||||
|
case ENTRY_VIRTUAL_DFN: s = "virtual dfn"; break;
|
||||||
|
case ENTRY_TYPE_ARRAY: s = "type array"; break;
|
||||||
|
case ENTRY_DFN_ARRAY: s = "dfn array"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
NLGEORGES::UFormDfn::TEntryType enumToEntry( int value )
|
||||||
|
{
|
||||||
|
NLGEORGES::UFormDfn::TEntryType entry = NLGEORGES::UFormDfn::EntryType;
|
||||||
|
|
||||||
|
switch( value )
|
||||||
|
{
|
||||||
|
case ENTRY_TYPE: entry = NLGEORGES::UFormDfn::EntryType; break;
|
||||||
|
case ENTRY_DFN: entry = NLGEORGES::UFormDfn::EntryDfn; break;
|
||||||
|
case ENTRY_VIRTUAL_DFN: entry = NLGEORGES::UFormDfn::EntryVirtualDfn; break;
|
||||||
|
case ENTRY_TYPE_ARRAY: entry = NLGEORGES::UFormDfn::EntryType; break;
|
||||||
|
case ENTRY_DFN_ARRAY: entry = NLGEORGES::UFormDfn::EntryDfn; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enumToArray( int value )
|
||||||
|
{
|
||||||
|
bool isArray = false;
|
||||||
|
|
||||||
|
switch( value )
|
||||||
|
{
|
||||||
|
case ENTRY_TYPE_ARRAY:
|
||||||
|
case ENTRY_DFN_ARRAY:
|
||||||
|
isArray = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
int entryToEnum( const NLGEORGES::UFormDfn::TEntryType &type, bool isArray )
|
||||||
|
{
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
|
switch( type )
|
||||||
|
{
|
||||||
|
case NLGEORGES::UFormDfn::EntryType:
|
||||||
|
|
||||||
|
if( isArray )
|
||||||
|
id = ENTRY_TYPE_ARRAY;
|
||||||
|
else
|
||||||
|
id = ENTRY_TYPE;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NLGEORGES::UFormDfn::EntryDfn:
|
||||||
|
if( isArray )
|
||||||
|
id = ENTRY_DFN_ARRAY;
|
||||||
|
else
|
||||||
|
id = ENTRY_DFN;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NLGEORGES::UFormDfn::EntryVirtualDfn:
|
||||||
|
id = ENTRY_VIRTUAL_DFN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DFNBrowserCtrl::DFNBrowserCtrl( QObject *parent ) :
|
||||||
|
QObject( parent )
|
||||||
|
{
|
||||||
|
m_browser = NULL;
|
||||||
|
m_dfn = NULL;
|
||||||
|
m_manager = new QtVariantPropertyManager();
|
||||||
|
m_factory = new QtVariantEditorFactory();
|
||||||
|
m_enumMgr = new QtEnumPropertyManager();
|
||||||
|
m_enumFactory = new QtEnumEditorFactory();
|
||||||
|
m_fileMgr = new FileManager();
|
||||||
|
m_fileFactory = new FileEditFactory();
|
||||||
|
|
||||||
|
m_idx = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFNBrowserCtrl::~DFNBrowserCtrl()
|
||||||
|
{
|
||||||
|
m_browser = NULL;
|
||||||
|
m_dfn = NULL;
|
||||||
|
|
||||||
|
delete m_manager;
|
||||||
|
m_manager = NULL;
|
||||||
|
delete m_factory;
|
||||||
|
m_factory = NULL;
|
||||||
|
delete m_enumMgr;
|
||||||
|
m_enumMgr = NULL;
|
||||||
|
delete m_enumFactory;
|
||||||
|
m_enumFactory = NULL;
|
||||||
|
delete m_fileMgr;
|
||||||
|
m_fileMgr = NULL;
|
||||||
|
delete m_fileFactory;
|
||||||
|
m_fileFactory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DFNBrowserCtrl::onElementSelected( int idx )
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( idx );
|
||||||
|
m_idx = idx;
|
||||||
|
|
||||||
|
disconnectManagers();
|
||||||
|
|
||||||
|
m_browser->clear();
|
||||||
|
m_browser->setFactoryForManager( m_manager, m_factory );
|
||||||
|
m_browser->setFactoryForManager( m_enumMgr, m_enumFactory );
|
||||||
|
m_browser->setFactoryForManager( m_fileMgr, m_fileFactory );
|
||||||
|
|
||||||
|
QtVariantProperty *p = NULL;
|
||||||
|
QtProperty *prop = NULL;
|
||||||
|
|
||||||
|
p = m_manager->addProperty( QVariant::String, "name" );
|
||||||
|
p->setValue( entry.getName().c_str() );
|
||||||
|
m_browser->addProperty( p );
|
||||||
|
|
||||||
|
|
||||||
|
NLGEORGES::UFormDfn::TEntryType et = entry.getType();
|
||||||
|
bool isArray = entry.getArrayFlag();
|
||||||
|
|
||||||
|
QStringList options;
|
||||||
|
options.push_back( "Type" );
|
||||||
|
options.push_back( "DFN" );
|
||||||
|
options.push_back( "Virtual DFN" );
|
||||||
|
options.push_back( "Type Array" );
|
||||||
|
options.push_back( "DFN Array" );
|
||||||
|
|
||||||
|
int enumId = entryToEnum( et, isArray );
|
||||||
|
|
||||||
|
prop = m_enumMgr->addProperty( "type" );
|
||||||
|
m_enumMgr->setEnumNames( prop, options );
|
||||||
|
m_enumMgr->setValue( prop, enumId );
|
||||||
|
m_browser->addProperty( prop );
|
||||||
|
|
||||||
|
|
||||||
|
prop = m_fileMgr->addProperty( "value" );
|
||||||
|
m_fileMgr->setValue( prop, entry.getFilename().c_str() );
|
||||||
|
m_browser->addProperty( prop );
|
||||||
|
|
||||||
|
p = m_manager->addProperty( QVariant::String, "default" );
|
||||||
|
p->setValue( entry.getDefault().c_str() );
|
||||||
|
m_browser->addProperty( p );
|
||||||
|
|
||||||
|
p = m_manager->addProperty( QVariant::String, "extension" );
|
||||||
|
p->setValue( entry.getFilenameExt().c_str() );
|
||||||
|
m_browser->addProperty( p );
|
||||||
|
|
||||||
|
connectManagers();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DFNBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v )
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx );
|
||||||
|
|
||||||
|
QString key = p->propertyName();
|
||||||
|
std::string value = v.toString().toUtf8().constData();
|
||||||
|
|
||||||
|
if( key == "name" )
|
||||||
|
{
|
||||||
|
entry.setName( value.c_str() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( key == "default" )
|
||||||
|
{
|
||||||
|
entry.setDefault( value.c_str() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( key == "extension" )
|
||||||
|
{
|
||||||
|
entry.setFilenameExt( value.c_str() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
Q_EMIT valueChanged( key, v.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DFNBrowserCtrl::onEnumValueChanged( QtProperty *p, int v )
|
||||||
|
{
|
||||||
|
NLGEORGES::UFormDfn::TEntryType tentry = enumToEntry( v );
|
||||||
|
bool isArray = enumToArray( v );
|
||||||
|
|
||||||
|
NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx );
|
||||||
|
entry.setArrayFlag( isArray );
|
||||||
|
entry.setType( tentry );
|
||||||
|
|
||||||
|
QString value = enumToString( v );
|
||||||
|
Q_EMIT valueChanged( p->propertyName(), value );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DFNBrowserCtrl::onFileValueChanged( QtProperty *p, const QString &v )
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormDfn::CEntry &entry = m_dfn->getEntry( m_idx );
|
||||||
|
entry.setFilename( v.toUtf8().constData() );
|
||||||
|
|
||||||
|
Q_EMIT valueChanged( p->propertyName(), v );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DFNBrowserCtrl::connectManagers()
|
||||||
|
{
|
||||||
|
connect( m_manager, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), this, SLOT( onVariantValueChanged( QtProperty*, const QVariant& ) ) );
|
||||||
|
connect( m_enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ), this, SLOT( onEnumValueChanged( QtProperty*, int ) ) );
|
||||||
|
connect( m_fileMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onFileValueChanged( QtProperty*, const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DFNBrowserCtrl::disconnectManagers()
|
||||||
|
{
|
||||||
|
disconnect( m_manager, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), this, SLOT( onVariantValueChanged( QtProperty*, const QVariant& ) ) );
|
||||||
|
disconnect( m_enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ), this, SLOT( onEnumValueChanged( QtProperty*, int ) ) );
|
||||||
|
disconnect( m_fileMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onFileValueChanged( QtProperty*, const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 DFN_BROWSER_CTRL
|
||||||
|
#define DFN_BROWSER_CTRL
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace NLGEORGES
|
||||||
|
{
|
||||||
|
class CFormDfn;
|
||||||
|
}
|
||||||
|
|
||||||
|
class QtVariantPropertyManager;
|
||||||
|
class QtVariantEditorFactory;
|
||||||
|
class QtTreePropertyBrowser;
|
||||||
|
class QVariant;
|
||||||
|
class QtProperty;
|
||||||
|
|
||||||
|
class QtEnumPropertyManager;
|
||||||
|
class QtEnumEditorFactory;
|
||||||
|
class FileManager;
|
||||||
|
class FileEditFactory;
|
||||||
|
|
||||||
|
class DFNBrowserCtrl : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DFNBrowserCtrl( QObject *parent = NULL );
|
||||||
|
~DFNBrowserCtrl();
|
||||||
|
|
||||||
|
void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; }
|
||||||
|
void setDFN( NLGEORGES::CFormDfn *dfn ){ m_dfn = dfn; }
|
||||||
|
|
||||||
|
void onElementSelected( int idx );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged( const QString &key, const QString &value );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onFileValueChanged( QtProperty *p, const QString &v );
|
||||||
|
void onVariantValueChanged( QtProperty *p, const QVariant &v );
|
||||||
|
void onEnumValueChanged( QtProperty *p, int v );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void connectManagers();
|
||||||
|
void disconnectManagers();
|
||||||
|
|
||||||
|
QtTreePropertyBrowser *m_browser;
|
||||||
|
NLGEORGES::CFormDfn *m_dfn;
|
||||||
|
|
||||||
|
QtVariantPropertyManager *m_manager;
|
||||||
|
QtVariantEditorFactory *m_factory;
|
||||||
|
|
||||||
|
QtEnumPropertyManager *m_enumMgr;
|
||||||
|
QtEnumEditorFactory *m_enumFactory;
|
||||||
|
|
||||||
|
FileManager *m_fileMgr;
|
||||||
|
FileEditFactory *m_fileFactory;
|
||||||
|
|
||||||
|
int m_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,320 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 "filepath_property_manager.h"
|
||||||
|
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////// Manager ////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
class FileManagerPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QMap< const QtProperty*, QString > values;
|
||||||
|
};
|
||||||
|
|
||||||
|
FileManager::FileManager( QObject *parent ) :
|
||||||
|
QtAbstractPropertyManager( parent )
|
||||||
|
{
|
||||||
|
m_pvt = new FileManagerPvt();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileManager::~FileManager()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileManager::value( const QtProperty *p ) const
|
||||||
|
{
|
||||||
|
QMap< const QtProperty*, QString >::const_iterator itr = m_pvt->values.find( p );
|
||||||
|
if( itr == m_pvt->values.end() )
|
||||||
|
return "";
|
||||||
|
else
|
||||||
|
return itr.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileManager::setValue( QtProperty *p, const QString &v )
|
||||||
|
{
|
||||||
|
if( !m_pvt->values.contains( p ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( m_pvt->values[ p ] == v )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_pvt->values[ p ] = v;
|
||||||
|
|
||||||
|
Q_EMIT propertyChanged( p );
|
||||||
|
Q_EMIT valueChanged( p, v );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileManager::hasValue( const QtProperty *p ) const
|
||||||
|
{
|
||||||
|
if( m_pvt->values.contains( p ) )
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileManager::valueText( const QtProperty *p ) const
|
||||||
|
{
|
||||||
|
return value( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileManager::initializeProperty( QtProperty *p )
|
||||||
|
{
|
||||||
|
if( m_pvt->values.contains( p ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_pvt->values[ p ] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileManager::uninitializeProperty( QtProperty *p )
|
||||||
|
{
|
||||||
|
m_pvt->values.remove( p );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class FileEditFactoryPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QMap< QtProperty*, QList< FileEdit* > > createdEditors;
|
||||||
|
QMap< FileEdit*, QtProperty* > editorToProperty;
|
||||||
|
|
||||||
|
void addEditor( QtProperty *p, FileEdit *editor )
|
||||||
|
{
|
||||||
|
editorToProperty[ editor ] = p;
|
||||||
|
|
||||||
|
QMap< QtProperty*, QList< FileEdit* > >::iterator itr = createdEditors.find( p );
|
||||||
|
if( itr == createdEditors.end() )
|
||||||
|
{
|
||||||
|
QList< FileEdit* > l;
|
||||||
|
l.push_back( editor );
|
||||||
|
createdEditors[ p ] = l;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QList< FileEdit* > &l = itr.value();
|
||||||
|
l.push_back( editor );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeEditor( QObject *o )
|
||||||
|
{
|
||||||
|
// Find in editorToProperty
|
||||||
|
QMap< FileEdit*, QtProperty* >::iterator itr = editorToProperty.begin();
|
||||||
|
while( itr != editorToProperty.end() )
|
||||||
|
{
|
||||||
|
if( itr.key() == o )
|
||||||
|
break;
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the property, and remove the editor from editorToProperty
|
||||||
|
QtProperty *p = NULL;
|
||||||
|
if( itr != editorToProperty.end() )
|
||||||
|
{
|
||||||
|
p = itr.value();
|
||||||
|
editorToProperty.erase( itr );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the property in createdEditors
|
||||||
|
QMap< QtProperty*, QList< FileEdit* > >::iterator mitr = createdEditors.find( p );
|
||||||
|
QList< FileEdit* > &l = mitr.value();
|
||||||
|
|
||||||
|
// Find the editor in the list
|
||||||
|
QList< FileEdit* >::iterator litr = l.begin();
|
||||||
|
while( litr != l.end() )
|
||||||
|
{
|
||||||
|
if( o == *litr )
|
||||||
|
break;
|
||||||
|
litr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the editor and remove the list too if it's empty
|
||||||
|
if( litr != l.end() )
|
||||||
|
l.erase( litr );
|
||||||
|
|
||||||
|
if( l.isEmpty() )
|
||||||
|
createdEditors.erase( mitr );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FileEditFactory::FileEditFactory( QObject *parent ) :
|
||||||
|
QtAbstractEditorFactory( parent )
|
||||||
|
{
|
||||||
|
m_pvt = new FileEditFactoryPvt();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileEditFactory::~FileEditFactory()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEditFactory::connectPropertyManager( FileManager *manager )
|
||||||
|
{
|
||||||
|
connect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
|
||||||
|
this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEditFactory::disconnectPropertyManager( FileManager *manager )
|
||||||
|
{
|
||||||
|
disconnect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
|
||||||
|
this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* FileEditFactory::createEditor( FileManager *manager, QtProperty *p, QWidget *parent )
|
||||||
|
{
|
||||||
|
FileEdit *editor = new FileEdit( parent );
|
||||||
|
editor->setValue( p->valueText() );
|
||||||
|
|
||||||
|
connect( editor, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onSetValue( const QString& ) ) );
|
||||||
|
connect( editor, SIGNAL( destroyed( QObject* ) ), this, SLOT( onEditorDestroyed( QObject* ) ) );
|
||||||
|
|
||||||
|
m_pvt->addEditor( p, editor );
|
||||||
|
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEditFactory::onPropertyChanged( QtProperty *p, const QString &v )
|
||||||
|
{
|
||||||
|
QMap< QtProperty*, QList< FileEdit* > >::iterator itr = m_pvt->createdEditors.find( p );
|
||||||
|
if( itr == m_pvt->createdEditors.end() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList< FileEdit* > &l = itr.value();
|
||||||
|
QList< FileEdit* >::iterator litr = l.begin();
|
||||||
|
while( litr != l.end() )
|
||||||
|
{
|
||||||
|
FileEdit *editor = *litr;
|
||||||
|
editor->blockSignals( true );
|
||||||
|
editor->setValue( v );
|
||||||
|
editor->blockSignals( false );
|
||||||
|
|
||||||
|
++litr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEditFactory::onSetValue( const QString& v )
|
||||||
|
{
|
||||||
|
QObject *s = sender();
|
||||||
|
FileEdit *editor = qobject_cast< FileEdit* >( s );
|
||||||
|
if( editor == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMap< FileEdit*, QtProperty* >::iterator itr = m_pvt->editorToProperty.find( editor );
|
||||||
|
if( itr == m_pvt->editorToProperty.end() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QtProperty *p = *itr;
|
||||||
|
FileManager *manager = qobject_cast< FileManager* >( p->propertyManager() );
|
||||||
|
if( manager == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
blockSignals( true );
|
||||||
|
manager->setValue( p, v );
|
||||||
|
blockSignals( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEditFactory::onEditorDestroyed( QObject *editor )
|
||||||
|
{
|
||||||
|
m_pvt->removeEditor( editor );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////// Editor /////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
class FileEditPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QLineEdit *lineEdit;
|
||||||
|
QToolButton *toolButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FileEdit::FileEdit( QWidget *parent ) :
|
||||||
|
QWidget( parent )
|
||||||
|
{
|
||||||
|
m_pvt = new FileEditPvt();
|
||||||
|
|
||||||
|
setupUI();
|
||||||
|
setupConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
FileEdit::~FileEdit()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
|
||||||
|
Q_EMIT destroyed( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEdit::setValue( const QString &value )
|
||||||
|
{
|
||||||
|
m_pvt->lineEdit->setText( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEdit::onButtonClicked()
|
||||||
|
{
|
||||||
|
QString file = QFileDialog::getOpenFileName( this,
|
||||||
|
tr( "" ),
|
||||||
|
tr( "" ) );
|
||||||
|
if( file.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( m_pvt->lineEdit->text() == file )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_pvt->lineEdit->setText( file );
|
||||||
|
|
||||||
|
Q_EMIT valueChanged( file );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEdit::setupUI()
|
||||||
|
{
|
||||||
|
m_pvt->lineEdit = new QLineEdit( this );
|
||||||
|
m_pvt->toolButton = new QToolButton( this );
|
||||||
|
m_pvt->toolButton->setText( "..." );
|
||||||
|
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout( this );
|
||||||
|
layout->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
layout->setSpacing( 0 );
|
||||||
|
layout->addWidget( m_pvt->lineEdit );
|
||||||
|
layout->addWidget( m_pvt->toolButton );
|
||||||
|
setLayout( layout );
|
||||||
|
|
||||||
|
setFocusProxy( m_pvt->lineEdit );
|
||||||
|
setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileEdit::setupConnections()
|
||||||
|
{
|
||||||
|
connect( m_pvt->toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onButtonClicked() ) );
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,116 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 FILEPATH_PROPERTY_MANAGER
|
||||||
|
#define FILEPATH_PROPERTY_MANAGER
|
||||||
|
|
||||||
|
#define QT_QTPROPERTYBROWSER_IMPORT
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <3rdparty/qtpropertybrowser/qtpropertymanager.h>
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////// Manager /////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class FileManagerPvt;
|
||||||
|
|
||||||
|
class FileManager : public QtAbstractPropertyManager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FileManager( QObject *parent = NULL );
|
||||||
|
~FileManager();
|
||||||
|
|
||||||
|
QString value( const QtProperty *p ) const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setValue( QtProperty *p, const QString &v );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged( QtProperty *p, const QString &v );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool hasValue( const QtProperty *p ) const;
|
||||||
|
QString valueText( const QtProperty *p ) const;
|
||||||
|
void initializeProperty( QtProperty *p );
|
||||||
|
void uninitializeProperty( QtProperty *p );
|
||||||
|
|
||||||
|
private:
|
||||||
|
FileManagerPvt *m_pvt;
|
||||||
|
|
||||||
|
Q_DISABLE_COPY( FileManager );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class FileEditFactoryPvt;
|
||||||
|
|
||||||
|
class FileEditFactory : public QtAbstractEditorFactory< FileManager >
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FileEditFactory( QObject *parent = NULL );
|
||||||
|
~FileEditFactory();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void connectPropertyManager( FileManager *manager );
|
||||||
|
void disconnectPropertyManager( FileManager *manager );
|
||||||
|
QWidget* createEditor( FileManager *manager, QtProperty *p, QWidget *parent );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onPropertyChanged( QtProperty *p, const QString &value );
|
||||||
|
void onSetValue( const QString &value );
|
||||||
|
void onEditorDestroyed( QObject *editor );
|
||||||
|
|
||||||
|
private:
|
||||||
|
FileEditFactoryPvt *m_pvt;
|
||||||
|
|
||||||
|
Q_DISABLE_COPY( FileEditFactory );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////// Editor ////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class FileEditPvt;
|
||||||
|
|
||||||
|
class FileEdit : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FileEdit( QWidget *parent = NULL );
|
||||||
|
~FileEdit();
|
||||||
|
|
||||||
|
void setValue( const QString &value );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void valueChanged( const QString &value );
|
||||||
|
void destroyed( QObject *editor );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onButtonClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupUI();
|
||||||
|
void setupConnections();
|
||||||
|
FileEditPvt *m_pvt;
|
||||||
|
|
||||||
|
Q_DISABLE_COPY( FileEdit );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,223 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 "georges_dfn_dialog.h"
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "georges.h"
|
||||||
|
#include "dfn_browser_ctrl.h"
|
||||||
|
|
||||||
|
#include "nel/misc/file.h"
|
||||||
|
#include "nel/misc/o_xml.h"
|
||||||
|
#include "nel/misc/path.h"
|
||||||
|
|
||||||
|
class GeorgesDFNDialogPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GeorgesDFNDialogPvt()
|
||||||
|
{
|
||||||
|
dfn = NULL;
|
||||||
|
ctrl = new DFNBrowserCtrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
~GeorgesDFNDialogPvt()
|
||||||
|
{
|
||||||
|
delete ctrl;
|
||||||
|
ctrl = NULL;
|
||||||
|
delete dfn;
|
||||||
|
dfn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
NLGEORGES::CFormDfn *dfn;
|
||||||
|
DFNBrowserCtrl *ctrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
GeorgesDFNDialog::GeorgesDFNDialog( QWidget *parent ) :
|
||||||
|
GeorgesDockWidget( parent )
|
||||||
|
{
|
||||||
|
m_ui.setupUi( this );
|
||||||
|
|
||||||
|
m_pvt = new GeorgesDFNDialogPvt();
|
||||||
|
m_pvt->ctrl->setBrowser( m_ui.browser );
|
||||||
|
|
||||||
|
setupConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
GeorgesDFNDialog::~GeorgesDFNDialog()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GeorgesDFNDialog::load( const QString &fileName )
|
||||||
|
{
|
||||||
|
GeorgesQt::CGeorges georges;
|
||||||
|
NLGEORGES::UFormDfn *udfn = georges.loadFormDfn( fileName.toUtf8().constData() );
|
||||||
|
if( udfn == NULL )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QFileInfo info( fileName );
|
||||||
|
setWindowTitle( info.fileName() );
|
||||||
|
|
||||||
|
NLGEORGES::CFormDfn *cdfn = static_cast< NLGEORGES::CFormDfn* >( udfn );
|
||||||
|
m_pvt->dfn = cdfn;
|
||||||
|
|
||||||
|
loadDfn();
|
||||||
|
|
||||||
|
m_fileName = fileName;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::write()
|
||||||
|
{
|
||||||
|
setModified( false );
|
||||||
|
setWindowTitle( windowTitle().remove( "*" ) );
|
||||||
|
|
||||||
|
m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
|
||||||
|
|
||||||
|
NLMISC::COFile file;
|
||||||
|
if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
NLMISC::COXml xml;
|
||||||
|
xml.init( &file );
|
||||||
|
|
||||||
|
m_pvt->dfn->write( xml.getDocument(), m_fileName.toUtf8().constData() );
|
||||||
|
|
||||||
|
xml.flush();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::newDocument( const QString &fileName )
|
||||||
|
{
|
||||||
|
m_fileName = fileName;
|
||||||
|
QFileInfo info( fileName );
|
||||||
|
setWindowTitle( info.fileName() + "*" );
|
||||||
|
setModified( true );
|
||||||
|
|
||||||
|
m_pvt->dfn = new NLGEORGES::CFormDfn();
|
||||||
|
|
||||||
|
loadDfn();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::onAddClicked()
|
||||||
|
{
|
||||||
|
QString name = QInputDialog::getText( this,
|
||||||
|
tr( "New element" ),
|
||||||
|
tr( "Enter name of the new element" ) );
|
||||||
|
|
||||||
|
QList< QListWidgetItem* > list = m_ui.list->findItems( name, Qt::MatchFixedString );
|
||||||
|
if( !list.isEmpty() )
|
||||||
|
{
|
||||||
|
QMessageBox::information( this,
|
||||||
|
tr( "Item already exists" ),
|
||||||
|
tr( "That item already exists!" ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ui.list->addItem( name );
|
||||||
|
m_pvt->dfn->addEntry( name.toUtf8().constData() );
|
||||||
|
|
||||||
|
log( "Added " + name );
|
||||||
|
|
||||||
|
onModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::onRemoveClicked()
|
||||||
|
{
|
||||||
|
int row = m_ui.list->currentRow();
|
||||||
|
if( row < 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
log( "Removed " + m_ui.list->currentItem()->text() );
|
||||||
|
|
||||||
|
QListWidgetItem *item = m_ui.list->takeItem( row );
|
||||||
|
delete item;
|
||||||
|
|
||||||
|
m_pvt->dfn->removeEntry( row );
|
||||||
|
|
||||||
|
onModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::onCurrentRowChanged( int row )
|
||||||
|
{
|
||||||
|
if( row < 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_pvt->ctrl->onElementSelected( row );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value )
|
||||||
|
{
|
||||||
|
onModified();
|
||||||
|
|
||||||
|
log( m_ui.list->currentItem()->text() + "." + key + " = " + value );
|
||||||
|
|
||||||
|
if( key == "name" )
|
||||||
|
{
|
||||||
|
m_ui.list->currentItem()->setText( value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::loadDfn()
|
||||||
|
{
|
||||||
|
m_pvt->ctrl->setDFN( m_pvt->dfn );
|
||||||
|
|
||||||
|
uint c = m_pvt->dfn->getNumEntry();
|
||||||
|
for( uint i = 0; i < c; i++ )
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormDfn::CEntry &entry = m_pvt->dfn->getEntry( i );
|
||||||
|
m_ui.list->addItem( entry.getName().c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( c > 0 )
|
||||||
|
{
|
||||||
|
m_ui.list->setCurrentRow( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ui.commentsEdit->setPlainText( m_pvt->dfn->getComment().c_str() );
|
||||||
|
m_ui.logEdit->setPlainText( m_pvt->dfn->Header.Log.c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::onModified()
|
||||||
|
{
|
||||||
|
if( !isModified() )
|
||||||
|
{
|
||||||
|
setModified( true );
|
||||||
|
setWindowTitle( windowTitle() + "*" );
|
||||||
|
|
||||||
|
Q_EMIT modified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::log( const QString &msg )
|
||||||
|
{
|
||||||
|
QString logMsg = buildLogMsg( msg );
|
||||||
|
m_ui.logEdit->appendPlainText( logMsg );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesDFNDialog::setupConnections()
|
||||||
|
{
|
||||||
|
connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
|
||||||
|
connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );
|
||||||
|
connect( m_ui.list, SIGNAL( currentRowChanged( int ) ), this, SLOT( onCurrentRowChanged( int ) ) );
|
||||||
|
connect( m_pvt->ctrl, SIGNAL( valueChanged( const QString&, const QString& ) ), this, SLOT( onValueChanged( const QString&, const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 GEORGES_DFN_DIALOG
|
||||||
|
#define GEORGES_DFN_DIALOG
|
||||||
|
|
||||||
|
#include "georges_dock_widget.h"
|
||||||
|
#include "ui_georges_dfn_dialog.h"
|
||||||
|
|
||||||
|
class GeorgesDFNDialogPvt;
|
||||||
|
|
||||||
|
class GeorgesDFNDialog : public GeorgesDockWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
GeorgesDFNDialog( QWidget *parent = NULL );
|
||||||
|
~GeorgesDFNDialog();
|
||||||
|
|
||||||
|
bool load( const QString &fileName );
|
||||||
|
void write();
|
||||||
|
void newDocument( const QString &fileName );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void modified();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onAddClicked();
|
||||||
|
void onRemoveClicked();
|
||||||
|
void onCurrentRowChanged( int row );
|
||||||
|
|
||||||
|
void onValueChanged( const QString& key, const QString &value );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void loadDfn();
|
||||||
|
void onModified();
|
||||||
|
void log( const QString &msg );
|
||||||
|
void setupConnections();
|
||||||
|
|
||||||
|
Ui::GeorgesDFNDialog m_ui;
|
||||||
|
GeorgesDFNDialogPvt *m_pvt;
|
||||||
|
QString m_fileName;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,136 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>GeorgesDFNDialog</class>
|
||||||
|
<widget class="QDockWidget" name="GeorgesDFNDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>693</width>
|
||||||
|
<height>559</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
|
<property name="tabPosition">
|
||||||
|
<enum>QTabWidget::West</enum>
|
||||||
|
</property>
|
||||||
|
<property name="tabShape">
|
||||||
|
<enum>QTabWidget::Rounded</enum>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="documentMode">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="movable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="dfnTab">
|
||||||
|
<property name="accessibleName">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Dfn</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0" colspan="3">
|
||||||
|
<widget class="QSplitter" name="splitter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QListWidget" name="list"/>
|
||||||
|
<widget class="QtTreePropertyBrowser" name="browser" native="true"/>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<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="1" column="1">
|
||||||
|
<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="2">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>466</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="commentTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Comments</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPlainTextEdit" name="commentsEdit">
|
||||||
|
<property name="textInteractionFlags">
|
||||||
|
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="logTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Log</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPlainTextEdit" name="logEdit">
|
||||||
|
<property name="textInteractionFlags">
|
||||||
|
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QtTreePropertyBrowser</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qttreepropertybrowser.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -0,0 +1,60 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 "georges_dock_widget.h"
|
||||||
|
|
||||||
|
GeorgesDockWidget::GeorgesDockWidget( QWidget *parent ) :
|
||||||
|
QDockWidget( parent )
|
||||||
|
{
|
||||||
|
m_modified = false;
|
||||||
|
m_undoStack = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GeorgesDockWidget::~GeorgesDockWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GeorgesDockWidget::buildLogMsg( const QString &msg )
|
||||||
|
{
|
||||||
|
QString user = getenv( "USER" );
|
||||||
|
if( user.isEmpty() )
|
||||||
|
user = getenv( "USERNAME" );
|
||||||
|
if( user.isEmpty() )
|
||||||
|
user = "anonymous";
|
||||||
|
|
||||||
|
QTime time = QTime::currentTime();
|
||||||
|
QDate date = QDate::currentDate();
|
||||||
|
|
||||||
|
QString dateString = date.toString( "ddd MMM dd" );
|
||||||
|
QString timeString = time.toString( "HH:mm:ss" );
|
||||||
|
|
||||||
|
QString logMsg;
|
||||||
|
logMsg += dateString;
|
||||||
|
logMsg += ' ';
|
||||||
|
logMsg += timeString;
|
||||||
|
logMsg += ' ';
|
||||||
|
logMsg += QString::number( date.year() );
|
||||||
|
logMsg += ' ';
|
||||||
|
logMsg += "(";
|
||||||
|
logMsg += user;
|
||||||
|
logMsg += ")";
|
||||||
|
logMsg += ' ';
|
||||||
|
logMsg += msg;
|
||||||
|
|
||||||
|
return logMsg;
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 GEORGES_DOCK_WIDGET
|
||||||
|
#define GEORGES_DOCK_WIDGET
|
||||||
|
|
||||||
|
#include <QDockWidget>
|
||||||
|
|
||||||
|
class QUndoStack;
|
||||||
|
|
||||||
|
class GeorgesDockWidget : public QDockWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GeorgesDockWidget( QWidget *parent = NULL );
|
||||||
|
~GeorgesDockWidget();
|
||||||
|
|
||||||
|
void setUndoStack( QUndoStack *stack ){ m_undoStack = stack; }
|
||||||
|
|
||||||
|
bool isModified() const{ return m_modified; }
|
||||||
|
void setModified( bool b ){ m_modified = b; }
|
||||||
|
|
||||||
|
QString fileName() const{ return m_fileName; }
|
||||||
|
|
||||||
|
virtual bool load( const QString &fileName ) = 0;
|
||||||
|
virtual void write() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QString buildLogMsg( const QString &msg );
|
||||||
|
virtual void log( const QString &msg ) = 0;
|
||||||
|
|
||||||
|
QString m_fileName;
|
||||||
|
bool m_modified;
|
||||||
|
QUndoStack *m_undoStack;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,265 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 "georges_typ_dialog.h"
|
||||||
|
#include "georges.h"
|
||||||
|
#include "typ_browser_ctrl.h"
|
||||||
|
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include "nel/misc/file.h"
|
||||||
|
#include "nel/misc/o_xml.h"
|
||||||
|
#include "nel/misc/path.h"
|
||||||
|
|
||||||
|
class GeorgesTypDialogPvt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GeorgesTypDialogPvt()
|
||||||
|
{
|
||||||
|
typ = NULL;
|
||||||
|
ctrl = new TypBrowserCtrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
~GeorgesTypDialogPvt()
|
||||||
|
{
|
||||||
|
delete typ;
|
||||||
|
typ = NULL;
|
||||||
|
delete ctrl;
|
||||||
|
ctrl = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NLGEORGES::CType *typ;
|
||||||
|
TypBrowserCtrl *ctrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
GeorgesTypDialog::GeorgesTypDialog( QWidget *parent ) :
|
||||||
|
GeorgesDockWidget( parent )
|
||||||
|
{
|
||||||
|
m_ui.setupUi( this );
|
||||||
|
m_pvt = new GeorgesTypDialogPvt();
|
||||||
|
m_pvt->ctrl->setBrowser( m_ui.browser );
|
||||||
|
|
||||||
|
setupConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
GeorgesTypDialog::~GeorgesTypDialog()
|
||||||
|
{
|
||||||
|
delete m_pvt;
|
||||||
|
m_pvt = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GeorgesTypDialog::load( const QString &fileName )
|
||||||
|
{
|
||||||
|
GeorgesQt::CGeorges georges;
|
||||||
|
NLGEORGES::UType *utyp = georges.loadFormType( fileName.toUtf8().constData() );
|
||||||
|
if( utyp == NULL )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_pvt->typ = dynamic_cast< NLGEORGES::CType* >( utyp );
|
||||||
|
|
||||||
|
loadTyp();
|
||||||
|
|
||||||
|
m_fileName = fileName;
|
||||||
|
|
||||||
|
QFileInfo info( fileName );
|
||||||
|
setWindowTitle( info.fileName() );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GeorgesTypDialog::write()
|
||||||
|
{
|
||||||
|
NLMISC::COFile file;
|
||||||
|
if( !file.open( m_fileName.toUtf8().constData(), false, true, false ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
NLMISC::COXml xml;
|
||||||
|
xml.init( &file );
|
||||||
|
|
||||||
|
m_pvt->typ->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
|
||||||
|
m_pvt->typ->write( xml.getDocument() );
|
||||||
|
|
||||||
|
xml.flush();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
setModified( false );
|
||||||
|
setWindowTitle( windowTitle().remove( "*" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::newDocument( const QString &fileName )
|
||||||
|
{
|
||||||
|
m_pvt->typ = new NLGEORGES::CType();
|
||||||
|
m_fileName = fileName;
|
||||||
|
|
||||||
|
QFileInfo info( fileName );
|
||||||
|
setWindowTitle( info.fileName() + "*" );
|
||||||
|
setModified( true );
|
||||||
|
|
||||||
|
loadTyp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::onAddClicked()
|
||||||
|
{
|
||||||
|
QString label = QInputDialog::getText( this,
|
||||||
|
tr( "Adding new definition" ),
|
||||||
|
tr( "Please specify the label" ) );
|
||||||
|
if( label.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList< QTreeWidgetItem* > l = m_ui.tree->findItems( label, Qt::MatchExactly, 0 );
|
||||||
|
if( !l.isEmpty() )
|
||||||
|
{
|
||||||
|
QMessageBox::information( this,
|
||||||
|
tr( "Failed to add item" ),
|
||||||
|
tr( "You can't add an item with the same label more than once!" ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
|
item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
|
||||||
|
item->setText( 0, label );
|
||||||
|
item->setText( 1, "" );
|
||||||
|
m_ui.tree->addTopLevelItem( item );
|
||||||
|
|
||||||
|
NLGEORGES::CType::CDefinition def;
|
||||||
|
def.Label = label.toUtf8().constData();
|
||||||
|
def.Value = "";
|
||||||
|
m_pvt->typ->Definitions.push_back( def );
|
||||||
|
|
||||||
|
log( "Added definition " + label );
|
||||||
|
|
||||||
|
onModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::onRemoveClicked()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem *item = m_ui.tree->currentItem();
|
||||||
|
if( item == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for( i = 0; i < m_ui.tree->topLevelItemCount(); i++ )
|
||||||
|
{
|
||||||
|
if( item == m_ui.tree->topLevelItem( i ) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString definition = item->text( 0 );
|
||||||
|
|
||||||
|
m_ui.tree->takeTopLevelItem( i );
|
||||||
|
delete item;
|
||||||
|
|
||||||
|
std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i;
|
||||||
|
m_pvt->typ->Definitions.erase( itr );
|
||||||
|
|
||||||
|
log( "Removed definition" + definition );
|
||||||
|
|
||||||
|
onModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column )
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for( i = 0; i < m_ui.tree->topLevelItemCount(); i++ )
|
||||||
|
{
|
||||||
|
if( item == m_ui.tree->topLevelItem( i ) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NLGEORGES::CType::CDefinition &def = m_pvt->typ->Definitions[ i ];
|
||||||
|
|
||||||
|
QString logMsg;
|
||||||
|
logMsg = "Changed definition" + QString( def.Label.c_str() );
|
||||||
|
|
||||||
|
if( i == 0 )
|
||||||
|
{
|
||||||
|
logMsg += ".label = ";
|
||||||
|
logMsg += item->text( 0 );
|
||||||
|
def.Label = item->text( 0 ).toUtf8().constData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logMsg += ".value = ";
|
||||||
|
logMsg += item->text( 1 );
|
||||||
|
def.Value = item->text( 1 ).toUtf8().constData();
|
||||||
|
}
|
||||||
|
|
||||||
|
log( logMsg );
|
||||||
|
|
||||||
|
onModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::onModified()
|
||||||
|
{
|
||||||
|
if( isModified() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
setModified( true );
|
||||||
|
setWindowTitle( windowTitle() + "*" );
|
||||||
|
|
||||||
|
Q_EMIT modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::onModified( const QString &k, const QString &v )
|
||||||
|
{
|
||||||
|
log( "Changed " + k + " = " + v );
|
||||||
|
onModified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::setupConnections()
|
||||||
|
{
|
||||||
|
connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
|
||||||
|
connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );
|
||||||
|
|
||||||
|
connect( m_ui.tree, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), this, SLOT( onItemChanged( QTreeWidgetItem*, int ) ) );
|
||||||
|
connect( m_pvt->ctrl, SIGNAL( modified( const QString&, const QString& ) ), this, SLOT( onModified( const QString&, const QString& ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::log( const QString &msg )
|
||||||
|
{
|
||||||
|
QString logMsg = buildLogMsg( msg );
|
||||||
|
m_ui.logEdit->appendPlainText( logMsg );
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeorgesTypDialog::loadTyp()
|
||||||
|
{
|
||||||
|
m_ui.logEdit->setPlainText( m_pvt->typ->Header.Log.c_str() );
|
||||||
|
m_ui.commentEdit->setPlainText( m_pvt->typ->Header.Comments.c_str() );
|
||||||
|
|
||||||
|
std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin();
|
||||||
|
while( itr != m_pvt->typ->Definitions.end() )
|
||||||
|
{
|
||||||
|
NLGEORGES::CType::CDefinition &def = *itr;
|
||||||
|
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||||
|
item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
|
||||||
|
item->setText( 0, def.Label.c_str() );
|
||||||
|
item->setText( 1, def.Value.c_str() );
|
||||||
|
m_ui.tree->addTopLevelItem( item );
|
||||||
|
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pvt->ctrl->setTyp( m_pvt->typ );
|
||||||
|
m_pvt->ctrl->load();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 GEORGES_TYP_DIALOG
|
||||||
|
#define GEORGES_TYP_DIALOG
|
||||||
|
|
||||||
|
#include "georges_dock_widget.h"
|
||||||
|
#include "ui_georges_typ_dialog.h"
|
||||||
|
|
||||||
|
class GeorgesTypDialogPvt;
|
||||||
|
|
||||||
|
class GeorgesTypDialog : public GeorgesDockWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
GeorgesTypDialog( QWidget *parent = NULL );
|
||||||
|
~GeorgesTypDialog();
|
||||||
|
|
||||||
|
bool load( const QString &fileName );
|
||||||
|
void write();
|
||||||
|
void newDocument( const QString &fileName );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void modified();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onAddClicked();
|
||||||
|
void onRemoveClicked();
|
||||||
|
|
||||||
|
void onItemChanged( QTreeWidgetItem *item, int column );
|
||||||
|
void onModified();
|
||||||
|
void onModified( const QString &k, const QString &v );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupConnections();
|
||||||
|
void log( const QString &msg );
|
||||||
|
void loadTyp();
|
||||||
|
|
||||||
|
Ui::GeorgesTypDialog m_ui;
|
||||||
|
GeorgesTypDialogPvt *m_pvt;
|
||||||
|
|
||||||
|
QString m_fileName;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,140 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>GeorgesTypDialog</class>
|
||||||
|
<widget class="QDockWidget" name="GeorgesTypDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>682</width>
|
||||||
|
<height>425</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTabWidget" name="logTab">
|
||||||
|
<property name="tabPosition">
|
||||||
|
<enum>QTabWidget::West</enum>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Type</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QSplitter" name="splitter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QtTreePropertyBrowser" name="browser" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="layoutWidget">
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0" colspan="3">
|
||||||
|
<widget class="QTreeWidget" name="tree">
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Label</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Value</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<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="1" column="1">
|
||||||
|
<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="2">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>15</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_2">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Comment</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPlainTextEdit" name="commentEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Log</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPlainTextEdit" name="logEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QtTreePropertyBrowser</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>qttreepropertybrowser.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -0,0 +1,198 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 "typ_browser_ctrl.h"
|
||||||
|
|
||||||
|
#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qtvariantproperty.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qtpropertymanager.h"
|
||||||
|
#include "3rdparty/qtpropertybrowser/qteditorfactory.h"
|
||||||
|
|
||||||
|
#include "nel/georges/type.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QString typeToString( int v )
|
||||||
|
{
|
||||||
|
QString s;
|
||||||
|
|
||||||
|
switch( v )
|
||||||
|
{
|
||||||
|
case NLGEORGES::UType::UnsignedInt: s = "UnsignedInt"; break;
|
||||||
|
case NLGEORGES::UType::SignedInt: s = "SignedInt"; break;
|
||||||
|
case NLGEORGES::UType::Double: s = "Double"; break;
|
||||||
|
case NLGEORGES::UType::String: s = "String"; break;
|
||||||
|
case NLGEORGES::UType::Color: s = "Color"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString uitypeToString( int v )
|
||||||
|
{
|
||||||
|
QString s;
|
||||||
|
|
||||||
|
switch( v )
|
||||||
|
{
|
||||||
|
case NLGEORGES::CType::Edit: s = "Edit"; break;
|
||||||
|
case NLGEORGES::CType::EditSpin: s = "EditSpin"; break;
|
||||||
|
case NLGEORGES::CType::NonEditableCombo: s = "NonEditableCombo"; break;
|
||||||
|
case NLGEORGES::CType::FileBrowser: s = "FileBrowser"; break;
|
||||||
|
case NLGEORGES::CType::BigEdit: s = "BigEdit"; break;
|
||||||
|
case NLGEORGES::CType::ColorEdit: s = "ColorEdit"; break;
|
||||||
|
case NLGEORGES::CType::IconWidget: s = "IconWidget"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TypBrowserCtrl::TypBrowserCtrl( QObject *parent ) :
|
||||||
|
QObject( parent )
|
||||||
|
{
|
||||||
|
m_typ = NULL;
|
||||||
|
|
||||||
|
m_variantMgr = new QtVariantPropertyManager( this );
|
||||||
|
m_variantFactory = new QtVariantEditorFactory( this );
|
||||||
|
m_enumMgr = new QtEnumPropertyManager( this );
|
||||||
|
m_enumFactory = new QtEnumEditorFactory( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
TypBrowserCtrl::~TypBrowserCtrl()
|
||||||
|
{
|
||||||
|
m_typ = NULL;
|
||||||
|
m_variantMgr = NULL;
|
||||||
|
m_variantFactory = NULL;
|
||||||
|
m_enumMgr = NULL;
|
||||||
|
m_enumFactory = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypBrowserCtrl::load()
|
||||||
|
{
|
||||||
|
m_browser->clear();
|
||||||
|
m_browser->setFactoryForManager( m_variantMgr, m_variantFactory );
|
||||||
|
m_browser->setFactoryForManager( m_enumMgr, m_enumFactory );
|
||||||
|
|
||||||
|
m_typ->Type;
|
||||||
|
m_typ->UIType;
|
||||||
|
|
||||||
|
QtProperty *p = NULL;
|
||||||
|
|
||||||
|
p = m_enumMgr->addProperty( "type" );
|
||||||
|
QStringList l;
|
||||||
|
l.push_back( "UnsignedInt" );
|
||||||
|
l.push_back( "SignedInt" );
|
||||||
|
l.push_back( "Double" );
|
||||||
|
l.push_back( "String" );
|
||||||
|
l.push_back( "Color" );
|
||||||
|
m_enumMgr->setEnumNames( p, l );
|
||||||
|
m_enumMgr->setValue( p, m_typ->Type );
|
||||||
|
m_browser->addProperty( p );
|
||||||
|
|
||||||
|
p = m_enumMgr->addProperty( "uitype" );
|
||||||
|
l.clear();
|
||||||
|
l.push_back( "Edit" );
|
||||||
|
l.push_back( "EditSpin" );
|
||||||
|
l.push_back( "NonEditableCombo" );
|
||||||
|
l.push_back( "FileBrowser" );
|
||||||
|
l.push_back( "BigEdit" );
|
||||||
|
l.push_back( "ColorEdit" );
|
||||||
|
l.push_back( "IconWidget" );
|
||||||
|
m_enumMgr->setEnumNames( p, l );
|
||||||
|
m_enumMgr->setValue( p, m_typ->UIType );
|
||||||
|
m_browser->addProperty( p );
|
||||||
|
|
||||||
|
|
||||||
|
QtVariantProperty *vp = NULL;
|
||||||
|
|
||||||
|
vp = m_variantMgr->addProperty( QVariant::String, "default" );
|
||||||
|
vp->setValue( m_typ->Default.c_str() );
|
||||||
|
m_browser->addProperty( vp );
|
||||||
|
|
||||||
|
vp = m_variantMgr->addProperty( QVariant::String, "min" );
|
||||||
|
vp->setValue( m_typ->Min.c_str() );
|
||||||
|
m_browser->addProperty( vp );
|
||||||
|
|
||||||
|
vp = m_variantMgr->addProperty( QVariant::String, "max" );
|
||||||
|
vp->setValue( m_typ->Max.c_str() );
|
||||||
|
m_browser->addProperty( vp );
|
||||||
|
|
||||||
|
vp = m_variantMgr->addProperty( QVariant::String, "increment" );
|
||||||
|
vp->setValue( m_typ->Increment.c_str() );
|
||||||
|
m_browser->addProperty( vp );
|
||||||
|
|
||||||
|
enableMgrConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypBrowserCtrl::onVariantValueChanged( QtProperty *p, const QVariant &v )
|
||||||
|
{
|
||||||
|
QString n = p->propertyName();
|
||||||
|
if( n == "default" )
|
||||||
|
{
|
||||||
|
m_typ->Default = v.toString().toUtf8().constData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( n == "min" )
|
||||||
|
{
|
||||||
|
m_typ->Min = v.toString().toUtf8().constData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( n == "max" )
|
||||||
|
{
|
||||||
|
m_typ->Max = v.toString().toUtf8().constData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( n == "increment" )
|
||||||
|
{
|
||||||
|
m_typ->Increment = v.toString().toUtf8().constData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
Q_EMIT modified( n, v.toString().toUtf8().constData() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypBrowserCtrl::onEnumValueChanged( QtProperty *p, int v )
|
||||||
|
{
|
||||||
|
QString n = p->propertyName();
|
||||||
|
QString value;
|
||||||
|
|
||||||
|
if( n == "type" )
|
||||||
|
{
|
||||||
|
m_typ->Type = NLGEORGES::UType::TType( v );
|
||||||
|
value = typeToString( v );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( n == "uitype" )
|
||||||
|
{
|
||||||
|
m_typ->UIType = NLGEORGES::CType::TUI( v );
|
||||||
|
value = uitypeToString( v );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
Q_EMIT modified( n, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TypBrowserCtrl::enableMgrConnections()
|
||||||
|
{
|
||||||
|
connect( m_variantMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), this, SLOT( onVariantValueChanged( QtProperty*, const QVariant& ) ) );
|
||||||
|
connect( m_enumMgr, SIGNAL( valueChanged( QtProperty*, int ) ), this, SLOT( onEnumValueChanged( QtProperty*, int ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
|||||||
|
// Ryzom Core Studio - Georges Editor Plugin
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||||
|
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||||
|
//
|
||||||
|
// 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 TYP_BROWSER_CTRL
|
||||||
|
#define TYP_BROWSER_CTRL
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class QtVariantPropertyManager;
|
||||||
|
class QtVariantEditorFactory;
|
||||||
|
class QtTreePropertyBrowser;
|
||||||
|
class QtEnumPropertyManager;
|
||||||
|
class QtEnumEditorFactory;
|
||||||
|
class QVariant;
|
||||||
|
class QtProperty;
|
||||||
|
|
||||||
|
namespace NLGEORGES
|
||||||
|
{
|
||||||
|
class CType;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TypBrowserCtrl : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TypBrowserCtrl( QObject *parent = NULL );
|
||||||
|
~TypBrowserCtrl();
|
||||||
|
|
||||||
|
void load();
|
||||||
|
|
||||||
|
void setTyp( NLGEORGES::CType *typ ){ m_typ = typ; }
|
||||||
|
void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; }
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void modified( const QString &k, const QString &v );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onVariantValueChanged( QtProperty *p, const QVariant &v );
|
||||||
|
void onEnumValueChanged( QtProperty *p, int v );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void enableMgrConnections();
|
||||||
|
|
||||||
|
NLGEORGES::CType *m_typ;
|
||||||
|
QtTreePropertyBrowser *m_browser;
|
||||||
|
|
||||||
|
QtVariantPropertyManager *m_variantMgr;
|
||||||
|
QtVariantEditorFactory *m_variantFactory;
|
||||||
|
QtEnumPropertyManager *m_enumMgr;
|
||||||
|
QtEnumEditorFactory *m_enumFactory;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue