Added #1193 Added scheme bank dialog in particles editor.

This commit is contained in:
dnk-88 2011-12-31 12:24:23 +03:00
parent 1049a4e339
commit 11d9de671d
7 changed files with 217 additions and 65 deletions

View file

@ -91,7 +91,7 @@
<item> <item>
<widget class="QPushButton" name="bankButton"> <widget class="QPushButton" name="bankButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>true</bool>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">

View file

@ -186,12 +186,11 @@ void CAttribWidget::changeUseScheme(int index)
void CAttribWidget::openSchemeBankDialog() void CAttribWidget::openSchemeBankDialog()
{ {
CSchemeBankDialog *dialog = new CSchemeBankDialog(this); CSchemeBankDialog dialog(this);
dialog->setModal(true); dialog.setModal(true);
dialog->show(); dialog.show();
dialog->exec(); dialog.exec();
delete dialog; updateUi();
//updateUi();
} }
void CAttribWidget::inputValueUpdate(void) void CAttribWidget::inputValueUpdate(void)

View file

@ -73,6 +73,7 @@ void CParticleEditor::release()
{ {
stop(); stop();
closeWorkspace(); closeWorkspace();
delete _SchemeManager;
} }
void CParticleEditor::setActiveNode(CWorkspaceNode *node) void CParticleEditor::setActiveNode(CWorkspaceNode *node)

View file

@ -17,8 +17,17 @@
// Project includes // Project includes
#include "stdpch.h" #include "stdpch.h"
#include "scheme_bank_dialog.h" #include "scheme_bank_dialog.h"
#include "scheme_manager.h"
#include "modules.h" #include "modules.h"
// NeL includes
#include <nel/misc/file.h>
// Qt includes
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
namespace NLQT namespace NLQT
{ {
@ -27,6 +36,16 @@ CSchemeBankDialog::CSchemeBankDialog(CAttribWidget *attribWidget, QWidget *paren
{ {
_ui.setupUi(this); _ui.setupUi(this);
_attribWidget = attribWidget; _attribWidget = attribWidget;
connect(_ui.createButton, SIGNAL(clicked()), this, SLOT(createScheme()));
connect(_ui.currentButton, SIGNAL(clicked()), this, SLOT(setCurrentScheme()));
connect(_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeScheme()));
connect(_ui.loadButton, SIGNAL(clicked()), this, SLOT(loadBank()));
connect(_ui.saveButton, SIGNAL(clicked()), this, SLOT(saveBank()));
connect(_ui.listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableButtons()));
connect(_ui.listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(changeNameScheme(QListWidgetItem *)));
buildList();
} }
CSchemeBankDialog::~CSchemeBankDialog() CSchemeBankDialog::~CSchemeBankDialog()
@ -35,27 +54,125 @@ CSchemeBankDialog::~CSchemeBankDialog()
void CSchemeBankDialog::createScheme() void CSchemeBankDialog::createScheme()
{ {
bool ok;
QString text = QInputDialog::getText(this, tr("Insert new scheme"),
tr("Set name:"), QLineEdit::Normal,
"new scheme", &ok);
if (ok && !text.isEmpty())
{
NL3D::CPSAttribMakerBase *attribMakerBase = _attribWidget->getCurrentSchemePtr()->clone();
Modules::psEdit().getSchemeManager()->insertScheme(text.toStdString(), attribMakerBase);
CSchemeItem *item = new CSchemeItem(text, _ui.listWidget);
item->setUserData(attribMakerBase);
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
} }
void CSchemeBankDialog::setCurrentScheme() void CSchemeBankDialog::setCurrentScheme()
{ {
//SchemeManager.insertScheme(cn.getName(), getCurrentSchemePtr()->clone()); CSchemeItem *item = dynamic_cast<CSchemeItem *>(_ui.listWidget->currentItem());
NL3D::CPSAttribMakerBase *attrib = item->getUserData();
nlassert(attrib);
_attribWidget->setCurrentSchemePtr(attrib->clone());
_attribWidget->updateUi();
} }
void CSchemeBankDialog::removeScheme() void CSchemeBankDialog::removeScheme()
{ {
CSchemeItem *item = dynamic_cast<CSchemeItem *>(_ui.listWidget->currentItem());
NL3D::CPSAttribMakerBase *attrib = item->getUserData();
nlassert(attrib);
Modules::psEdit().getSchemeManager()->remove(attrib);
_ui.listWidget->removeItemWidget(item);
delete item;
if (_ui.listWidget->count() == 0)
{
_ui.currentButton->setEnabled(false);
_ui.removeButton->setEnabled(false);
}
} }
void CSchemeBankDialog::saveBank() void CSchemeBankDialog::saveBank()
{ {
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save scheme bank file"), ".",
tr("Scheme bank files (*.scb)"));
if (!fileName.isEmpty())
{
try
{
NLMISC::COFile iF;
iF.open(fileName.toStdString());
NLQT::CSchemeManager *schemeManager = Modules::psEdit().getSchemeManager();
iF.serial(*schemeManager);
}
catch (std::exception &e)
{
QMessageBox::critical(this, "Scheme manager", tr("Error saving scheme bank : %1").arg(e.what()));
return;
}
}
} }
void CSchemeBankDialog::loadBank() void CSchemeBankDialog::loadBank()
{ {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open scheme bank file"), ".",
tr("Scheme bank files (*.scb)"));
if (!fileName.isEmpty())
{
NLQT::CSchemeManager sm;
try
{
NLMISC::CIFile iF;
iF.open(fileName.toStdString());
iF.serial(sm);
Modules::psEdit().getSchemeManager()->swap(sm);
}
catch (std::exception &e)
{
QMessageBox::critical(this, "Scheme manager", tr("Error loading scheme bank : %1").arg(e.what()));
return;
}
buildList();
}
}
void CSchemeBankDialog::changeNameScheme(QListWidgetItem *item)
{
CSchemeItem *schemeItem = dynamic_cast<CSchemeItem *>(item);
NL3D::CPSAttribMakerBase *attrib = schemeItem->getUserData();
nlassert(attrib);
Modules::psEdit().getSchemeManager()->rename(attrib, item->text().toStdString());
}
void CSchemeBankDialog::enableButtons()
{
_ui.currentButton->setEnabled(true);
_ui.removeButton->setEnabled(true);
} }
void CSchemeBankDialog::buildList() void CSchemeBankDialog::buildList()
{ {
_ui.listWidget->clear();
typedef std::vector<NLQT::CSchemeManager::TSchemeInfo> TSchemeVect;
static TSchemeVect schemes;
Modules::psEdit().getSchemeManager()->getSchemes(_attribWidget->getCurrentSchemePtr()->getType(), schemes);
for (TSchemeVect::const_iterator it = schemes.begin(); it != schemes.end(); ++it)
{
CSchemeItem *item = new CSchemeItem(it->first.c_str(), _ui.listWidget);
item->setUserData(it->second);
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
} }
} /* namespace NLQT */ } /* namespace NLQT */

