Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modern CMakeLists.txt #196

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
cmake_minimum_required(VERSION 3.0)
project(xlsx CXX)

set(libname xlsx)

message(STATUS ${CMAKE_CURRENT_LIST_FILE})

find_package(Qt5 CONFIG REQUIRED COMPONENTS Gui)
set(CMAKE_AUTOMOC ON)

set(qxlsx_includes
${CMAKE_CURRENT_SOURCE_DIR}/src/xlsx
${Qt5Gui_INCLUDE_DIRS}
)

# come up with private incudes
# https://bugreports.qt.io/browse/QTBUG-37417
foreach(module Gui)
set(qt_module Qt${module})
set(qt5_module Qt5${module})
find_package(${qt5_module})
if("${${qt5_module}_PRIVATE_INCLUDE_DIRS}" STREQUAL "")
foreach(base_dir ${${qt5_module}_INCLUDE_DIRS})
if("${base_dir}" MATCHES "/${qt_module}\$")
list(APPEND ${qt5_module}_PRIVATE_INCLUDE_DIRS "${base_dir}/${${qt5_module}_VERSION}/${qt_module}")
endif()
endforeach()
endif()
list(APPEND qxlsx_includes ${${qt5_module}_PRIVATE_INCLUDE_DIRS})
endforeach()
message("INC=${qxlsx_includes}")

