Merge pull request #590 from Blubbz0r/#2274-GUI-Printing-support
#2274 GUI: Printing support
This commit is contained in:
commit
355890375c
|
@ -6,9 +6,9 @@ DEPENDPATH += . \
|
|||
INCLUDEPATH += . \
|
||||
../lib
|
||||
|
||||
# In Qt 5 widgets are in separate module
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
QT += widgets
|
||||
QT += widgets # In Qt 5 widgets are in separate module
|
||||
QT += printsupport # In Qt 5 QPrinter/QPrintDialog are in separate module
|
||||
}
|
||||
|
||||
contains(LINKCORE, [yY][eE][sS]) {
|
||||
|
@ -88,6 +88,7 @@ HEADERS += aboutdialog.h \
|
|||
logview.h \
|
||||
mainwindow.h \
|
||||
platforms.h \
|
||||
printablereport.h \
|
||||
project.h \
|
||||
projectfile.h \
|
||||
projectfiledialog.h \
|
||||
|
@ -121,6 +122,7 @@ SOURCES += aboutdialog.cpp \
|
|||
main.cpp \
|
||||
mainwindow.cpp\
|
||||
platforms.cpp \
|
||||
printablereport.cpp \
|
||||
project.cpp \
|
||||
projectfile.cpp \
|
||||
projectfiledialog.cpp \
|
||||
|
|
22
gui/main.ui
22
gui/main.ui
|
@ -62,7 +62,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>25</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="mMenuFile">
|
||||
|
@ -78,6 +78,10 @@
|
|||
<addaction name="separator"/>
|
||||
<addaction name="mActionProjectMRU"/>
|
||||
<addaction name="mActionSave"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="mActionPrintPreview"/>
|
||||
<addaction name="mActionPrint"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="mActionQuit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="mMenuView">
|
||||
|
@ -682,6 +686,22 @@
|
|||
<string>C++03</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="mActionPrint">
|
||||
<property name="text">
|
||||
<string>&Print...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Print the Current Report</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="mActionPrintPreview">
|
||||
<property name="text">
|
||||
<string>Print Pre&view...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open a Print Preview Dialog for the Current Results</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -77,6 +77,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
|||
connect(mLineEditFilter, SIGNAL(textChanged(const QString&)), mFilterTimer, SLOT(start()));
|
||||
connect(mLineEditFilter, SIGNAL(returnPressed()), this, SLOT(FilterResults()));
|
||||
|
||||
connect(mUI.mActionPrint, SIGNAL(triggered()), mUI.mResults, SLOT(Print()));
|
||||
connect(mUI.mActionPrintPreview, SIGNAL(triggered()), mUI.mResults, SLOT(PrintPreview()));
|
||||
connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
|
||||
connect(mUI.mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
|
||||
|
@ -134,6 +136,9 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
|||
|
||||
EnableCheckButtons(true);
|
||||
|
||||
mUI.mActionPrint->setShortcut(QKeySequence::Print);
|
||||
mUI.mActionPrint->setEnabled(false);
|
||||
mUI.mActionPrintPreview->setEnabled(false);
|
||||
mUI.mActionClearResults->setEnabled(false);
|
||||
mUI.mActionSave->setEnabled(false);
|
||||
mUI.mActionRecheck->setEnabled(false);
|
||||
|
@ -695,6 +700,8 @@ void MainWindow::CheckDone()
|
|||
if (mUI.mResults->HasResults()) {
|
||||
mUI.mActionClearResults->setEnabled(true);
|
||||
mUI.mActionSave->setEnabled(true);
|
||||
mUI.mActionPrint->setEnabled(true);
|
||||
mUI.mActionPrintPreview->setEnabled(true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MaxRecentProjects + 1; i++) {
|
||||
|
@ -768,6 +775,8 @@ void MainWindow::ClearResults()
|
|||
mUI.mResults->Clear(true);
|
||||
mUI.mActionClearResults->setEnabled(false);
|
||||
mUI.mActionSave->setEnabled(false);
|
||||
mUI.mActionPrint->setEnabled(false);
|
||||
mUI.mActionPrintPreview->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::OpenResults()
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2015 Daniel Marjamäki and Cppcheck team.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "printablereport.h"
|
||||
#include <QDir>
|
||||
|
||||
PrintableReport::PrintableReport() :
|
||||
Report(QString())
|
||||
{
|
||||
}
|
||||
|
||||
PrintableReport::~PrintableReport()
|
||||
{
|
||||
}
|
||||
|
||||
bool PrintableReport::Create()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void PrintableReport::WriteHeader()
|
||||
{
|
||||
// No header for printable report
|
||||
}
|
||||
|
||||
void PrintableReport::WriteFooter()
|
||||
{
|
||||
// No footer for printable report
|
||||
}
|
||||
|
||||
void PrintableReport::WriteError(const ErrorItem &error)
|
||||
{
|
||||
const QString file = QDir::toNativeSeparators(error.files[error.files.size() - 1]);
|
||||
QString line = QString("%1,%2,").arg(file).arg(error.lines[error.lines.size() - 1]);
|
||||
line += QString("%1,%2").arg(GuiSeverity::toString(error.severity)).arg(error.summary);
|
||||
|
||||
mFormattedReport += line;
|
||||
mFormattedReport += "\n";
|
||||
}
|
||||
|
||||
QString PrintableReport::GetFormattedReportText() const
|
||||
{
|
||||
return mFormattedReport;
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2015 Daniel Marjamäki and Cppcheck team.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PRINTABLE_REPORT_H
|
||||
#define PRINTABLE_REPORT_H
|
||||
|
||||
#include "report.h"
|
||||
|
||||
/// @addtogroup GUI
|
||||
/// @{
|
||||
|
||||
|
||||
/**
|
||||
* @brief Printable (in-memory) report.
|
||||
* This report formats results and exposes them for printing.
|
||||
*/
|
||||
class PrintableReport : public Report {
|
||||
public:
|
||||
PrintableReport();
|
||||
virtual ~PrintableReport();
|
||||
|
||||
/**
|
||||
* @brief Create the report (file).
|
||||
* @return true if succeeded, false if file could not be created.
|
||||
*/
|
||||
virtual bool Create();
|
||||
|
||||
/**
|
||||
* @brief Write report header.
|
||||
*/
|
||||
virtual void WriteHeader();
|
||||
|
||||
/**
|
||||
* @brief Write report footer.
|
||||
*/
|
||||
virtual void WriteFooter();
|
||||
|
||||
/**
|
||||
* @brief Write error to report.
|
||||
* @param error Error data.
|
||||
*/
|
||||
virtual void WriteError(const ErrorItem &error);
|
||||
|
||||
/**
|
||||
* @brief Returns the formatted report.
|
||||
*/
|
||||
QString GetFormattedReportText() const;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Stores the formatted report contents.
|
||||
*/
|
||||
QString mFormattedReport;
|
||||
};
|
||||
/// @}
|
||||
#endif // PRINTABLE_REPORT_H
|
|
@ -22,6 +22,9 @@
|
|||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QModelIndex>
|
||||
#include <QPrinter>
|
||||
#include <QPrintDialog>
|
||||
#include <QPrintPreviewDialog>
|
||||
#include <QSettings>
|
||||
#include "common.h"
|
||||
#include "erroritem.h"
|
||||
|
@ -32,6 +35,7 @@
|
|||
#include "xmlreportv1.h"
|
||||
#include "xmlreportv2.h"
|
||||
#include "csvreport.h"
|
||||
#include "printablereport.h"
|
||||
#include "applicationlist.h"
|
||||
#include "checkstatistics.h"
|
||||
|
||||
|
@ -178,6 +182,41 @@ void ResultsView::Save(const QString &filename, Report::Type type) const
|
|||
}
|
||||
}
|
||||
|
||||
void ResultsView::Print()
|
||||
{
|
||||
QPrinter printer;
|
||||
QPrintDialog dialog(&printer, this);
|
||||
dialog.setWindowTitle(tr("Print Report"));
|
||||
if (dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
Print(&printer);
|
||||
}
|
||||
|
||||
void ResultsView::PrintPreview()
|
||||
{
|
||||
QPrinter printer;
|
||||
QPrintPreviewDialog dialog(&printer, this);
|
||||
connect(&dialog, SIGNAL(paintRequested(QPrinter*)), SLOT(Print(QPrinter*)));
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void ResultsView::Print(QPrinter* printer)
|
||||
{
|
||||
if (!mErrorsFound) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("No errors found, nothing to print."));
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
PrintableReport report;
|
||||
mUI.mTree->SaveResults(&report);
|
||||
QTextDocument doc(report.GetFormattedReportText());
|
||||
doc.print(printer);
|
||||
}
|
||||
|
||||
void ResultsView::UpdateSettings(bool showFullPath,
|
||||
bool saveFullPath,
|
||||
bool saveAllErrors,
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
class ErrorItem;
|
||||
class ApplicationList;
|
||||
class QModelIndex;
|
||||
class QPrinter;
|
||||
class QSettings;
|
||||
class CheckStatistics;
|
||||
|
||||
|
@ -222,6 +223,22 @@ public slots:
|
|||
*/
|
||||
void UpdateDetails(const QModelIndex &index);
|
||||
|
||||
/**
|
||||
* @brief Slot opening a print dialog to print the current report
|
||||
*/
|
||||
void Print();
|
||||
|
||||
/**
|
||||
* @brief Slot printing the current report to the printer.
|
||||
* @param printer The printer used for printing the report.
|
||||
*/
|
||||
void Print(QPrinter* printer);
|
||||
|
||||
/**
|
||||
* @brief Slot opening a print preview dialog
|
||||
*/
|
||||
void PrintPreview();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Have any errors been found
|
||||
|
|
Loading…
Reference in New Issue