View file

@ -27,12 +27,37 @@
#include "nel/3d/particle_system.h" #include "nel/3d/particle_system.h"
// Project includes // Project includes
#include "attrib_widget.h"
#include "ps_wrapper.h" #include "ps_wrapper.h"
namespace NLQT namespace NLQT
{ {
class CAttribWidget; class CAttribWidget;
/**
@class CSchemeItem
@brief Contain pointer to NL3D::CPSAttribMakerBase.
*/
class CSchemeItem: public QListWidgetItem
{
public:
CSchemeItem(const QString &text, QListWidget *parent = 0, int type = UserType ):
QListWidgetItem(text, parent, type), _attrib(NULL) {}
void setUserData(NL3D::CPSAttribMakerBase *attrib)
{
_attrib = attrib;
}
NL3D::CPSAttribMakerBase *getUserData() const
{
return _attrib;
}
private:
NL3D::CPSAttribMakerBase *_attrib;
}; /* class CSchemeItem */
class CSchemeBankDialog: public QDialog class CSchemeBankDialog: public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -47,6 +72,8 @@ private Q_SLOTS:
void removeScheme(); void removeScheme();
void saveBank(); void saveBank();
void loadBank(); void loadBank();
void enableButtons();
void changeNameScheme(QListWidgetItem *item);
private: private:
void buildList(); void buildList();

View file

@ -14,31 +14,27 @@
<string>Sceme bank</string> <string>Sceme bank</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="8"> <item row="0" column="0" rowspan="7">
<widget class="QListWidget" name="listWidget"/> <widget class="QListWidget" name="listWidget"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QPushButton" name="createButton"> <widget class="QPushButton" name="createButton">
<property name="text"> <property name="text">
<string>Create</string> <string>Put current</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QPushButton" name="renameButton">
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="removeButton"> <widget class="QPushButton" name="removeButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Remove</string> <string>Remove</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="4" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -51,24 +47,33 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="1"> <item row="5" column="1">
<widget class="QPushButton" name="loadButton"> <widget class="QPushButton" name="loadButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>Load bank</string> <string>Load bank</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="6" column="1">
<widget class="QPushButton" name="saveButton"> <widget class="QPushButton" name="saveButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>Save bank</string> <string>Save bank</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0" colspan="2"> <item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -105,7 +110,10 @@
</layout> </layout>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="setCurrentButton"> <widget class="QPushButton" name="currentButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Set current</string> <string>Set current</string>
</property> </property>

View file

@ -80,12 +80,12 @@ void CSchemeManager::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
} }
} }
void CSchemeManager::swap(CSchemeManager &other) void CSchemeManager::swap(CSchemeManager &other)
{ {
this->_SchemeMap.swap(other._SchemeMap); this->_SchemeMap.swap(other._SchemeMap);
} }
void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am) void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am)
{ {
TSchemeMap::iterator smIt; TSchemeMap::iterator smIt;
for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt) for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt)
@ -101,7 +101,7 @@ void CSchemeManager::remove(NL3D::CPSAttribMakerBase *am)
} }
// rename a scheme, given a pointer on it // rename a scheme, given a pointer on it
void CSchemeManager::rename(NL3D::CPSAttribMakerBase *am, const std::string &newName) void CSchemeManager::rename(NL3D::CPSAttribMakerBase *am, const std::string &newName)
{ {
TSchemeMap::iterator smIt; TSchemeMap::iterator smIt;
for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt) for (smIt = _SchemeMap.begin(); smIt != _SchemeMap.end(); ++smIt)