.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <QFontMetrics>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
@@ -278,15 +280,74 @@ void cDistributorWindow::exportList(const QString& szFileName)
|
||||
void cDistributorWindow::writeXLSX(const QString& szFileName)
|
||||
{
|
||||
QXlsx::Document xlsx;
|
||||
QXlsx::Format fmt;
|
||||
fmt.setFontBold(true);
|
||||
xlsx.write(1, 1, "empty");
|
||||
xlsx.write(2, 1, "empty", fmt);
|
||||
QFont font = xlsx.cellAt(1, 1)->format().font();
|
||||
QFont fontBold = xlsx.cellAt(2, 1)->format().font();
|
||||
fmt.setFontBold(false);
|
||||
xlsx.write(1, 1, "");
|
||||
xlsx.write(2, 1, "", fmt);
|
||||
|
||||
qint16 iHeight = 0;
|
||||
qreal dName = 0;
|
||||
qreal dPhone = 0;
|
||||
qreal dFax = 0;
|
||||
qreal dEmail = 0;
|
||||
qreal dAddress = 0;
|
||||
qreal dPostal = 0;
|
||||
qreal dCity = 0;
|
||||
qreal dCountry = 0;
|
||||
qreal dLink = 0;
|
||||
qreal dDescription = 0;
|
||||
|
||||
writeXLSXLine(xlsx, 1, tr("Name"), tr("Phone"), tr("Fax"), tr("Email"), tr("address"), tr("postal"), tr("city"), tr("country"), tr("link"), tr("description"));
|
||||
|
||||
metrics(fontBold, dName, iHeight, tr("Name"));
|
||||
metrics(fontBold, dPhone, iHeight, tr("Phone"));
|
||||
metrics(fontBold, dFax, iHeight, tr("Fax"));
|
||||
metrics(fontBold, dEmail, iHeight, tr("Email"));
|
||||
metrics(fontBold, dAddress, iHeight, tr("address"));
|
||||
metrics(fontBold, dPostal, iHeight, tr("postal"));
|
||||
metrics(fontBold, dCity, iHeight, tr("city"));
|
||||
metrics(fontBold, dCountry, iHeight, tr("country"));
|
||||
metrics(fontBold, dLink, iHeight, tr("link"));
|
||||
metrics(fontBold, dDescription, iHeight, tr("description"));
|
||||
xlsx.setRowHeight(1, iHeight);
|
||||
|
||||
for(int x = 0;x < m_lpDistributorList->count();x++)
|
||||
{
|
||||
iHeight = 0;
|
||||
|
||||
cDistributor* lpDistributor = m_lpDistributorList->at(x);
|
||||
writeXLSXLine(xlsx, x+2, lpDistributor->name(), lpDistributor->phone(), lpDistributor->fax(), lpDistributor->eMail(), lpDistributor->address(), QString::number(lpDistributor->postalCode()), lpDistributor->city(), lpDistributor->country(), lpDistributor->link(), lpDistributor->description());
|
||||
|
||||
metrics(font, dName, iHeight, lpDistributor->name());
|
||||
metrics(font, dPhone, iHeight, lpDistributor->phone());
|
||||
metrics(font, dFax, iHeight, lpDistributor->fax());
|
||||
metrics(font, dEmail, iHeight, lpDistributor->eMail());
|
||||
metrics(font, dAddress, iHeight, lpDistributor->address());
|
||||
metrics(font, dPostal, iHeight, QString::number(lpDistributor->postalCode()));
|
||||
metrics(font, dCity, iHeight, lpDistributor->city());
|
||||
metrics(font, dCountry, iHeight, lpDistributor->country());
|
||||
metrics(font, dLink, iHeight, lpDistributor->link());
|
||||
metrics(font, dDescription, iHeight, lpDistributor->description());
|
||||
|
||||
xlsx.setRowHeight(x+2, iHeight);
|
||||
}
|
||||
|
||||
xlsx.setColumnWidth( 1, dName*1.2);
|
||||
xlsx.setColumnWidth( 2, dPhone*1.2);
|
||||
xlsx.setColumnWidth( 3, dFax*1.2);
|
||||
xlsx.setColumnWidth( 4, dEmail*1.2);
|
||||
xlsx.setColumnWidth( 5, dAddress*1.2);
|
||||
xlsx.setColumnWidth( 6, dPostal*1.2);
|
||||
xlsx.setColumnWidth( 7, dCity*1.2);
|
||||
xlsx.setColumnWidth( 8, dCountry*1.2);
|
||||
xlsx.setColumnWidth( 9, dLink*1.2);
|
||||
xlsx.setColumnWidth(10, dDescription*1.2);
|
||||
|
||||
xlsx.saveAs(szFileName);
|
||||
}
|
||||
|
||||
|
||||
+68
-5
@@ -451,6 +451,26 @@ void cMainWindow::onMenuFileExport()
|
||||
QStringList szIDList;
|
||||
QMap<int, int>::const_iterator i;
|
||||
QXlsx::Document xlsx;
|
||||
QXlsx::Format fmt;
|
||||
fmt.setFontBold(true);
|
||||
xlsx.write(1, 1, "empty");
|
||||
xlsx.write(2, 1, "empty", fmt);
|
||||
QFont font = xlsx.cellAt(1, 1)->format().font();
|
||||
QFont fontBold = xlsx.cellAt(2, 1)->format().font();
|
||||
fmt.setFontBold(false);
|
||||
xlsx.write(1, 1, "");
|
||||
xlsx.write(2, 1, "", fmt);
|
||||
|
||||
qint16 iHeight = 0;
|
||||
qreal dCount = 0;
|
||||
qreal dGroup = 0;
|
||||
qreal dPart = 0;
|
||||
qreal dDescription = 0;
|
||||
qreal dDistributor = 0;
|
||||
qreal dSKU = 0;
|
||||
qreal dState = 0;
|
||||
qreal dPrice = 0;
|
||||
qreal dProject = 0;
|
||||
|
||||
qint32 iLine = 1;
|
||||
|
||||
@@ -465,6 +485,16 @@ void cMainWindow::onMenuFileExport()
|
||||
xlsx.write(iLine, 7, tr("state"), format);
|
||||
xlsx.write(iLine, 8, tr("price"), format);
|
||||
xlsx.write(iLine, 9, tr("project"), format);
|
||||
|
||||
metrics(fontBold, dCount, iHeight, tr("Count"));
|
||||
metrics(fontBold, dGroup, iHeight, tr("Group"));
|
||||
metrics(fontBold, dPart, iHeight, tr("Part"));
|
||||
metrics(fontBold, dDescription, iHeight, tr("Description"));
|
||||
metrics(fontBold, dDistributor, iHeight, tr("Distributor"));
|
||||
metrics(fontBold, dSKU, iHeight, tr("SKU"));
|
||||
metrics(fontBold, dState, iHeight, tr("State"));
|
||||
metrics(fontBold, dPrice, iHeight, tr("Price"));
|
||||
metrics(fontBold, dProject, iHeight, tr("Project"));
|
||||
}
|
||||
|
||||
iLine++;
|
||||
@@ -518,7 +548,7 @@ void cMainWindow::onMenuFileExport()
|
||||
QString szDescription;
|
||||
QString szPartDistributorName;
|
||||
qint32 iCount;
|
||||
qreal dPrice;
|
||||
qreal dOrderPrice;
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
@@ -544,8 +574,19 @@ void cMainWindow::onMenuFileExport()
|
||||
xlsx.write(iLine, 5, szOldDistributor);
|
||||
xlsx.write(iLine, 6, szPartDistributorName);
|
||||
xlsx.write(iLine, 7, szOldState);
|
||||
xlsx.write(iLine, 8, dPrice, formatCurrency);
|
||||
xlsx.write(iLine, 8, dOrderPrice, formatCurrency);
|
||||
xlsx.write(iLine, 9, szPartlist.join("\n"), formatWrap);
|
||||
|
||||
metrics(font, dCount, iHeight, QString::number(iCount));
|
||||
metrics(font, dGroup, iHeight, szOldGroup);
|
||||
metrics(font, dPart, iHeight, szOldPart);
|
||||
metrics(font, dDescription, iHeight, szDescription);
|
||||
metrics(font, dDistributor, iHeight, szOldDistributor);
|
||||
metrics(font, dSKU, iHeight, szPartDistributorName);
|
||||
metrics(font, dState, iHeight, szOldState);
|
||||
metrics(font, dPrice, iHeight, QString("€ ") + QString::number(dOrderPrice, 'f', 2));
|
||||
metrics(font, dProject, iHeight, szPartlist.join("\n"));
|
||||
|
||||
iLine++;
|
||||
}
|
||||
}
|
||||
@@ -555,16 +596,16 @@ void cMainWindow::onMenuFileExport()
|
||||
szOldPart = query.value("partName").toString();
|
||||
szOldDistributor = query.value("distributorName").toString();
|
||||
szOldState = cPartlistItem::stateString((cPartlistItem::STATE)query.value("partlistitemState").toInt());
|
||||
szPartlist.append(query.value("partlistName").toString());
|
||||
szPartlist.append(QString("%1 (%2)").arg(query.value("partlistName").toString()).arg(query.value("partlistitemReference").toString().split(", ").count()));
|
||||
iCount = query.value("partlistitemReference").toString().split(", ").count() * list.find(query.value("partlistID").toInt()).value();
|
||||
dPrice = query.value("partdistributorPrice").toDouble();
|
||||
dOrderPrice = query.value("partdistributorPrice").toDouble();
|
||||
szDescription = query.value("partDescription").toString();
|
||||
szPartDistributorName = query.value("partdistributorName").toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!szPartlist.contains(query.value("partlistName").toString()))
|
||||
szPartlist.append(query.value("partlistName").toString());
|
||||
szPartlist.append(QString("%1 (%2)").arg(query.value("partlistName").toString()).arg(query.value("partlistitemReference").toString().split(", ").count()));
|
||||
iCount += query.value("partlistitemReference").toString().split(", ").count();
|
||||
}
|
||||
}
|
||||
@@ -582,11 +623,33 @@ void cMainWindow::onMenuFileExport()
|
||||
xlsx.write(iLine, 7, szOldState);
|
||||
xlsx.write(iLine, 8, dPrice, formatCurrency);
|
||||
xlsx.write(iLine, 9, szPartlist.join("\n"), formatWrap);
|
||||
|
||||
metrics(font, dCount, iHeight, QString::number(iCount));
|
||||
metrics(font, dGroup, iHeight, szOldGroup);
|
||||
metrics(font, dPart, iHeight, szOldPart);
|
||||
metrics(font, dDescription, iHeight, szDescription);
|
||||
metrics(font, dDistributor, iHeight, szOldDistributor);
|
||||
metrics(font, dSKU, iHeight, szPartDistributorName);
|
||||
metrics(font, dState, iHeight, szOldState);
|
||||
metrics(font, dPrice, iHeight, QString("€ ") + QString::number(dOrderPrice, 'f', 2));
|
||||
metrics(font, dProject, iHeight, szPartlist.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
if(bXLSX)
|
||||
{
|
||||
xlsx.setColumnWidth( 1, dCount*1.2);
|
||||
xlsx.setColumnWidth( 2, dGroup*1.2);
|
||||
xlsx.setColumnWidth( 3, dPart*1.2);
|
||||
xlsx.setColumnWidth( 4, dDescription*1.2);
|
||||
xlsx.setColumnWidth( 5, dDistributor*1.2);
|
||||
xlsx.setColumnWidth( 6, dSKU*1.2);
|
||||
xlsx.setColumnWidth( 7, dState*1.2);
|
||||
xlsx.setColumnWidth( 8, dPrice*1.2);
|
||||
xlsx.setColumnWidth( 9, dProject*1.2);
|
||||
|
||||
xlsx.saveAs(szFileName);
|
||||
}
|
||||
}
|
||||
|
||||
void cMainWindow::onMenuFileClose()
|
||||
|
||||
+17
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
#include <QFontMetrics>
|
||||
|
||||
|
||||
QString rootPath()
|
||||
@@ -19,3 +20,19 @@ QString rootPath()
|
||||
|
||||
return(szPath);
|
||||
}
|
||||
|
||||
void metrics(const QFont& font, qreal &dWidth, qint16 &iHeight, const QString& text)
|
||||
{
|
||||
QFontMetrics metrics(font);
|
||||
QSize newSize = metrics.boundingRect(text).size();
|
||||
|
||||
if(newSize.height() > iHeight)
|
||||
iHeight = newSize.height();
|
||||
|
||||
qint32 dW = (qreal)metrics.boundingRect("1111111111").width()/10*8.43;
|
||||
qint32 w = newSize.width();
|
||||
qreal newWidth = 8.43/dW*(qreal)w;
|
||||
|
||||
if(newWidth > dWidth)
|
||||
dWidth = newWidth;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
#define myDebug qDebug() << __FILE__ << "(" << __LINE__ << ") - " << __PRETTY_FUNCTION__ << ":"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <QSize>
|
||||
#include <QFont>
|
||||
|
||||
QString rootPath();
|
||||
void metrics(const QFont& font, qreal& dWidth, qint16& iHeight, const QString& text);
|
||||
|
||||
|
||||
#endif // COMMON_H
|
||||
|
||||
@@ -708,6 +708,26 @@ void cPartlistWindow::exportList(const QString& szFileName)
|
||||
void cPartlistWindow::writeXLSX(const QString& szFileName)
|
||||
{
|
||||
QXlsx::Document xlsx;
|
||||
QXlsx::Format fmt;
|
||||
fmt.setFontBold(true);
|
||||
xlsx.write(1, 1, "empty");
|
||||
xlsx.write(2, 1, "empty", fmt);
|
||||
QFont font = xlsx.cellAt(1, 1)->format().font();
|
||||
QFont fontBold = xlsx.cellAt(2, 1)->format().font();
|
||||
fmt.setFontBold(false);
|
||||
xlsx.write(1, 1, "");
|
||||
xlsx.write(2, 1, "", fmt);
|
||||
|
||||
qint16 iHeight = 0;
|
||||
qreal dReference = 0;
|
||||
qreal dCount = 0;
|
||||
qreal dGroup = 0;
|
||||
qreal dPart = 0;
|
||||
qreal dDistributor = 0;
|
||||
qreal dState = 0;
|
||||
qreal dPrice = 0;
|
||||
qreal dDescription = 0;
|
||||
|
||||
QXlsx::Format format;
|
||||
QXlsx::Format formatBig;
|
||||
QXlsx::Format formatMerged;
|
||||
@@ -736,6 +756,15 @@ void cPartlistWindow::writeXLSX(const QString& szFileName)
|
||||
xlsx.write(4, 7, tr("price"), format);
|
||||
xlsx.write(4, 8, tr("description"), format);
|
||||
|
||||
metrics(fontBold, dReference, iHeight, tr("reference"));
|
||||
metrics(fontBold, dCount, iHeight, tr("count"));
|
||||
metrics(fontBold, dGroup, iHeight, tr("group"));
|
||||
metrics(fontBold, dPart, iHeight, tr("part"));
|
||||
metrics(fontBold, dDistributor, iHeight, tr("distributor"));
|
||||
metrics(fontBold, dState, iHeight, tr("state"));
|
||||
metrics(fontBold, dPrice, iHeight, tr("price"));
|
||||
metrics(fontBold, dDescription, iHeight, tr("description"));
|
||||
|
||||
cPartlistItemList list = itemList(true);
|
||||
|
||||
for(int x = 0;x < list.count();x++)
|
||||
@@ -753,8 +782,29 @@ void cPartlistWindow::writeXLSX(const QString& szFileName)
|
||||
xlsx.write(x+5, 6, lpItem->stateString());
|
||||
xlsx.write(x+5, 7, lpItem->price(), formatCurrency);
|
||||
xlsx.write(x+5, 8, lpItem->description());
|
||||
|
||||
metrics(font, dReference, iHeight, lpItem->reference());
|
||||
metrics(font, dCount, iHeight, QString::number(lpItem->reference().split(", ").count()));
|
||||
metrics(font, dGroup, iHeight, lpPart->partGroup()->name());
|
||||
metrics(font, dPart, iHeight, lpPart->name());
|
||||
if(lpDistributor)
|
||||
metrics(font, dDistributor, iHeight, lpDistributor->name());
|
||||
metrics(font, dState, iHeight, lpItem->stateString());
|
||||
metrics(font, dPrice, iHeight, QString("€ ") + QString::number(lpItem->price(), 'f', 2));
|
||||
metrics(font, dDescription, iHeight, lpItem->description());
|
||||
}
|
||||
|
||||
if(dReference > 25)
|
||||
dReference = 50;
|
||||
xlsx.setColumnWidth( 1, dReference*1.2);
|
||||
xlsx.setColumnWidth( 2, dCount*1.2);
|
||||
xlsx.setColumnWidth( 3, dGroup*1.2);
|
||||
xlsx.setColumnWidth( 4, dPart*1.2);
|
||||
xlsx.setColumnWidth( 5, dDistributor*1.2);
|
||||
xlsx.setColumnWidth( 6, dState*1.2);
|
||||
xlsx.setColumnWidth( 7, dPrice*1.2);
|
||||
xlsx.setColumnWidth( 8, dDescription*1.2);
|
||||
|
||||
xlsx.saveAs(szFileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +310,25 @@ void cPartWindow::exportList(const QString& szFileName)
|
||||
void cPartWindow::writeXLSX(const QString& szFileName)
|
||||
{
|
||||
QXlsx::Document xlsx;
|
||||
QXlsx::Format fmt;
|
||||
fmt.setFontBold(true);
|
||||
xlsx.write(1, 1, "empty");
|
||||
xlsx.write(2, 1, "empty", fmt);
|
||||
QFont font = xlsx.cellAt(1, 1)->format().font();
|
||||
QFont fontBold = xlsx.cellAt(2, 1)->format().font();
|
||||
fmt.setFontBold(false);
|
||||
xlsx.write(1, 1, "");
|
||||
xlsx.write(2, 1, "", fmt);
|
||||
|
||||
qint16 iHeight = 0;
|
||||
qreal dGroup = 0;
|
||||
qreal dName = 0;
|
||||
qreal dDescription = 0;
|
||||
qreal dLink = 0;
|
||||
qreal dDistributor = 0;
|
||||
qreal dPartName = 0;
|
||||
qreal dPrice = 0;
|
||||
|
||||
qint32 iLine = 1;
|
||||
QXlsx::Format format;
|
||||
QXlsx::Format formatMerged;
|
||||
@@ -330,6 +349,14 @@ void cPartWindow::writeXLSX(const QString& szFileName)
|
||||
xlsx.write(iLine, 5, tr("Distributor"), format);
|
||||
xlsx.write(iLine, 6, tr("Part Name"), format);
|
||||
xlsx.write(iLine, 7, tr("Price"), format);
|
||||
|
||||
metrics(fontBold, dGroup, iHeight, tr("Group"));
|
||||
metrics(fontBold, dName, iHeight, tr("Name"));
|
||||
metrics(fontBold, dDescription, iHeight, tr("Description"));
|
||||
metrics(fontBold, dLink, iHeight, tr("Link"));
|
||||
metrics(fontBold, dDistributor, iHeight, tr("Distributor"));
|
||||
metrics(fontBold, dPartName, iHeight, tr("Part Name"));
|
||||
metrics(fontBold, dPrice, iHeight, tr("Price"));
|
||||
iLine++;
|
||||
|
||||
for(int x = 0;x < m_lpPartList->count();x++)
|
||||
@@ -341,6 +368,11 @@ void cPartWindow::writeXLSX(const QString& szFileName)
|
||||
xlsx.write(iLine, 3, lpPart->description());
|
||||
xlsx.write(iLine, 4, lpPart->link());
|
||||
|
||||
metrics(font, dGroup, iHeight, lpPart->partGroup()->name());
|
||||
metrics(font, dName, iHeight, lpPart->name());
|
||||
metrics(font, dDescription, iHeight, lpPart->description());
|
||||
metrics(font, dLink, iHeight, lpPart->link());
|
||||
|
||||
qint32 iLineTemp = 0;
|
||||
for(int y = 0;y < m_lpPartDistributorList->count();y++)
|
||||
{
|
||||
@@ -351,6 +383,11 @@ void cPartWindow::writeXLSX(const QString& szFileName)
|
||||
xlsx.write(iLine+iLineTemp, 5, lpPartDistributor->distributor()->name());
|
||||
xlsx.write(iLine+iLineTemp, 6, lpPartDistributor->name());
|
||||
xlsx.write(iLine+iLineTemp, 7, lpPartDistributor->price(), formatCurrency);
|
||||
|
||||
metrics(font, dDistributor, iHeight, lpPartDistributor->distributor()->name());
|
||||
metrics(font, dPartName, iHeight, lpPartDistributor->name());
|
||||
metrics(font, dPrice, iHeight, QString("€ ") + QString::number(lpPartDistributor->price(), 'f', 2));
|
||||
|
||||
iLineTemp++;
|
||||
}
|
||||
}
|
||||
@@ -366,6 +403,14 @@ void cPartWindow::writeXLSX(const QString& szFileName)
|
||||
iLine++;
|
||||
}
|
||||
|
||||
xlsx.setColumnWidth( 1, dGroup*1.2);
|
||||
xlsx.setColumnWidth( 2, dName*1.2);
|
||||
xlsx.setColumnWidth( 3, dDescription*1.2);
|
||||
xlsx.setColumnWidth( 4, dLink*1.2);
|
||||
xlsx.setColumnWidth( 5, dDistributor*1.2);
|
||||
xlsx.setColumnWidth( 6, dPartName*1.2);
|
||||
xlsx.setColumnWidth( 7, dPrice*1.2);
|
||||
|
||||
xlsx.saveAs(szFileName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user