Implemented saving.

This commit is contained in:
dfighter1985 2014-09-02 23:54:42 +02:00
parent b6e743dc16
commit 5e2b448cbe
3 changed files with 46 additions and 0 deletions

View file

@ -324,6 +324,8 @@ namespace GeorgesQt
return NULL; return NULL;
} }
connect( d, SIGNAL( modified() ), this, SLOT( setModified() ) );
return d; return d;
} }

View file

@ -4,6 +4,10 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include "nel/misc/file.h"
#include "nel/misc/o_xml.h"
#include "nel/misc/path.h"
class GeorgesTypDialogPvt class GeorgesTypDialogPvt
{ {
public: public:
@ -48,12 +52,31 @@ bool GeorgesTypDialog::load( const QString &fileName )
loadTyp(); loadTyp();
m_fileName = fileName;
setWindowTitle( fileName );
return true; return true;
} }
void GeorgesTypDialog::write() void GeorgesTypDialog::write()
{ {
std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false );
NLMISC::COFile file;
if( !file.open( path.c_str(), false, true, false ) )
return;
NLMISC::COXml xml;
xml.init( &file );
m_pvt->typ->write( xml.getDocument() );
xml.flush();
file.close();
setModified( false );
setWindowTitle( windowTitle().remove( "*" ) );
} }
void GeorgesTypDialog::onAddClicked() void GeorgesTypDialog::onAddClicked()
@ -84,6 +107,7 @@ void GeorgesTypDialog::onAddClicked()
def.Value = ""; def.Value = "";
m_pvt->typ->Definitions.push_back( def ); m_pvt->typ->Definitions.push_back( def );
onModified();
} }
void GeorgesTypDialog::onRemoveClicked() void GeorgesTypDialog::onRemoveClicked()
@ -105,6 +129,7 @@ void GeorgesTypDialog::onRemoveClicked()
std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i; std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i;
m_pvt->typ->Definitions.erase( itr ); m_pvt->typ->Definitions.erase( itr );
onModified();
} }
void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column )
@ -122,6 +147,19 @@ void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column )
def.Label = item->text( 0 ).toUtf8().constData(); def.Label = item->text( 0 ).toUtf8().constData();
else else
def.Value = item->text( 1 ).toUtf8().constData(); def.Value = item->text( 1 ).toUtf8().constData();
onModified();
}
void GeorgesTypDialog::onModified()
{
if( isModified() )
return;
setModified( true );
setWindowTitle( windowTitle() + "*" );
Q_EMIT modified();
} }
void GeorgesTypDialog::setupConnections() void GeorgesTypDialog::setupConnections()

View file

@ -16,11 +16,15 @@ public:
bool load( const QString &fileName ); bool load( const QString &fileName );
void write(); void write();
Q_SIGNALS:
void modified();
private Q_SLOTS: private Q_SLOTS:
void onAddClicked(); void onAddClicked();
void onRemoveClicked(); void onRemoveClicked();
void onItemChanged( QTreeWidgetItem *item, int column ); void onItemChanged( QTreeWidgetItem *item, int column );
void onModified();
private: private:
void setupConnections(); void setupConnections();
@ -29,6 +33,8 @@ private:
Ui::GeorgesTypDialog m_ui; Ui::GeorgesTypDialog m_ui;
GeorgesTypDialogPvt *m_pvt; GeorgesTypDialogPvt *m_pvt;
QString m_fileName;
}; };