Skip to content

Commit

Permalink
Merge PR #173 branch 'sprint4/172-generatePdf' of github.com:FACT-Tea…
Browse files Browse the repository at this point in the history
…m/FactDev into S4

Conflicts:
	src/gui/mainwindow/mainwindow.ui
  • Loading branch information
aroquemaurel committed Mar 9, 2015
2 parents 1545edd + e4d431e commit 1fe97dd
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:
- sudo apt-get install g++-4.8 gdb
- sudo apt-get install doxygen doxygen-latex doxygen-doc
- sudo apt-get install -y lcov
# - sudo apt-get install texlive texlive-fonts-extra latex-xcolor texlive-extra-utils texlive-font-utils >> /dev/null
- sudo apt-get install texlive texlive-fonts-extra latex-xcolor texlive-extra-utils texlive-font-utils >> /dev/null
- wget -O Qt5.2.0.tar.xz https://www.dropbox.com/s/mkqtb8teeydsmrk/Qt5.2.0.tar.xz?dl=0
- mkdir ~/Qt5.2.0
- tar -xJf Qt5.2.0.tar.xz -C ~/Qt5.2.0
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cd ..
echo "#### COMPILATION ####"
~/Qt5.2.0/5.2.0/gcc_64/bin/qmake FactDev.pro -r -spec linux-g++ CONFIG+=debug >> /dev/null
make -j15 >> /dev/null
make -j9 >> /dev/null
LD_LIBRARY_PATH=`pwd`/src
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
ln -s `pwd`/src/sql `pwd`/tests/sql
Expand Down
23 changes: 23 additions & 0 deletions src/generator/pdfgenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "pdfgenerator.h"

namespace Generator {
PdfGenerator::PdfGenerator(QString pdflatexPath)
{
_pdflatexPath = pdflatexPath;
}

void PdfGenerator::generate(QString inputDir, QString filename)
{
QProcess process;
process.setWorkingDirectory(inputDir);
QStringList args;
args << filename+".tex";
process.start(_pdflatexPath, args);
process.waitForFinished();


QFile(inputDir+"/"+filename+".aux").remove();
QFile(inputDir+"/"+filename+".log").remove();
}

}
17 changes: 17 additions & 0 deletions src/generator/pdfgenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef PDFGENERATOR_H
#define PDFGENERATOR_H
#include <QString>
#include <QProcess>
#include <QFile>

namespace Generator {
class PdfGenerator
{
public:
PdfGenerator(QString pdflatexPath="pdflatex");
void generate(QString inputDir, QString filename);
private:
QString _pdflatexPath;
};
}
#endif // PDFGENERATOR_H
12 changes: 6 additions & 6 deletions src/generator.cpp → src/generator/texgenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "generator.h"
#include "generator/texgenerator.h"


Generator::Generator(QString tpl)
namespace Generator {
TexGenerator::TexGenerator(QString tpl)
{
_tplFile = tpl;
}

Generator::~Generator()
TexGenerator::~TexGenerator()
{

}

void Generator::generate(QVariantHash data, QString path)
void TexGenerator::generate(QVariantHash data, QString path)
{
QString ret;

Expand All @@ -36,4 +36,4 @@ void Generator::generate(QVariantHash data, QString path)
}
}


}
15 changes: 9 additions & 6 deletions src/generator.h → src/generator/texgenerator.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#ifndef GENERATOR_H
#define GENERATOR_H
#ifndef TEXGENERATOR_H
#define TEXGENERATOR_H

#include "models/billing.h"
#include "models/user.h"

#include "libs/qt-mustache/src/mustache.h"

class Generator
namespace Generator {
class TexGenerator
{
public:
Generator(QString tpl);
~Generator();
TexGenerator(QString tpl);
~TexGenerator();

void generate(QVariantHash data, QString path);

private:
QString _tplFile;
};

#endif // GENERATOR_H
}
#endif // TEXGENERATOR_H
3 changes: 2 additions & 1 deletion src/gui/dialogs/addquotedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void AddQuoteDialog::accept() {
_quote->setContributories(*((Widgets::ContributoriesWidget*)ui->wdgContributories)->getContributories());

_quote->commit();
_quote->generateTex();
_quote->generatePdf();

QDialog::accept();
}

Expand Down
13 changes: 10 additions & 3 deletions src/gui/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,18 @@ void MainWindow::removeDoc() {
removeItem(ui->tblQuotes, ItemType(ItemType::BILLING, "document"));
}

void MainWindow::generateTex()
void MainWindow::openPdf()
{
QModelIndex ls = ui->tblQuotes->selectionModel()->selectedRows().first();
int pid = ui->tblQuotes->model()->data(ls, Qt::DisplayRole).toInt();
Billing(pid).generateTex();
Billing bill(pid);
if(!QFile(bill.getPath()+".pdf").exists()) {
bill.generatePdf();
}
QFileInfo pdf(bill.getPath()+".pdf");

QDesktopServices::openUrl(QUrl("file:///"+pdf.absoluteFilePath()));

}

void MainWindow::search(QString text)
Expand Down Expand Up @@ -572,7 +579,7 @@ void MainWindow::updateButtons()
ui->wdgTblProjectsToolBar->updateBtn(canAdd);
ui->btnRemoveDoc->setEnabled(billingIsSelected);
ui->btnEditDoc->setEnabled(billingIsSelected);
ui->btnLatex->setEnabled(billingIsSelected);
ui->btnPdf->setEnabled(billingIsSelected);

if (billingIsSelected) {

Expand Down
4 changes: 3 additions & 1 deletion src/gui/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <QModelIndex>
#include <QTableView>
#include <QDir>
#include <QDesktopServices>
#include <QUrl>

#include "utils/itemtype.h"
#include "utils/log.h"
Expand Down Expand Up @@ -189,7 +191,7 @@ public slots:
*/
//void editQuote();

void generateTex();
void openPdf();
private slots:
/**
* @brief MainWindow::openContextualMenuTable open contextual menu
Expand Down
64 changes: 32 additions & 32 deletions src/gui/mainwindow/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="btnLatex">
<widget class="QPushButton" name="btnPdf">
<property name="text">
<string>Générer en LaTeX</string>
<string>Ouvrir le PDF</string>
</property>
<property name="icon">
<iconset resource="../../icons.qrc">
<normaloff>:/icons/img/convert_to_latex.png</normaloff>:/icons/img/convert_to_latex.png</iconset>
<normaloff>:/icons/img/convert_to_pdf.png</normaloff>:/icons/img/convert_to_pdf.png</iconset>
</property>
</widget>
</item>
Expand Down Expand Up @@ -704,8 +704,8 @@
<slot>editCustomer()</slot>
<hints>
<hint type="sourcelabel">
<x>910</x>
<y>543</y>
<x>367</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>764</x>
Expand All @@ -720,8 +720,8 @@
<slot>removeCustomer()</slot>
<hints>
<hint type="sourcelabel">
<x>823</x>
<y>543</y>
<x>348</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>280</x>
Expand All @@ -736,8 +736,8 @@
<slot>addCustomer()</slot>
<hints>
<hint type="sourcelabel">
<x>599</x>
<y>543</y>
<x>311</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>406</x>
Expand All @@ -752,8 +752,8 @@
<slot>addProject()</slot>
<hints>
<hint type="sourcelabel">
<x>726</x>
<y>543</y>
<x>330</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>720</x>
Expand Down Expand Up @@ -880,8 +880,8 @@
<slot>customersTableToProjectsTable()</slot>
<hints>
<hint type="sourcelabel">
<x>378</x>
<y>108</y>
<x>373</x>
<y>96</y>
</hint>
<hint type="destinationlabel">
<x>1026</x>
Expand All @@ -896,8 +896,8 @@
<slot>backToCustomersTable()</slot>
<hints>
<hint type="sourcelabel">
<x>332</x>
<y>106</y>
<x>327</x>
<y>93</y>
</hint>
<hint type="destinationlabel">
<x>326</x>
Expand Down Expand Up @@ -928,8 +928,8 @@
<slot>projectsTableToDocsTable()</slot>
<hints>
<hint type="sourcelabel">
<x>379</x>
<y>146</y>
<x>374</x>
<y>99</y>
</hint>
<hint type="destinationlabel">
<x>920</x>
Expand All @@ -944,8 +944,8 @@
<slot>backToProjectsTable()</slot>
<hints>
<hint type="sourcelabel">
<x>578</x>
<y>121</y>
<x>583</x>
<y>119</y>
</hint>
<hint type="destinationlabel">
<x>672</x>
Expand All @@ -960,8 +960,8 @@
<slot>addProject()</slot>
<hints>
<hint type="sourcelabel">
<x>916</x>
<y>539</y>
<x>499</x>
<y>130</y>
</hint>
<hint type="destinationlabel">
<x>797</x>
Expand All @@ -976,8 +976,8 @@
<slot>editProject()</slot>
<hints>
<hint type="sourcelabel">
<x>916</x>
<y>539</y>
<x>499</x>
<y>130</y>
</hint>
<hint type="destinationlabel">
<x>738</x>
Expand All @@ -992,8 +992,8 @@
<slot>removeProject()</slot>
<hints>
<hint type="sourcelabel">
<x>916</x>
<y>539</y>
<x>499</x>
<y>130</y>
</hint>
<hint type="destinationlabel">
<x>0</x>
Expand All @@ -1008,8 +1008,8 @@
<slot>changeCustomerTable()</slot>
<hints>
<hint type="sourcelabel">
<x>378</x>
<y>108</y>
<x>373</x>
<y>96</y>
</hint>
<hint type="destinationlabel">
<x>415</x>
Expand All @@ -1024,8 +1024,8 @@
<slot>changeProjectsTable()</slot>
<hints>
<hint type="sourcelabel">
<x>379</x>
<y>146</y>
<x>374</x>
<y>99</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
Expand Down Expand Up @@ -1130,10 +1130,10 @@
</hints>
</connection>
<connection>
<sender>btnLatex</sender>
<sender>btnPdf</sender>
<signal>released()</signal>
<receiver>MainWindow</receiver>
<slot>generateTex()</slot>
<slot>openPdf()</slot>
<hints>
<hint type="sourcelabel">
<x>828</x>
Expand Down Expand Up @@ -1225,7 +1225,7 @@
<slot>changeDocsTable()</slot>
<slot>editQuote()</slot>
<slot>updateButtons()</slot>
<slot>generateTex()</slot>
<slot>openPdf()</slot>
<slot>billingIsPaid()</slot>
</slots>
</ui>
Loading

0 comments on commit 1fe97dd

Please sign in to comment.