mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-22 17:08:43 +00:00
Apply table changes to the loaded data, and offer to save when closing the changed table.
This commit is contained in:
parent
d4f57a1902
commit
7abf5b2aa1
2 changed files with 54 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <QTableWidget>
|
||||
#include <QFormLayout>
|
||||
#include <QCloseEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "nel/misc/diff_tool.h"
|
||||
|
||||
|
@ -17,9 +18,12 @@ public:
|
|||
UXTEditorPvt()
|
||||
{
|
||||
t = new QTableWidget();
|
||||
changed = false;
|
||||
}
|
||||
|
||||
QTableWidget *t;
|
||||
std::vector< STRING_MANAGER::TStringInfo > infos;
|
||||
bool changed;
|
||||
};
|
||||
|
||||
|
||||
|
@ -30,6 +34,8 @@ CEditor( parent )
|
|||
setAttribute( Qt::WA_DeleteOnClose );
|
||||
|
||||
d_ptr = new UXTEditorPvt();
|
||||
|
||||
blockTableSignals( false );
|
||||
}
|
||||
|
||||
UXTEditor::~UXTEditor()
|
||||
|
@ -40,12 +46,16 @@ UXTEditor::~UXTEditor()
|
|||
|
||||
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 );
|
||||
|
||||
if( infos.size() == 0 )
|
||||
if( d_ptr->infos.size() == 0 )
|
||||
return;
|
||||
|
||||
blockTableSignals( true );
|
||||
|
||||
d_ptr->t->clear();
|
||||
d_ptr->t->setColumnCount( 2 );
|
||||
d_ptr->t->setRowCount( infos.size() );
|
||||
|
@ -71,6 +81,8 @@ void UXTEditor::open( QString filename )
|
|||
|
||||
d_ptr->t->resizeColumnsToContents();
|
||||
|
||||
blockTableSignals( false );
|
||||
|
||||
setWidget( d_ptr->t );
|
||||
setCurrentFile( filename );
|
||||
}
|
||||
|
@ -91,10 +103,38 @@ void UXTEditor::activateWindow()
|
|||
|
||||
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();
|
||||
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 )
|
||||
{
|
||||
QTableWidgetItem *h1 = new QTableWidgetItem( id );
|
||||
|
@ -105,4 +145,12 @@ void UXTEditor::setHeaderText( const QString &id, const QString &text )
|
|||
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:
|
||||
void closeEvent( QCloseEvent *e );
|
||||
|
||||
private Q_SLOTS:
|
||||
void onCellChanged( int row, int column );
|
||||
|
||||
private:
|
||||
void setHeaderText( const QString &id, const QString &text );
|
||||
void blockTableSignals( bool block = false );
|
||||
|
||||
UXTEditorPvt *d_ptr;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue