Skip to content

Commit

Permalink
Fix #16474 - Clean up formatting of crash report data
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed May 7, 2017
1 parent ddbb170 commit 6c41bdf
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 54 deletions.
20 changes: 16 additions & 4 deletions src/app/qgscrashdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ QgsCrashDialog::QgsCrashDialog( QWidget *parent )

void QgsCrashDialog::setBugReport( const QString &reportData )
{
mReportDetailsText->setPlainText( reportData );
mReportData = reportData;
mReportDetailsText->setHtml( reportData );
}

void QgsCrashDialog::showReportWidget()
Expand All @@ -52,8 +53,19 @@ void QgsCrashDialog::showReportWidget()
void QgsCrashDialog::createBugReport()
{
QClipboard *clipboard = QApplication::clipboard();
QString userText = "User Feedback\n=============\n" + mUserFeedbackText->toPlainText();
QString details = "Report Details\n==============\n" + mReportDetailsText->toPlainText();
QString userText = "h2. User Feedback\n\n" + mUserFeedbackText->toPlainText();
QString details = "h2. Report Details\n\n" + mReportData;
QString finalText = userText + "\n\n" + details;
clipboard->setText( finalText );
QString markdown = htmlToMarkdown( finalText );
clipboard->setText( markdown );
}

QString QgsCrashDialog::htmlToMarkdown( const QString &html ) const
{
QString markdown = html;
markdown.replace( "<br>", "\n" );
markdown.replace( "<b>", "*" );
markdown.replace( "</b>", "*" );
return markdown;
}

5 changes: 5 additions & 0 deletions src/app/qgscrashdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ class APP_EXPORT QgsCrashDialog : public QDialog, private Ui::QgsCrashDialog

void setBugReport( const QString &reportData );

static QString htmlToMarkdown( const QString &html );

private slots:
void showReportWidget();
void createBugReport();

private:
QString mReportData;
};

#endif // QGSCRASHDIALOG_H
2 changes: 1 addition & 1 deletion src/app/qgscrashhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void QgsCrashHandler::showCrashDialog( const QgsStackLines &stack )
QgsCrashDialog dlg( QApplication::activeWindow() );
QgsCrashReport report;
report.setStackTrace( stack );
dlg.setBugReport( report.toString() );
dlg.setBugReport( report.toHtml() );
if ( dlg.exec() )
{
restartApplication();
Expand Down
31 changes: 13 additions & 18 deletions src/app/qgscrashreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ void QgsCrashReport::setFlags( QgsCrashReport::Flags flags )
mFlags = flags;
}

const QString QgsCrashReport::toString() const
const QString QgsCrashReport::toHtml() const
{
QStringList reportData;
reportData.append( "Crash ID: " + crashID() );
reportData.append( "<b>Crash ID</b>: " + crashID() );

if ( flags().testFlag( QgsCrashReport::Stack ) )
{
reportData.append( "\n" );
reportData.append( "Stack Trace" );
reportData.append( "===========" );
reportData.append( "<br>" );
reportData.append( "<b>Stack Trace</b>" );
if ( mStackTrace.isEmpty() )
{
reportData.append( "Stack trace unable to be generated." );
Expand All @@ -60,25 +59,22 @@ const QString QgsCrashReport::toString() const

if ( flags().testFlag( QgsCrashReport::Plugins ) )
{
reportData.append( "\n" );
reportData.append( "Plugins" );
reportData.append( "=======" );
reportData.append( "<br>" );
reportData.append( "<b>Plugins</b>" );
// TODO Get plugin info
}

if ( flags().testFlag( QgsCrashReport::ProjectDetails ) )
{
reportData.append( "\n" );
reportData.append( "Project Info" );
reportData.append( "============" );
reportData.append( "<br>" );
reportData.append( "<b>Project Info</b>" );
// TODO Get project details
}

if ( flags().testFlag( QgsCrashReport::QgisInfo ) )
{
reportData.append( "\n" );
reportData.append( "QGIS Info" );
reportData.append( "=========" );
reportData.append( "<br>" );
reportData.append( "<b>QGIS Info</b>" );
reportData.append( QString( "QGIS Version: %1" ).arg( Qgis::QGIS_VERSION ) );

if ( QString( Qgis::QGIS_DEV_VERSION ) == QLatin1String( "exported" ) )
Expand All @@ -100,9 +96,8 @@ const QString QgsCrashReport::toString() const

if ( flags().testFlag( QgsCrashReport::SystemInfo ) )
{
reportData.append( "\n" );
reportData.append( "System Info" );
reportData.append( "===========" );
reportData.append( "<br>" );
reportData.append( "<b>System Info</b>" );
reportData.append( QString( "CPU Type: %1" ).arg( QSysInfo::currentCpuArchitecture() ) );
reportData.append( QString( "Kernel Type: %1" ).arg( QSysInfo::kernelType() ) );
reportData.append( QString( "Kernel Version: %1" ).arg( QSysInfo::kernelVersion() ) );
Expand All @@ -111,7 +106,7 @@ const QString QgsCrashReport::toString() const
QString report;
Q_FOREACH ( QString line, reportData )
{
report += line + "\n";
report += line + "<br>";
}
return report;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgscrashreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class APP_EXPORT QgsCrashReport
* Generate a string version of the report.
* \return A formatted string including all the information from the report.
*/
const QString toString() const;
const QString toHtml() const;

/**
* Generates a crash ID for the crash report.
Expand Down
76 changes: 46 additions & 30 deletions src/ui/qgscrashdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>583</width>
<height>644</height>
<width>522</width>
<height>636</height>
</rect>
</property>
<property name="palette">
Expand Down Expand Up @@ -450,6 +450,16 @@
<property name="topMargin">
<number>1</number>
</property>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Report Details</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
Expand Down Expand Up @@ -490,16 +500,20 @@
</item>
</layout>
</item>
<item row="3" column="0" colspan="3">
<widget class="QPlainTextEdit" name="mReportDetailsText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="0" column="2">
<widget class="QPushButton" name="mCopyReportButton">
<property name="text">
<string>Copy Report</string>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Tell us something about when you got the crash</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
Expand All @@ -522,29 +536,31 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="mCopyReportButton">
<property name="text">
<string>Copy Report</string>
<item row="6" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Tell us something about when you got the crash</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Report Details</string>
<item row="3" column="0" colspan="3">
<widget class="QTextEdit" name="mReportDetailsText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="wordWrap">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
Expand Down

0 comments on commit 6c41bdf

Please sign in to comment.