Implemented saving.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-02 23:54:42 +02:00
parent 173dbba11c
commit f587e06d7a
3 changed files with 46 additions and 0 deletions

View file

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

View file

@ -4,6 +4,10 @@
#include <QInputDialog>
#include <QMessageBox>
#include "nel/misc/file.h"
#include "nel/misc/o_xml.h"
#include "nel/misc/path.h"
class GeorgesTypDialogPvt
{
public:
@ -48,12 +52,31 @@ bool GeorgesTypDialog::load( const QString &fileName )
loadTyp();
m_fileName = fileName;
setWindowTitle( fileName );
return true;
}
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()
@ -84,6 +107,7 @@ void GeorgesTypDialog::onAddClicked()
def.Value = "";
m_pvt->typ->Definitions.push_back( def );
onModified();
}
void GeorgesTypDialog::onRemoveClicked()
@ -105,6 +129,7 @@ void GeorgesTypDialog::onRemoveClicked()
std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i;
m_pvt->typ->Definitions.erase( itr );
onModified();
}
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();
else
def.Value = item->text( 1 ).toUtf8().constData();
onModified();
}
void GeorgesTypDialog::onModified()
{
if( isModified() )
return;
setModified( true );
setWindowTitle( windowTitle() + "*" );
Q_EMIT modified();
}
void GeorgesTypDialog::setupConnections()

View file

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