Logging DFN changes.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-02 20:13:10 +02:00
parent e3d405454e
commit 0b9c281b2f
5 changed files with 47 additions and 24 deletions

View file

@ -83,6 +83,8 @@ void GeorgesDFNDialog::write()
setModified( false ); setModified( false );
setWindowTitle( windowTitle().remove( "*" ) ); setWindowTitle( windowTitle().remove( "*" ) );
m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false );
if( path.empty() ) if( path.empty() )
return; return;
@ -117,6 +119,8 @@ void GeorgesDFNDialog::onAddClicked()
m_ui.list->addItem( name ); m_ui.list->addItem( name );
m_pvt->dfn->addEntry( name.toUtf8().constData() ); m_pvt->dfn->addEntry( name.toUtf8().constData() );
log( "Added " + name );
} }
void GeorgesDFNDialog::onRemoveClicked() void GeorgesDFNDialog::onRemoveClicked()
@ -125,6 +129,8 @@ void GeorgesDFNDialog::onRemoveClicked()
if( row < 0 ) if( row < 0 )
return; return;
log( "Removed " + m_ui.list->currentItem()->text() );
QListWidgetItem *item = m_ui.list->takeItem( row ); QListWidgetItem *item = m_ui.list->takeItem( row );
delete item; delete item;
@ -149,12 +155,20 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value
Q_EMIT modified(); Q_EMIT modified();
} }
log( m_ui.list->currentItem()->text() + "." + key + " = " + value );
if( key == "name" ) if( key == "name" )
{ {
m_ui.list->currentItem()->setText( value ); m_ui.list->currentItem()->setText( value );
} }
} }
void GeorgesDFNDialog::log( const QString &msg )
{
QString logMsg = buildLogMsg( msg );
m_ui.logEdit->appendPlainText( logMsg );
}
void GeorgesDFNDialog::setupConnections() void GeorgesDFNDialog::setupConnections()
{ {
connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );

View file

@ -27,6 +27,7 @@ private Q_SLOTS:
void onValueChanged( const QString& key, const QString &value ); void onValueChanged( const QString& key, const QString &value );
private: private:
void log( const QString &msg );
void setupConnections(); void setupConnections();
Ui::GeorgesDFNDialog m_ui; Ui::GeorgesDFNDialog m_ui;

View file

@ -11,4 +11,32 @@ GeorgesDockWidget::~GeorgesDockWidget()
{ {
} }
QString GeorgesDockWidget::buildLogMsg( const QString &msg )
{
QString user = getenv( "USER" );
if( user.isEmpty() )
user = getenv( "USERNAME" );
if( user.isEmpty() )
user = "anonymous";
QTime time = QTime::currentTime();
QDate date = QDate::currentDate();
QString dateString = date.toString( "ddd MMM dd" );
QString timeString = time.toString( "HH:mm:ss" );
QString logMsg;
logMsg += dateString;
logMsg += ' ';
logMsg += timeString;
logMsg += ' ';
logMsg += QString::number( date.year() );
logMsg += ' ';
logMsg += "(";
logMsg += user;
logMsg += ")";
logMsg += ' ';
logMsg += msg;
return logMsg;
}

View file

@ -21,6 +21,9 @@ public:
virtual void write() = 0; virtual void write() = 0;
protected: protected:
QString buildLogMsg( const QString &msg );
virtual void log( const QString &msg ) = 0;
QString m_fileName; QString m_fileName;
bool m_modified; bool m_modified;
QUndoStack *m_undoStack; QUndoStack *m_undoStack;

View file

@ -698,30 +698,7 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::log( const QString &msg ) void CGeorgesTreeViewDialog::log( const QString &msg )
{ {
QString user = getenv( "USER" ); QString logMsg = buildLogMsg( msg );
if( user.isEmpty() )
user = getenv( "USERNAME" );
if( user.isEmpty() )
user = "anonymous";
QTime time = QTime::currentTime();
QDate date = QDate::currentDate();
QString dateString = date.toString( "ddd MMM dd" );
QString timeString = time.toString( "HH:mm:ss" );
QString logMsg;
logMsg += dateString;
logMsg += ' ';
logMsg += timeString;
logMsg += ' ';
logMsg += QString::number( date.year() );
logMsg += ' ';
logMsg += "(";
logMsg += user;
logMsg += ")";
logMsg += ' ';
logMsg += msg;
m_ui.logEdit->appendPlainText( logMsg ); m_ui.logEdit->appendPlainText( logMsg );
} }