mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-21 00:18:43 +00:00
Apply table changes to the loaded data, and offer to save when closing the changed table.
--HG-- branch : gsoc2014-dfighter
This commit is contained in:
parent
0de5152aa9
commit
fbc1632d04
2 changed files with 54 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "nel/misc/diff_tool.h"
|
#include "nel/misc/diff_tool.h"
|
||||||
|
|
||||||
|
@ -17,9 +18,12 @@ public:
|
||||||
UXTEditorPvt()
|
UXTEditorPvt()
|
||||||
{
|
{
|
||||||
t = new QTableWidget();
|
t = new QTableWidget();
|
||||||
|
changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTableWidget *t;
|
QTableWidget *t;
|
||||||
|
std::vector< STRING_MANAGER::TStringInfo > infos;
|
||||||
|
bool changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +34,8 @@ CEditor( parent )
|
||||||
setAttribute( Qt::WA_DeleteOnClose );
|
setAttribute( Qt::WA_DeleteOnClose );
|
||||||
|
|
||||||
d_ptr = new UXTEditorPvt();
|
d_ptr = new UXTEditorPvt();
|
||||||
|
|
||||||
|
blockTableSignals( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
UXTEditor::~UXTEditor()
|
UXTEditor::~UXTEditor()
|
||||||
|
@ -40,12 +46,16 @@ UXTEditor::~UXTEditor()
|
||||||
|
|
||||||
void UXTEditor::open( QString filename )
|
void UXTEditor::open( QString filename )
|
||||||
{
|
{
|
||||||
std::vector< STRING_MANAGER::TStringInfo > infos;
|
std::vector< STRING_MANAGER::TStringInfo > &infos = d_ptr->infos;
|
||||||
|
|
||||||
|
infos.clear();
|
||||||
STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, true );
|
STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, true );
|
||||||
|
|
||||||
if( infos.size() == 0 )
|
if( d_ptr->infos.size() == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
blockTableSignals( true );
|
||||||
|
|
||||||
d_ptr->t->clear();
|
d_ptr->t->clear();
|
||||||
d_ptr->t->setColumnCount( 2 );
|
d_ptr->t->setColumnCount( 2 );
|
||||||
d_ptr->t->setRowCount( infos.size() );
|
d_ptr->t->setRowCount( infos.size() );
|
||||||
|
@ -71,6 +81,8 @@ void UXTEditor::open( QString filename )
|
||||||
|
|
||||||
d_ptr->t->resizeColumnsToContents();
|
d_ptr->t->resizeColumnsToContents();
|
||||||
|
|
||||||
|
blockTableSignals( false );
|
||||||
|
|
||||||
setWidget( d_ptr->t );
|
setWidget( d_ptr->t );
|
||||||
setCurrentFile( filename );
|
setCurrentFile( filename );
|
||||||
}
|
}
|
||||||
|
@ -91,10 +103,38 @@ void UXTEditor::activateWindow()
|
||||||
|
|
||||||
void UXTEditor::closeEvent( QCloseEvent *e )
|
void UXTEditor::closeEvent( QCloseEvent *e )
|
||||||
{
|
{
|
||||||
|
if( d_ptr->changed )
|
||||||
|
{
|
||||||
|
int reply = QMessageBox::question( this,
|
||||||
|
tr( "Table changed" ),
|
||||||
|
tr( "The table has changed. Would you like to save your changes?" ),
|
||||||
|
QMessageBox::Yes,
|
||||||
|
QMessageBox::No
|
||||||
|
);
|
||||||
|
|
||||||
|
if( reply == QMessageBox::Yes )
|
||||||
|
save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
e->accept();
|
e->accept();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UXTEditor::onCellChanged( int row, int column )
|
||||||
|
{
|
||||||
|
QTableWidgetItem *item = d_ptr->t->item( row, column );
|
||||||
|
STRING_MANAGER::TStringInfo &info = d_ptr->infos[ row ];
|
||||||
|
|
||||||
|
if( column == 0 )
|
||||||
|
info.Identifier = item->text().toUtf8().constData();
|
||||||
|
else
|
||||||
|
if( column == 1 )
|
||||||
|
info.Text = item->text().toUtf8().constData();
|
||||||
|
|
||||||
|
d_ptr->changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
void UXTEditor::setHeaderText( const QString &id, const QString &text )
|
void UXTEditor::setHeaderText( const QString &id, const QString &text )
|
||||||
{
|
{
|
||||||
QTableWidgetItem *h1 = new QTableWidgetItem( id );
|
QTableWidgetItem *h1 = new QTableWidgetItem( id );
|
||||||
|
@ -105,4 +145,12 @@ void UXTEditor::setHeaderText( const QString &id, const QString &text )
|
||||||
d_ptr->t->setHorizontalHeaderItem( 1, h2 );
|
d_ptr->t->setHorizontalHeaderItem( 1, h2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UXTEditor::blockTableSignals( bool block )
|
||||||
|
{
|
||||||
|
if( block )
|
||||||
|
disconnect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) );
|
||||||
|
else
|
||||||
|
connect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,12 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void closeEvent( QCloseEvent *e );
|
void closeEvent( QCloseEvent *e );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onCellChanged( int row, int column );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setHeaderText( const QString &id, const QString &text );
|
void setHeaderText( const QString &id, const QString &text );
|
||||||
|
void blockTableSignals( bool block = false );
|
||||||
|
|
||||||
UXTEditorPvt *d_ptr;
|
UXTEditorPvt *d_ptr;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue