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 );
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 );
if( path.empty() )
return;
@ -117,6 +119,8 @@ void GeorgesDFNDialog::onAddClicked()
m_ui.list->addItem( name );
m_pvt->dfn->addEntry( name.toUtf8().constData() );
log( "Added " + name );
}
void GeorgesDFNDialog::onRemoveClicked()
@ -125,6 +129,8 @@ void GeorgesDFNDialog::onRemoveClicked()
if( row < 0 )
return;
log( "Removed " + m_ui.list->currentItem()->text() );
QListWidgetItem *item = m_ui.list->takeItem( row );
delete item;
@ -149,12 +155,20 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value
Q_EMIT modified();
}
log( m_ui.list->currentItem()->text() + "." + key + " = " + value );
if( key == "name" )
{
m_ui.list->currentItem()->setText( value );
}
}
void GeorgesDFNDialog::log( const QString &msg )
{
QString logMsg = buildLogMsg( msg );
m_ui.logEdit->appendPlainText( logMsg );
}
void GeorgesDFNDialog::setupConnections()
{
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 );
private:
void log( const QString &msg );
void setupConnections();
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;
protected:
QString buildLogMsg( const QString &msg );
virtual void log( const QString &msg ) = 0;
QString m_fileName;
bool m_modified;
QUndoStack *m_undoStack;

View file

@ -698,30 +698,7 @@ namespace GeorgesQt
void CGeorgesTreeViewDialog::log( 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;
QString logMsg = buildLogMsg( msg );
m_ui.logEdit->appendPlainText( logMsg );
}