# get header files that are not *_p.h
file(GLOB tmp_hdr ${CMAKE_CURRENT_SOURCE_DIR}/src/xlsx/*.h)
foreach(hdr_file ${tmp_hdr})
string(REGEX MATCH ".*_p.h" hdr_match ${hdr_file})
if ("${hdr_match}" STREQUAL "")
list(APPEND hdrs ${hdr_file})
endif()
endforeach()

add_library(${libname} SHARED)
target_link_libraries(${libname} Qt5::Gui)
target_include_directories(${libname} PRIVATE ${qxlsx_includes})
set_target_properties(${libname} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
if (UNIX)
# force linker to resolve all deps
set_target_properties(${libname} PROPERTIES LINK_FLAGS "-Wl,--no-undefined")
endif (UNIX)

target_sources(${libname} PRIVATE
src/xlsx/xlsxabstractooxmlfile.cpp
src/xlsx/xlsxabstractsheet.cpp
src/xlsx/xlsxcell.cpp
src/xlsx/xlsxcellformula.cpp
src/xlsx/xlsxcellrange.cpp
src/xlsx/xlsxcellreference.cpp
src/xlsx/xlsxchart.cpp
src/xlsx/xlsxchartsheet.cpp
src/xlsx/xlsxcolor.cpp
src/xlsx/xlsxconditionalformatting.cpp
src/xlsx/xlsxcontenttypes.cpp
src/xlsx/xlsxdatavalidation.cpp
src/xlsx/xlsxdocpropsapp.cpp
src/xlsx/xlsxdocpropscore.cpp
src/xlsx/xlsxdocument.cpp
src/xlsx/xlsxdrawing.cpp
src/xlsx/xlsxdrawinganchor.cpp
src/xlsx/xlsxformat.cpp
src/xlsx/xlsxmediafile.cpp
src/xlsx/xlsxnumformatparser.cpp
src/xlsx/xlsxrelationships.cpp
src/xlsx/xlsxrichstring.cpp
src/xlsx/xlsxsharedstrings.cpp
src/xlsx/xlsxsimpleooxmlfile.cpp
src/xlsx/xlsxstyles.cpp
src/xlsx/xlsxtheme.cpp
src/xlsx/xlsxutility.cpp
src/xlsx/xlsxworkbook.cpp
src/xlsx/xlsxworksheet.cpp
src/xlsx/xlsxzipreader.cpp
src/xlsx/xlsxzipwriter.cpp

${hdrs}
)

# libraries
install(
TARGETS ${libname}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)

install(
FILES ${hdrs}
DESTINATION include/${libname}
)
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MIT License

Copyright (c) 2013-2014 Debao Zhang <[email protected]>
All right reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

25 changes: 25 additions & 0 deletions _clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BasedOnStyle: WebKit
Standard: Cpp11
ColumnLimit: 100
PointerBindsToType: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
AlignAfterOpenBracket: true
AlwaysBreakTemplateDeclarations: true
AllowShortFunctionsOnASingleLine: InlineOnly
NamespaceIndentation: None
SortIncludes: false
ForEachMacros: [ forever, foreach, Q_FOREACH, BOOST_FOREACH ]

4 changes: 4 additions & 0 deletions examples/xlsx/calendar/calendar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/calendar
INSTALLS += target
47 changes: 23 additions & 24 deletions examples/xlsx/calendar/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

//Select a proper locale
//QLocale::setDefault(QLocale(QLocale::English));
// Select a proper locale
// QLocale::setDefault(QLocale(QLocale::English));

Document xlsx;
QDate today(QDate::currentDate());
for (int month=1; month<=12; ++month) {
for (int month = 1; month <= 12; ++month) {
xlsx.addSheet(QLocale().monthName(month));
xlsx.currentWorksheet()->setGridLinesVisible(false);

//the header row
// the header row
Format headerStyle;
headerStyle.setFontSize(48);
headerStyle.setFontColor(Qt::darkBlue);
Expand All @@ -29,8 +29,8 @@ int main(int argc, char **argv)
xlsx.write("A1", QString("%1 %2").arg(QLocale().monthName(month)).arg(today.year()));
xlsx.mergeCells("A1:N1", headerStyle);

//header with month titles
for (int day=1; day<=7; ++day) {
// header with month titles
for (int day = 1; day <= 7; ++day) {
Format monthStyle;
monthStyle.setFontSize(12);
monthStyle.setFontColor(Qt::white);
Expand All @@ -40,10 +40,10 @@ int main(int argc, char **argv)
monthStyle.setFillPattern(Format::PatternSolid);
monthStyle.setPatternBackgroundColor(Qt::darkBlue);

xlsx.setColumnWidth(day*2-1, day*2-1, 5);
xlsx.setColumnWidth(day*2, day*2, 13);
xlsx.write(2, day*2-1, QLocale().dayName(day));
xlsx.mergeCells(CellRange(2, day*2-1, 2, day*2), monthStyle);
xlsx.setColumnWidth(day * 2 - 1, day * 2 - 1, 5);
xlsx.setColumnWidth(day * 2, day * 2, 13);
xlsx.write(2, day * 2 - 1, QLocale().dayName(day));
xlsx.mergeCells(CellRange(2, day * 2 - 1, 2, day * 2), monthStyle);
}

QColor borderColor = QColor(Qt::gray);
Expand Down Expand Up @@ -101,43 +101,42 @@ int main(int argc, char **argv)
greyRightStyle.setBottomBorderColor(borderColor);

int rownum = 3;
for (int day=1; day<=31; ++day) {
for (int day = 1; day <= 31; ++day) {
QDate date(today.year(), month, day);
if (!date.isValid())
break;
xlsx.setRowHeight(rownum, 100);
int dow = date.dayOfWeek();
int colnum = dow*2-1;
int colnum = dow * 2 - 1;

if (dow <= 5) {
xlsx.write(rownum, colnum, day, workdayLeftStyle);
xlsx.write(rownum, colnum+1, QVariant(), workdayRightStyle);
xlsx.write(rownum, colnum + 1, QVariant(), workdayRightStyle);
} else {
xlsx.write(rownum, colnum, day, weekendLeftStyle);
xlsx.write(rownum, colnum+1, QVariant(), weekendRightStyle);
xlsx.write(rownum, colnum + 1, QVariant(), weekendRightStyle);
}

if (day == 1 && dow != 1) {//First day
for (int i=1; i<dow; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
if (day == 1 && dow != 1) { // First day
for (int i = 1; i < dow; ++i) {
xlsx.write(rownum, i * 2 - 1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i * 2, QVariant(), greyRightStyle);
}
} else if (day == date.daysInMonth() && dow != 7) {//Last day
for (int i=dow+1; i<=7; ++i) {
xlsx.write(rownum, i*2-1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i*2, QVariant(), greyRightStyle);
} else if (day == date.daysInMonth() && dow != 7) { // Last day
for (int i = dow + 1; i <= 7; ++i) {
xlsx.write(rownum, i * 2 - 1, QVariant(), greyLeftStyle);
xlsx.write(rownum, i * 2, QVariant(), greyRightStyle);
}
}

if (dow == 7)
rownum++;
}

}

xlsx.saveAs("Book1.xlsx");

//Make sure that read/write works well.
// Make sure that read/write works well.
Document xlsx2("Book1.xlsx");
xlsx2.saveAs("Book2.xlsx");

Expand Down
4 changes: 4 additions & 0 deletions examples/xlsx/chart/chart.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/chart
INSTALLS += target
12 changes: 6 additions & 6 deletions examples/xlsx/chart/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ int main()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i) {
xlsx.write(i, 1, i*i*i); //A1:A9
xlsx.write(i, 2, i*i); //B1:B9
xlsx.write(i, 3, i*i-1); //C1:C9
for (int i = 1; i < 10; ++i) {
xlsx.write(i, 1, i * i * i); // A1:A9
xlsx.write(i, 2, i * i); // B1:B9
xlsx.write(i, 3, i * i - 1); // C1:C9
}
//![0]

Expand Down Expand Up @@ -53,14 +53,14 @@ int main()

Chart *scatterChart = xlsx.insertChart(83, 3, QSize(300, 300));
scatterChart->setChartType(Chart::CT_Scatter);
//Will generate three lines.
// Will generate three lines.
scatterChart->addSeries(CellRange("A1:A9"));
scatterChart->addSeries(CellRange("B1:B9"));
scatterChart->addSeries(CellRange("C1:C9"));

Chart *scatterChart_2 = xlsx.insertChart(83, 9, QSize(300, 300));
scatterChart_2->setChartType(Chart::CT_Scatter);
//Will generate two lines.
// Will generate two lines.
scatterChart_2->addSeries(CellRange("A1:C9"));

Chart *doughnutChart = xlsx.insertChart(103, 3, QSize(300, 300));
Expand Down
4 changes: 4 additions & 0 deletions examples/xlsx/chartsheet/chartsheet.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/chartsheet
INSTALLS += target
6 changes: 3 additions & 3 deletions examples/xlsx/chartsheet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ int main()
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i)
xlsx.write(i, 1, i*i);
for (int i = 1; i < 10; ++i)
xlsx.write(i, 1, i * i);
//![0]

//![1]
xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet);
Chartsheet *sheet = static_cast<Chartsheet*>(xlsx.currentSheet());
Chartsheet *sheet = static_cast<Chartsheet *>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
barChart->setChartType(Chart::CT_Bar);
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
Expand Down
4 changes: 4 additions & 0 deletions examples/xlsx/conditionalformatting/conditionalformatting.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/conditionalformatting
INSTALLS += target
4 changes: 2 additions & 2 deletions examples/xlsx/conditionalformatting/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ int main()
xlsx.write("E1", "dataBar", hFmt);
xlsx.write("F1", "colorScale", hFmt);

for (int row=3; row<22; ++row) {
for (int col=2; col<22; ++col)
for (int row = 3; row < 22; ++row) {
for (int col = 2; col < 22; ++col)
xlsx.write(row, col, qrand() % 100);
}
//![0]
Expand Down
4 changes: 4 additions & 0 deletions examples/xlsx/datavalidation/datavalidation.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/datavalidation
INSTALLS += target
4 changes: 4 additions & 0 deletions examples/xlsx/definename/definename.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/definename
INSTALLS += target
6 changes: 3 additions & 3 deletions examples/xlsx/definename/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ int main()
{
//![0]
Document xlsx;
for (int i=1; i<=10; ++i) {
for (int i = 1; i <= 10; ++i) {
xlsx.write(i, 1, i);
xlsx.write(i, 2, i*i);
xlsx.write(i, 3, i*i*i);
xlsx.write(i, 2, i * i);
xlsx.write(i, 3, i * i * i);
}
//![0]
//![1]
Expand Down
4 changes: 4 additions & 0 deletions examples/xlsx/demo/demo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ CONFIG += console
CONFIG -= app_bundle

SOURCES += main.cpp

# install
target.path = $$[QT_INSTALL_EXAMPLES]/xlsx/demo
INSTALLS += target
Loading