diff --git a/.clang-tidy b/.clang-tidy index 15e77a976..314ec521f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,6 +7,7 @@ Checks: clang-analyzer-*, misc-*, readability-*, + -bugprone-branch-clone, -bugprone-easily-swappable-parameters, -bugprone-implicit-widening-of-multiplication-result, -bugprone-integer-division, @@ -21,6 +22,7 @@ Checks: -cppcoreguidelines-avoid-c-arrays, -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-explicit-virtual-functions, -cppcoreguidelines-init-variables, -cppcoreguidelines-macro-usage, @@ -58,6 +60,7 @@ Checks: -misc-no-recursion, -misc-non-private-member-variables-in-classes, -misc-unused-parameters, + -modernize-avoid-c-arrays, -modernize-pass-by-value, -modernize-return-braced-init-list, -modernize-use-default-member-init, diff --git a/.github/actions/cmake/action.yml b/.github/actions/cmake/action.yml index 255d7b81a..e91f05116 100644 --- a/.github/actions/cmake/action.yml +++ b/.github/actions/cmake/action.yml @@ -5,8 +5,8 @@ inputs: description: "Specify Qt version to use" required: true qt_arch: - description: "Specify Qt version to use" - default: "gcc_64" + description: "Specify architecture to use" + default: "linux_gcc_64" use_qt6: description: "Specify whether we're using Qt 5 or Qt 6" required: true diff --git a/.github/actions/run-linter/action.yml b/.github/actions/run-linter/action.yml index e6428df3b..c7e0771a9 100644 --- a/.github/actions/run-linter/action.yml +++ b/.github/actions/run-linter/action.yml @@ -11,7 +11,7 @@ runs: - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.6.3 + qt_version: 6.8.3 use_qt6: ON modules: qtserialport qtmultimedia additional_cmake_args: -DCMAKE_GLOBAL_AUTOGEN_TARGET=ON -DCMAKE_AUTOGEN_ORIGIN_DEPENDS=OFF diff --git a/.github/workflows/appimage.yml b/.github/workflows/appimage.yml index de1025893..0d73f44b8 100644 --- a/.github/workflows/appimage.yml +++ b/.github/workflows/appimage.yml @@ -23,7 +23,7 @@ jobs: - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.6.3 + qt_version: 6.8.3 use_qt6: ON modules: qtserialport qtmultimedia additional_cmake_args: -DCMAKE_INSTALL_PREFIX='${{ github.workspace }}/install/usr' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5e4f25828..6aa1111ab 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -39,4 +39,4 @@ jobs: - name: Run clazy uses: ./.github/actions/run-linter with: - lint_program_with_args: clazy-standalone --checks=level1,no-fully-qualified-moc-types,no-non-pod-global-static + lint_program_with_args: clazy-standalone --checks=level1,no-fully-qualified-moc-types,no-non-pod-global-static,no-qstring-arg,no-qproperty-without-notify,no-range-loop-detach,no-lambda-unique-connection diff --git a/3rdparty/necrolog b/3rdparty/necrolog index be88dcde5..9d607eb1a 160000 --- a/3rdparty/necrolog +++ b/3rdparty/necrolog @@ -1 +1 @@ -Subproject commit be88dcde5ec0bb7dc224e285e63d1dd0e18834a7 +Subproject commit 9d607eb1a5bdf5c93ed22cbabbc48a89db920a04 diff --git a/libqf/libqfcore/CMakeLists.txt b/libqf/libqfcore/CMakeLists.txt index 473b63064..6bdab83fb 100644 --- a/libqf/libqfcore/CMakeLists.txt +++ b/libqf/libqfcore/CMakeLists.txt @@ -16,11 +16,8 @@ add_library(libqfcore SHARED src/sql/connection.cpp src/sql/dbenum.cpp src/sql/dbenumcache.cpp - src/sql/dbfsattrs.cpp - src/sql/dbfsdriver.cpp src/sql/query.cpp src/sql/querybuilder.cpp - src/sql/tablelocker.cpp src/sql/transaction.cpp src/utils/clioptions.cpp src/utils/crypt.cpp diff --git a/libqf/libqfcore/include/qf/core/sql/dbfsattrs.h b/libqf/libqfcore/include/qf/core/sql/dbfsattrs.h deleted file mode 100644 index 0842c1d30..000000000 --- a/libqf/libqfcore/include/qf/core/sql/dbfsattrs.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../../../src/sql/dbfsattrs.h" diff --git a/libqf/libqfcore/include/qf/core/sql/dbfsdriver.h b/libqf/libqfcore/include/qf/core/sql/dbfsdriver.h deleted file mode 100644 index ed3f13088..000000000 --- a/libqf/libqfcore/include/qf/core/sql/dbfsdriver.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../../../src/sql/dbfsdriver.h" diff --git a/libqf/libqfcore/include/qf/core/sql/tablelocker.h b/libqf/libqfcore/include/qf/core/sql/tablelocker.h deleted file mode 100644 index 758d543fb..000000000 --- a/libqf/libqfcore/include/qf/core/sql/tablelocker.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../../../src/sql/tablelocker.h" diff --git a/libqf/libqfcore/src/core/exception.cpp b/libqf/libqfcore/src/core/exception.cpp index 3e6563856..64ef6c93d 100644 --- a/libqf/libqfcore/src/core/exception.cpp +++ b/libqf/libqfcore/src/core/exception.cpp @@ -4,9 +4,6 @@ #include -#include -#include - using namespace qf::core; #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) @@ -16,9 +13,9 @@ using namespace qf::core; #endif //============================================================ -// Exception +// Exception //============================================================ -bool Exception::s_abortOnException = false; +bool Exception::s_abortOnException = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) namespace { @@ -34,11 +31,11 @@ Exception::Exception(const QString &_msg, const QString &_where) m_where = _where; m_msg = _msg; m_what = m_msg.toUtf8(); - m_stackTrace = StackTrace::stackTrace().toString(); + m_stackTrace = StackTrace::stackTrace().join('\n'); log(); } -void Exception::log() +void Exception::log() const { if(isLogStackTrace()) logWarning() << message() << "\n" << where() << "\n----- stack trace -----\n" << stackTrace(); @@ -53,7 +50,7 @@ QString Exception::toString() const return ret; } -const char* Exception::what() const throw() +const char* Exception::what() const noexcept { return m_what.constData(); } diff --git a/libqf/libqfcore/src/core/exception.h b/libqf/libqfcore/src/core/exception.h index 0b6a0cc24..09c47c16c 100644 --- a/libqf/libqfcore/src/core/exception.h +++ b/libqf/libqfcore/src/core/exception.h @@ -38,13 +38,13 @@ class QFCORE_DECL_EXPORT Exception : public std::exception QString m_stackTrace; protected: void init(const QString& _msg, const QString& _where); - void log(); + void log() const; public: QString message() const {return m_msg;} QString where() const {return m_where;} QString stackTrace() const {return m_stackTrace;} virtual QString toString() const; - const char* what() const throw() Q_DECL_OVERRIDE; + const char* what() const noexcept override; operator const char *() const throw(){return what();} // set global variables: abortOnException from command line diff --git a/libqf/libqfcore/src/core/logentrymap.cpp b/libqf/libqfcore/src/core/logentrymap.cpp index 397596323..e5c189a36 100644 --- a/libqf/libqfcore/src/core/logentrymap.cpp +++ b/libqf/libqfcore/src/core/logentrymap.cpp @@ -2,8 +2,7 @@ #include -namespace qf { -namespace core { +namespace qf::core { //========================================================= // LogEntryMap @@ -114,15 +113,14 @@ LogEntryMap &LogEntryMap::setTimeStamp(const QDateTime &ts) QString LogEntryMap::toString() const { QString ret = "{"; - ret += "\"level\":" + QString::number((int)level()) + ", "; - ret += "\"category\":\"" + category() + "\", "; - ret += "\"message\":\"" + message() + "\", "; - ret += "\"file\":\"" + file() + "\", "; - ret += "\"line\":" + QString::number(line()) + ", "; - ret += "\"time\":\"" + timeStamp().toString(Qt::ISODate) + "\", "; - ret += "\"function\":\"" + function() + "\"}"; + ret += R"("level":)" + QString::number((int)level()) + ", "; + ret += R"("category":")" + category() + "\", "; + ret += R"("message":")" + message() + "\", "; + ret += R"("file":")" + file() + "\", "; + ret += R"("line":)" + QString::number(line()) + ", "; + ret += R"("time":")" + timeStamp().toString(Qt::ISODate) + "\", "; + ret += R"("function":")" + function() + "\"}"; return ret; } -} // namespace core -} // namespace qf +} diff --git a/libqf/libqfcore/src/core/stacktrace.cpp b/libqf/libqfcore/src/core/stacktrace.cpp index cffd624be..fe4a6ec91 100644 --- a/libqf/libqfcore/src/core/stacktrace.cpp +++ b/libqf/libqfcore/src/core/stacktrace.cpp @@ -1,170 +1,40 @@ #include "stacktrace.h" -#include "string.h" - #include -#include -#include - #if defined Q_CC_GNU && !defined Q_CC_MINGW && !defined ANDROID - #include +#include +#include #endif using namespace qf::core; -#if defined Q_CC_GNU && !defined Q_CC_MINGW - -static QString cutName(QString &s) -{ - QString ret; - int ix = 0; - while(ix < s.length() && s[ix] >= '0' && s[ix] <= '9') { - ix++; - } - if(ix < s.length()) { - int l = s.mid(0, ix).toInt(); - ret = s.mid(ix, l); - s = s.mid(ix + l); - } - return ret; -} - -static QString demangle_gcc(const QString &_s) -{ - String s = _s; - String ret; - int first_digit_pos; - for(first_digit_pos=0; first_digit_pos<_s.length(); first_digit_pos++) { - QChar c = _s[first_digit_pos]; - if(c >= '0' && c <= '9') - break; - } - if(first_digit_pos < s.length()) { - s = s.slice(first_digit_pos); - while(true) { - QString ns = cutName(s); - if(ns.isEmpty()) - break; - if(ret.isEmpty()) - ret = ns; - else - ret += "::" + ns; - } - ret += "(" + s + ")"; - } - else - ret = s; - //qDebug() << "\t ret:" << ret; - return ret; -} - -#endif -StackTrace::StackTrace(const QStringList &sl) +QStringList StackTrace::stackTrace() { - m_trace = sl; -} - -StackTrace StackTrace::stackTrace() -{ - QStringList sl_ret; #if defined Q_CC_GNU && !defined Q_CC_MINGW - QStringList sl = trace2str(); - for(String s : sl) { - int ix = s.indexOf('('); - String s1, s2, s3; - if(ix > 0) { - s1 = s.slice(0, ix); - s = s.slice(ix+1); - ix = s.indexOf('['); - if(ix > 0) { - s2 = s.slice(0, ix-2); - s3 = s.slice(ix + 1, -1); - } - else s2 = s.slice(0, -1); - } - else { - ix = s.indexOf('['); - if(ix > 0) { - s1 = s.slice(0, ix-1); - s3 = s.slice(ix + 1, -1); - } - else s1 = s; - } - sl_ret << s1 + ";" + demangle_gcc(s2) + ";" + s3; - } -#endif - return StackTrace(sl_ret); -} + const int max_frames = 100; + void* addrlist[max_frames]; // NOLINT(modernize-avoid-c-arrays) -QString StackTrace::toString() const -{ - return m_trace.join("\n"); -} - -QStringList StackTrace::trace() const -{ - return m_trace; -} + // Retrieve current stack addresses + int addrlen = backtrace(addrlist, max_frames); -#if defined(Q_CC_MSVC) -QString QFStackTrace::trace2str() -{ - std::ostringstream oss; - - CONTEXT context = {0}; - ::GetThreadContext( GetCurrentThread(), &context ); - - _asm call $+5 - _asm pop eax - _asm mov context.Eip, eax - _asm mov eax, esp - _asm mov context.Esp, eax - _asm mov context.Ebp, ebp - - SimpleSymbolEngine::instance().StackTrace( &context, oss ); - return oss.str(); -} -#elif defined Q_CC_GNU && !defined Q_CC_MINGW && !defined ANDROID -QStringList StackTrace::trace2str() -{ - static const int MAX_CNT = 100; - void *array[MAX_CNT]; - int size; - char **strings; - QStringList ret; + if (addrlen == 0) { + return {}; + } - size = backtrace (array, MAX_CNT); - strings = backtrace_symbols (array, size); + // Create readable strings for each frame + auto symbollist = backtrace_symbols(addrlist, addrlen); - for(int i = 1; i < size; i++) { - //qDebug() << strings[i]; - ret << QString::fromUtf8(strings[i]); + QStringList sl_ret; + for (int i = 0; i < addrlen; i++) { + sl_ret << symbollist[i]; } - free(strings); - return ret; -} + free(symbollist); // NOLINT(bugprone-multi-level-implicit-pointer-conversion,cppcoreguidelines-no-malloc,hicpp-no-malloc) + return sl_ret; #else -///http://www.gnu.org/software/hello/manual/gnulib/execinfo_002eh.html -/** -8.13 execinfo.h - -Declares the functions backtrace, backtrace_symbols, backtrace_symbols_fd. - -Documentation: -http://www.gnu.org/software/libc/manual/html_node/Backtraces.html, -man backtrace. - -Gnulib module: — - -Portability problems fixed by Gnulib: - -Portability problems not fixed by Gnulib: -This header file is missing on all non-glibc platforms: - MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, - Cygwin, mingw, Interix 3.5, BeOS. -*/ -QStringList StackTrace::trace2str() {return QStringList();} + return {}; #endif +} + diff --git a/libqf/libqfcore/src/core/stacktrace.h b/libqf/libqfcore/src/core/stacktrace.h index adf7d0c54..15388992e 100644 --- a/libqf/libqfcore/src/core/stacktrace.h +++ b/libqf/libqfcore/src/core/stacktrace.h @@ -15,14 +15,7 @@ namespace core { class QFCORE_DECL_EXPORT StackTrace { public: - static StackTrace stackTrace(); - QString toString() const; - QStringList trace() const; -protected: - static QStringList trace2str(); -private: - StackTrace(const QStringList &sl); - QStringList m_trace; + static QStringList stackTrace(); }; } diff --git a/libqf/libqfcore/src/core/string.cpp b/libqf/libqfcore/src/core/string.cpp index 47212ce9d..9eeb5a60e 100644 --- a/libqf/libqfcore/src/core/string.cpp +++ b/libqf/libqfcore/src/core/string.cpp @@ -1,7 +1,9 @@ -#include "string.h" +#include "string.h" // NOLINT(modernize-deprecated-headers) #include +#include + using namespace qf::core; qf::core::String qf::core::String::slice(int start, int end) const @@ -9,10 +11,10 @@ qf::core::String qf::core::String::slice(int start, int end) const int l = length(); if(start < 0) start += l; if(end < 0) end += l; - if(start < 0) start = 0; - if(end < 0) end = 0; - if(end > l) end = l; - if(start > end) start = end; + start = std::max(start, 0); + end = std::max(end, 0); + end = std::min(end, l); + start = std::min(start, end); //qfTrash() << "\tstart:" << start << "end:" << end; //qfTrash() << "\tthis:" << *this; return mid(start, end - start); @@ -66,10 +68,9 @@ QStringList String::splitAndTrim(QChar sep, QChar quote, bool trim_parts, SplitB if(fs2.value(0) == quote && fs2.value(-1) == quote) fs2 = fs2.slice(1, -1); } - if(!fs2.isEmpty()) - ret.append(fs2); - else if(keep_empty_parts == KeepEmptyParts) + if(!fs2.isEmpty() || keep_empty_parts == KeepEmptyParts) { ret.append(fs2); + } } return ret; } diff --git a/libqf/libqfcore/src/core/utils.cpp b/libqf/libqfcore/src/core/utils.cpp index 6d25dad4f..bd93b6c4c 100644 --- a/libqf/libqfcore/src/core/utils.cpp +++ b/libqf/libqfcore/src/core/utils.cpp @@ -6,8 +6,7 @@ #include #include -namespace qf { -namespace core { +namespace qf::core { const QString& Utils::nullValueString() { @@ -153,7 +152,7 @@ QSet Utils::findCaptions(const QString &caption_format) { QSet ret; QRegularExpression rx; - rx.setPattern("\\{\\{([A-Za-z][A-Za-z0-9]*(\\.[A-Za-z][A-Za-z0-9]*)*)\\}\\}"); + rx.setPattern(R"(\{\{([A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)*)\}\})"); auto match_iterator = rx.globalMatch(caption_format); while (match_iterator.hasNext()) { auto match = match_iterator.next(); @@ -186,15 +185,17 @@ QString Utils::removeJsonComments(const QString &json_str) { // http://blog.ostermiller.org/find-comment QString ret = json_str; - ret.replace(QRegularExpression("/\\*(?:.|[\\n])*?\\*/"), QString()); - ret.replace(QRegularExpression("(?()) { QVariant v = data(index, Qt::BackgroundRole); if(v.isValid()) { - QColor bgr_color = v.value(); + auto bgr_color = v.value(); if(bgr_color.isValid()) { return contrastTextColor(bgr_color); } @@ -394,7 +391,7 @@ bool SqlTableModel::removeTableRow(int row_no, bool throw_exc) sqlfld.setValue(id); bool invalid_id = false; if(id.isNull()) - invalid_id = true; + invalid_id = true; // NOLINT(bugprone-branch-clone) #if QT_VERSION_MAJOR >= 6 else if(id.typeId() == QMetaType::Int && id.toInt() == 0) #else @@ -578,7 +575,8 @@ QString SqlTableModel::buildQuery() return ret; } -static QString paramValueToString(const QVariant &v) +namespace { +QString paramValueToString(const QVariant &v) { QString ret; if(v.isValid()) @@ -587,6 +585,7 @@ static QString paramValueToString(const QVariant &v) ret = QStringLiteral("NULL"); return ret; } +} QString SqlTableModel::replaceQueryParameters(const QString query_str) { @@ -617,7 +616,7 @@ QString SqlTableModel::replaceQueryParameters(const QString query_str) return ret; } -qf::core::sql::Connection SqlTableModel::sqlConnection() +qf::core::sql::Connection SqlTableModel::sqlConnection() const { QSqlDatabase db = QSqlDatabase::database(connectionName()); qf::core::sql::Connection ret = qf::core::sql::Connection(db); @@ -688,13 +687,15 @@ bool SqlTableModel::reloadTable(const QString &query_str) return true; } -static QString compose_table_id(const QString &table_name, const QString &schema_name) +namespace { +QString compose_table_id(const QString &table_name, const QString &schema_name) { QString ret = table_name; if(!schema_name.isEmpty()) ret = schema_name + '.' + ret; return ret; } +} QStringList SqlTableModel::tableIds(const qf::core::utils::Table::FieldList &table_fields) { @@ -711,7 +712,8 @@ QStringList SqlTableModel::tableIds(const qf::core::utils::Table::FieldList &tab return ret; } -static QMap< QString, QSet > separateFields(const qf::core::utils::Table::FieldList &table_fields) +namespace { +QMap< QString, QSet > separateFields(const qf::core::utils::Table::FieldList &table_fields) { QMap< QString, QSet > field_ids; Q_FOREACH(const qfu::Table::Field &fld, table_fields) { @@ -722,8 +724,9 @@ static QMap< QString, QSet > separateFields(const qf::core::utils::Tabl } return field_ids; } +} -void SqlTableModel::setSqlFlags(qf::core::utils::Table::FieldList &table_fields, const QString &query_str) +void SqlTableModel::setSqlFlags(qf::core::utils::Table::FieldList &table_fields, const QString &query_str) const { //qfLogFuncFrame(); //QSet table_ids = tableIds(table_fields); @@ -792,7 +795,7 @@ QSet SqlTableModel::referencedForeignTables() QSet ret; { const QStringList sl = m_foreignKeyDependencies.values(); - for(QString s : sl) { + for(const auto &s : sl) { QString tbl_name; qf::core::Utils::parseFieldName(s, nullptr, &tbl_name); tbl_name = tbl_name.trimmed().toLower(); @@ -825,13 +828,13 @@ QStringList SqlTableModel::tableIdsSortedAccordingToForeignKeys() QString slave_key = it.value(); QString field, table, schema; qf::core::Utils::parseFieldName(slave_key, &field, &table, &schema); - slave_key = qf::core::Utils::composeFieldName(table, schema); + slave_key = qf::core::Utils::composeFieldName(table, schema); // NOLINT(readability-suspicious-call-argument) if(qf::core::Utils::fieldNameCmp(table_id, slave_key)) { dependency_satisfied = false; /// table_id is a slave, so check if master table is in return list already qf::core::Utils::parseFieldName(master_key, &field, &table, &schema); - master_key = qf::core::Utils::composeFieldName(table, schema); - for(auto included_table_id : ret) { + master_key = qf::core::Utils::composeFieldName(table, schema); // NOLINT(readability-suspicious-call-argument) + for(const auto &included_table_id : ret) { if(qf::core::Utils::fieldNameCmp(included_table_id, master_key)) { ret << table_ids.takeFirst(); dependency_satisfied = true; diff --git a/libqf/libqfcore/src/model/sqltablemodel.h b/libqf/libqfcore/src/model/sqltablemodel.h index 05d9f16d1..e9c52828e 100644 --- a/libqf/libqfcore/src/model/sqltablemodel.h +++ b/libqf/libqfcore/src/model/sqltablemodel.h @@ -62,7 +62,7 @@ class QFCORE_DECL_EXPORT SqlTableModel : public TableModel } Q_SIGNAL void connectionNameChanged(QString arg); - qf::core::sql::Connection sqlConnection(); + qf::core::sql::Connection sqlConnection() const; QString query() const { return m_query; } void setQuery(const QString &query_str); Q_SIGNAL void queryChanged(const QString &query_str); @@ -80,7 +80,7 @@ class QFCORE_DECL_EXPORT SqlTableModel : public TableModel virtual bool reloadTable(const QString &query_str); QStringList tableIds(const utils::Table::FieldList &table_fields); - void setSqlFlags(qf::core::utils::Table::FieldList &table_fields, const QString &query_str); + void setSqlFlags(qf::core::utils::Table::FieldList &table_fields, const QString &query_str) const; QSet referencedForeignTables(); QStringList tableIdsSortedAccordingToForeignKeys(); diff --git a/libqf/libqfcore/src/model/tablemodel.cpp b/libqf/libqfcore/src/model/tablemodel.cpp index 0e903b36d..5984d523e 100644 --- a/libqf/libqfcore/src/model/tablemodel.cpp +++ b/libqf/libqfcore/src/model/tablemodel.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace qfc = qf::core; namespace qfu = qf::core::utils; @@ -28,11 +29,13 @@ bool TableModel::ColumnDefinition::matchesSqlId(const QString column_name) const } //========================================= -// TableModel +// TableModel //========================================= -QString TableModel::m_defaultTimeFormat = QStringLiteral("hh:mm:ss"); -QString TableModel::m_defaultDateFormat = QStringLiteral("yyyy-MM-dd"); -QString TableModel::m_defaultDateTimeFormat = QStringLiteral("yyyy-MM-ddThh:mm:ss"); +namespace { +const auto DEFAULT_TIME_FORMAT = QStringLiteral("hh:mm:ss"); +const auto DEFAULT_DATE_FORMAT = QStringLiteral("yyyy-MM-dd"); +const auto DEFAULT_DATETIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); +} TableModel::TableModel(QObject *parent) : Super(parent) @@ -152,14 +155,14 @@ QVariant TableModel::data(const QModelIndex &index, int role) const QString format = cd.format(); if(format.isEmpty()) { if(type == QMetaType::QDate) { - format = m_defaultDateFormat; + format = DEFAULT_DATE_FORMAT; } else if(type == QMetaType::QTime) { - format = m_defaultTimeFormat; + format = DEFAULT_TIME_FORMAT; //qfInfo() << "format" << format; } else if(type == QMetaType::QDateTime) { - format = m_defaultDateTimeFormat; + format = DEFAULT_DATETIME_FORMAT; //qfInfo() << "format" << format; } } @@ -786,8 +789,7 @@ bool TableModel::insertRows(int row_ix, int count, const QModelIndex &parent) qfLogFuncFrame() << "row:" << row_ix << "count:" << count; if(count < 0) return false; - if(row_ix < 0) - row_ix = 0; + row_ix = std::max(row_ix, 0); beginInsertRows(parent, row_ix, row_ix + count - 1); bool ok = true; for(int i=0; i 0) - cd.setType((int)t); + cd.setType(t); cd.setHeader(cap); //ret.appendColumn(headerData(ix, Qt::Horizontal, FieldNameRole).toString(), t, cap); } diff --git a/libqf/libqfcore/src/model/tablemodel.h b/libqf/libqfcore/src/model/tablemodel.h index 05525fb5b..8999e801f 100644 --- a/libqf/libqfcore/src/model/tablemodel.h +++ b/libqf/libqfcore/src/model/tablemodel.h @@ -219,9 +219,6 @@ class QFCORE_DECL_EXPORT TableModel : public QAbstractTableModel ColumnList m_columns; bool m_columnsAutoGenerated = false; bool m_nullReportedAsString; - static QString m_defaultTimeFormat; - static QString m_defaultDateFormat; - static QString m_defaultDateTimeFormat; }; }}} diff --git a/libqf/libqfcore/src/network/networkaccessmanager.cpp b/libqf/libqfcore/src/network/networkaccessmanager.cpp index 1af6c20a6..8423ae5a5 100644 --- a/libqf/libqfcore/src/network/networkaccessmanager.cpp +++ b/libqf/libqfcore/src/network/networkaccessmanager.cpp @@ -7,9 +7,9 @@ #include #include -namespace qf { -namespace core { -namespace network { + + +namespace qf::core::network { NetworkAccessManager::NetworkAccessManager(QObject *parent) : Super(parent) @@ -24,7 +24,7 @@ NetworkAccessManager::~NetworkAccessManager() NetworkReply *NetworkAccessManager::get(const QUrl &url) { qfLogFuncFrame() << url.toString(); - NetworkReply *ret = new NetworkReply(); + auto *ret = new NetworkReply(); QNetworkRequest rq(url); //rq.setRawHeader("User-Agent", "MyOwnBrowser 1.0"); QNetworkReply *repl = Super::get(rq); @@ -32,4 +32,4 @@ NetworkReply *NetworkAccessManager::get(const QUrl &url) return ret; } -}}} +} diff --git a/libqf/libqfcore/src/network/networkreply.cpp b/libqf/libqfcore/src/network/networkreply.cpp index 9e2a39811..a4a056c1a 100644 --- a/libqf/libqfcore/src/network/networkreply.cpp +++ b/libqf/libqfcore/src/network/networkreply.cpp @@ -3,9 +3,9 @@ #include -namespace qf { -namespace core { -namespace network { + + +namespace qf::core::network { NetworkReply::NetworkReply(QObject *parent) : QObject(parent), m_reply(nullptr) @@ -105,4 +105,4 @@ void NetworkReply::readyRead_helper() } } -}}} +} diff --git a/libqf/libqfcore/src/sql/catalog.cpp b/libqf/libqfcore/src/sql/catalog.cpp index b9275d242..b1276fdb7 100644 --- a/libqf/libqfcore/src/sql/catalog.cpp +++ b/libqf/libqfcore/src/sql/catalog.cpp @@ -12,7 +12,9 @@ #include #include -#define QFCATALOG_MYSQL_VERSION_MAJOR 5 +enum { +QFCATALOG_MYSQL_VERSION_MAJOR = 5 +}; using namespace qf::core::sql; diff --git a/libqf/libqfcore/src/sql/connection.cpp b/libqf/libqfcore/src/sql/connection.cpp index 8c0d5fb7e..9f827224a 100644 --- a/libqf/libqfcore/src/sql/connection.cpp +++ b/libqf/libqfcore/src/sql/connection.cpp @@ -25,9 +25,9 @@ using namespace qf::core::sql; //========================================= namespace { -QMap s_primaryIndexCache; -QMap s_serialFieldNamesCache; -QMap s_tableRecordCache; +QMap s_primaryIndexCache; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +QMap s_serialFieldNamesCache; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +QMap s_tableRecordCache; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) void s_clearCache(const QString &connection_name) { @@ -60,10 +60,7 @@ void s_clearCache(const QString &connection_name) } -Connection::Connection() - : QSqlDatabase() -{ -} +Connection::Connection() = default; Connection::Connection(const QSqlDatabase& qdb) : QSqlDatabase(qdb) @@ -125,8 +122,8 @@ int Connection::connectionId() int Connection::defaultPort(const QString &driver_name) { if(driver_name.endsWith(QLatin1String("PSQL"))) return 5432; - else if(driver_name.endsWith(QLatin1String("MYSQL"))) return 3306; - else if(driver_name.endsWith("IBASE")) return 3050; + if(driver_name.endsWith(QLatin1String("MYSQL"))) return 3306; + if(driver_name.endsWith("IBASE")) return 3050; return 0; } @@ -153,7 +150,8 @@ QString Connection::info(int verbosity) const return s; } -static QString formatValueForSql(const QVariant &val) +namespace { +QString formatValueForSql(const QVariant &val) { QString ret = val.toString(); #if QT_VERSION_MAJOR >= 6 @@ -171,7 +169,7 @@ static QString formatValueForSql(const QVariant &val) return ret; } -static QVariant sqlite_set_pragma(QSqlQuery &q, const QString &pragma_key, const QVariant &val) +QVariant sqlite_set_pragma(QSqlQuery &q, const QString &pragma_key, const QVariant &val) { qfLogFuncFrame() << pragma_key << "value:" << val.toString(); QString qs = "PRAGMA " + pragma_key; @@ -191,11 +189,11 @@ static QVariant sqlite_set_pragma(QSqlQuery &q, const QString &pragma_key, const } return old_val; } - else { - qfError() << "SQL PRAGMA query is supposed to return data but it hasn't"; - } + qfError() << "SQL PRAGMA query is supposed to return data but it hasn't"; + return QVariant(); } +} QStringList Connection::tables(const QString& dbname, QSql::TableType type) const { @@ -273,7 +271,7 @@ QStringList Connection::tables(const QString& dbname, QSql::TableType type) cons QSqlQuery q(*this); QStringList sl = serverVersion(); int ver = 0; - if(sl.size() > 0) { + if(!sl.empty()) { //qfDebug() << "\tsl[0]:" << sl[0]; ver = sl[0].toInt(); } @@ -553,7 +551,6 @@ QStringList Connection::schemas() const " WHERE (n.nspname NOT LIKE 'pg\\_temp\\_%' OR" " n.nspname = (pg_catalog.current_schemas(true))[1])" " ORDER BY 1"); - QSqlRecord r = q.record(); while(q.next()) { QString s = q.value(0).toString(); qfLogFuncFrame() << "loading schema" << s; @@ -600,107 +597,9 @@ QString Connection::errorString() const { return lastError().text(); } -#if 0 -QFSql::RelationKind DbInfo::relationKind(const QString& _relname) -{ - QFSql::RelationKind ret = QFSql::UnknownRelation; - QString relname, dbname; - qf::core::Utils::parseFieldName(_relname, &relname, &dbname); - if(driverName().endsWith(QLatin1String("PSQL"))) { - QSqlQuery q(*this); - q.setForwardOnly(true); - QString s = "SELECT c.relname, c.relkind, n.nspname" - " FROM pg_class AS c" - " LEFT JOIN pg_namespace AS n ON c.relnamespace=n.oid" - " WHERE c.relname = '%1'"; - if(!dbname.isEmpty()) s += " AND n.nspname = '" + dbname + "'"; - if(q.exec(s.arg(relname))) { - while(q.next()) { - s = q.value(1).toString(); - if(s == "r") ret = QFSql::TableRelation; - else if(s == "v") ret = QFSql::ViewRelation; - else if(s == "i") ret = QFSql::IndexRelation; - else if(s == "S") ret = QFSql::SequenceRelation; - break; - } - } - } - else if(driverName().endsWith(QLatin1String("SQLITE"))) { - QSqlQuery q(*this); - q.setForwardOnly(true); - QString from; - if(dbname.isEmpty() || dbname == "main") from = "(SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)"; - else from = dbname + ".sqlite_master"; - QString s = "SELECT type, name, tbl_name FROM %1 WHERE name = '%2'"; - s = s.arg(from).arg(relname); - QVariant old_short_column_names = sqlite_set_pragma(q, "short_column_names", 0); - QVariant old_full_column_names = sqlite_set_pragma(q, "full_column_names", 0); - if(!q.exec(s)) { - QF_SQL_EXCEPTION(QString("Error getting table list for database '%1'").arg(dbname)); - } - // For tables, the type field will always be 'table' and the name field will be the name of the table. - // For indices, type is equal to 'index', name is the name of the index - // and tbl_name is the name of the table to which the index belongs. - else { - while(q.next()) { - s = q.value(0).toString(); - if(s == "table") ret = QFSql::TableRelation; - else if(s == "view") ret = QFSql::ViewRelation; - else if(s == "index") ret = QFSql::IndexRelation; - break; - } - } - sqlite_set_pragma(q, "short_column_names", old_short_column_names); - sqlite_set_pragma(q, "full_column_names", old_full_column_names); - } - else if(driverName().endsWith(QLatin1String("MYSQL"))) { - QSqlQuery q(*this); - q.setForwardOnly(true); - /* - QString s = "SELECT table_type FROM INFORMATION_SCHEMA.TABLES" - " WHERE table_schema = '%1' AND table_name = '%2'"; - */ - /// kvuli verzi 4, ktera nema information_schema - QString s = "SHOW FULL tables FROM %1 LIKE '%2'"; - s = s.arg(dbname).arg(relname); - if(!q.exec(s)) { - QF_SQL_EXCEPTION(QString("Error getting table list for database '%1'\n\n%2").arg(dbname).arg(s)); - } - else { - while(q.next()) { - s = q.value(1).toString(); - if(s == "BASE TABLE") ret = QFSql::TableRelation; - else if(s == "VIEW") ret = QFSql::ViewRelation; - else if(s == "SYSTEM VIEW") ret = QFSql::SystemTableRelation; - break; - } - } - //if(!q.exec("PRAGMA full_column_names=1")) QF_SQL_EXCEPTION(QString("SQL Error\nquery: %1;").arg(s)); - } - return ret; -} - -QStringList DbInfo::fieldDefsFromCreateTableCommand(const QString &cmd) -{ - qfLogFuncFrame() << cmd; - QString fs = cmd; - QStringList sl; - do { - int ix; - if((ix = fs.indexOf('(')) <0) - break; - fs = fs.slice(ix); - if((ix= fs.indexOfMatchingBracket('(', ')', '\'')) <0) - break; - //qfDebug() << "\tlen:" << fs.len() << "ix:" << ix; - fs = fs.slice(1, ix); - sl = fs.splitBracketed(',', '(', ')', '\''); - } while(false); - return sl; -} -#endif -static QString err_msg(QProcess::ProcessError err_no) +namespace { +QString err_msg(QProcess::ProcessError err_no) { switch(err_no) { case QProcess::FailedToStart: @@ -717,6 +616,7 @@ static QString err_msg(QProcess::ProcessError err_no) return "An unknown error occurred. This is the default return value of error()."; } } +} QString Connection::createTableSqlCommand(const QString &tblname) { @@ -757,7 +657,7 @@ QString Connection::createTableSqlCommand(const QString &tblname) qfError() << msg; return QString(); } - else if(q.next()) { + if(q.next()) { return q.value(1).toString() + ";"; } return QString(); @@ -799,7 +699,7 @@ QString Connection::dumpTableSqlCommand(const QString &tblname) } return QString(); } - else if(driverName().endsWith(QLatin1String("PSQL"))) { + if(driverName().endsWith(QLatin1String("PSQL"))) { return dumpSqlTable_psql(tblname, true); } return "unsupported for " + driverName(); @@ -944,7 +844,7 @@ QString Connection::currentSchema() const ret = q.value(0).toString(); } } - else if(driverName().endsWith(QLatin1String("SQLITE"))) { + else if(driverName().endsWith(QLatin1String("SQLITE"))) { // NOLINT(bugprone-branch-clone) ret = "main"; } else { diff --git a/libqf/libqfcore/src/sql/dbenumcache.cpp b/libqf/libqfcore/src/sql/dbenumcache.cpp index 48766204c..4cee11146 100644 --- a/libqf/libqfcore/src/sql/dbenumcache.cpp +++ b/libqf/libqfcore/src/sql/dbenumcache.cpp @@ -37,7 +37,7 @@ DbEnum DbEnumCache::EnumList::valueForId(const QString& group_id) const } DbEnumCache::DbEnumCache(const QString &connection_name) - : m_connectionName(connection_name) + : m_connectionName(connection_name) { if(m_connectionName.isEmpty()) { static QString cn = QString::fromLatin1(QSqlDatabase::defaultConnection); @@ -46,11 +46,7 @@ DbEnumCache::DbEnumCache(const QString &connection_name) qfInfo() << "creating new DbEnumCache for connection name:" << m_connectionName; } -DbEnumCache::~DbEnumCache() -{ - // next line can cause seg fault on app exit because logDevice() can be destroyied before - //qfInfo() << "destroying DbEnumCache for connection name:" << m_connectionName; -} +DbEnumCache::~DbEnumCache() = default; void DbEnumCache::clear(const QString & group_name) { @@ -92,7 +88,7 @@ DbEnumCache& DbEnumCache::instanceForConnection(const QString &connection_name) QString cn = connection_name; if(cn.isEmpty()) cn = QSqlDatabase::defaultConnection; - if(instances.count(cn) == 0) { + if(!instances.contains(cn)) { instances.emplace(cn, DbEnumCache{cn}); } return instances[cn]; diff --git a/libqf/libqfcore/src/sql/dbfsattrs.cpp b/libqf/libqfcore/src/sql/dbfsattrs.cpp deleted file mode 100644 index 701671db9..000000000 --- a/libqf/libqfcore/src/sql/dbfsattrs.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "dbfsattrs.h" - -#include - -using namespace qf::core::sql; - -const DbFsAttrs &DbFsAttrs::sharedNull() -{ - static DbFsAttrs n = DbFsAttrs(SharedDummyHelper()); - return n; -} - -DbFsAttrs::DbFsAttrs(DbFsAttrs::SharedDummyHelper) -{ - d = new Data(Invalid); -} - -DbFsAttrs::DbFsAttrs() -{ - *this = sharedNull(); -} - -DbFsAttrs::DbFsAttrs(DbFsAttrs::NodeType t) -{ - d = new Data(t); -} - -QChar DbFsAttrs::typeChar() const -{ - if(type() == Dir) - return 'd'; - if(type() == File) - return 'f'; - return QChar(); -} - -QString DbFsAttrs::typeName() const -{ - if(type() == Dir) - return QStringLiteral("DIR"); - if(type() == File) - return QStringLiteral("FILE"); - return QStringLiteral("INVALID"); -} - -QString DbFsAttrs::toString() const -{ - QString ret; - if(isNull()) - ret += "NULL - "; - else if(type() == Dir && inode() == 0 && pinode() == 0) - ret += "ROOT - "; - ret += "inode: " + QString::number(inode()) + ", "; - ret += "pinode: " + QString::number(pinode()) + ", "; - ret += "type: " % typeName() % ", "; - ret += "name: " + name(); - return ret; -} - diff --git a/libqf/libqfcore/src/sql/dbfsattrs.h b/libqf/libqfcore/src/sql/dbfsattrs.h deleted file mode 100644 index 4452efd97..000000000 --- a/libqf/libqfcore/src/sql/dbfsattrs.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef QF_CORE_SQL_DBFSATTRS_H -#define QF_CORE_SQL_DBFSATTRS_H - -#include "../core/coreglobal.h" -#include "../core/utils.h" - -#include -#include - -namespace qf { -namespace core { -namespace sql { - -class QFCORE_DECL_EXPORT DbFsAttrs -{ -public: - enum NodeType {Invalid, Dir, File}; -public: - DbFsAttrs(); - DbFsAttrs(NodeType t); -private: - class SharedDummyHelper {}; - class Data : public QSharedData - { - public: - int inode = -1; - int pinode = -1; - QDateTime mtime; - NodeType type = Invalid; - QString name; - int size = 0; - explicit Data(NodeType t) : type(t) {} - }; - QSharedDataPointer d; - - DbFsAttrs(SharedDummyHelper); - static const DbFsAttrs& sharedNull(); - QF_SHARED_CLASS_FIELD_RW(int, i, setI, node) - QF_SHARED_CLASS_FIELD_RW(int, p, setP, inode) - QF_SHARED_CLASS_FIELD_RW(NodeType, t, setT, ype) - QF_SHARED_CLASS_FIELD_RW(QString, n, setN, ame) - QF_SHARED_CLASS_FIELD_RW(int, s, setS, ize) - QF_SHARED_CLASS_FIELD_RW(QDateTime, m, setM, time) -public: - bool isNull() const {return d == sharedNull().d;} - QChar typeChar() const; - QString typeName() const; - QString toString() const; -}; - -}}} - -#endif // QF_CORE_SQL_DBFSATTRS_H diff --git a/libqf/libqfcore/src/sql/dbfsdriver.cpp b/libqf/libqfcore/src/sql/dbfsdriver.cpp deleted file mode 100644 index 2222141ed..000000000 --- a/libqf/libqfcore/src/sql/dbfsdriver.cpp +++ /dev/null @@ -1,919 +0,0 @@ -#include "dbfsdriver.h" -#include "connection.h" -#include "query.h" -#include "tablelocker.h" -#include "../model/sqltablemodel.h" -#include "../core/assert.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define sqlDebug qfDebug - -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -static const auto SkipEmptyParts = QString::SkipEmptyParts; -#else -static const auto SkipEmptyParts = Qt::SkipEmptyParts; -#endif - -using namespace qf::core::sql; - -static QMutex s_cacheRemoveMutex; - -//static const QString COL_ID("id"); -static const QString COL_INODE("inode"); -static const QString COL_PINODE("pinode"); -static const QString COL_TYPE("type"); -static const QString COL_NAME("name"); -static const QString COL_META("meta"); -static const QString COL_MTIME("mtime"); -static const QString COL_DATA("data"); -static const QString COL_SIZE("size"); - -static const QString O_LOCK_EXCLUSIVE = QStringLiteral("EXCLUSIVE"); -//static const bool O_CREATE = true; -//static const bool O_DELETE = true; -static QString CRM_SINGLE_STR = QStringLiteral("SINGLE"); -static QString CRM_RECURSIVE_STR = QStringLiteral("RECURSIVE"); -static QString CRM_NOOP_STR = QStringLiteral("NOOP"); -static const bool O_POST_NOTIFY = true; - -const QString DbFsDriver::CHANNEL_INVALIDATE_DBFS_DRIVER_CACHE = QStringLiteral("invalidate_dbfs_driver_cache"); - -DbFsDriver::DbFsDriver(QObject *parent) - : QObject(parent) -{ - m_connectionName = QLatin1String(QSqlDatabase::defaultConnection); -} - -DbFsDriver::~DbFsDriver() -{ -} - -DbFsAttrs DbFsDriver::attributes(const QString &path) -{ - //qfLogFuncFrame() << path; - QString spath = cleanPath(path); - if(!m_fileAttributesCache.contains(spath)) { - DbFsAttrs a = readAttrs(spath, 0); - m_fileAttributesCache[spath] = a; - } - DbFsAttrs ret = m_fileAttributesCache.value(spath); - //qfDebug() << ret.toString(); - return ret; -} - -QList DbFsDriver::childAttributes(const QString &parent_path) -{ - qfLogFuncFrame() << parent_path; - QString clean_ppath = cleanPath(parent_path); - QList ret; - if(m_directoryCache.contains(clean_ppath)) { - Q_FOREACH(QString entry, m_directoryCache.value(clean_ppath)) { - QString p = joinPath(clean_ppath, entry); - ret << attributes(p); - } - } - else { - QStringList dir_entry_list; - DbFsAttrs parent_attrs = attributes(clean_ppath); - if(!parent_attrs.isNull() && parent_attrs.type() == DbFsAttrs::Dir) { - int parent_inode = parent_attrs.inode(); - ret = readChildAttrs(parent_inode); - Q_FOREACH(auto attrs, ret) { - QString path = joinPath(clean_ppath, attrs.name()); - //qfDebug() << clean_ppath + "name:" << attrs.name() << "->" << path; - m_fileAttributesCache[path] = attrs; - dir_entry_list << attrs.name(); - } - } - else { - qfWarning() << "Node on path:" << parent_path << "is not dir:" << parent_attrs.toString(); - } - m_directoryCache[clean_ppath] = dir_entry_list; - } - return ret; -} - -Connection DbFsDriver::connection() -{ - QSqlDatabase db = QSqlDatabase::database(connectionName(), false); - QF_ASSERT_EX(db.isOpen(), tr("Connection '%1' is not open!").arg(connectionName())); - /* - if(!m_isNotifyRegistered) { - auto drv = db.driver(); - bool ok = drv->subscribeToNotification(CHANNEL_INVALIDATE_DBFSDRIVER_CACHE); - if(!ok) { - qfError() << "Cannot subscribe channel" << CHANNEL_INVALIDATE_DBFSDRIVER_CACHE << "for notification"; - } - else { - connect(drv, SIGNAL(notification(QString,QSqlDriver::NotificationSource,QVariant)), this, SLOT(onSqlNotify(QString,QSqlDriver::NotificationSource,QVariant))); - } - m_isNotifyRegistered = true; - } - */ - return Connection(db); -} - -bool DbFsDriver::checkWritePermissions() -{ - bool ok = true; - return ok; -} - -static QByteArray truncateArray(const QByteArray &ba, int new_size) -{ - QByteArray ret = ba; - if(new_size >= 0) { - int orig_size = ret.size(); - ret.resize(new_size); - for(int i=orig_size; i pf = splitPathFile(spath); - DbFsAttrs patt = readAttrs(pf.first, 0); - if(patt.isNull()) { - qfWarning() << "cannot create node:" << spath << " parent dir not exits"; - break; - } - if(patt.type() != DbFsAttrs::Dir) { - qfWarning() << "cannot create node:" << spath << " parent path is not dir"; - break; - } - QByteArray ba = data; - if(options & PN_TRUNCATE) { - ba = truncateArray(ba, new_size); - } - att.setName(pf.second); - att.setType(new_attrs.type()); - att.setPinode(patt.inode()); - ret = sqlInsertNode(att, ba); - - invalid_file_cache_path = spath; - invalid_file_cache_mode = CRM_Single; - invalid_dir_cache_path = pf.first; - invalid_dir_cache_mode = CRM_Single; - } - else { - qfWarning() << "PUT to not existing path:" << spath; - break; - } - } - else { - if(!(options & PN_OVERRIDE)) { - qfError() << "Internal Error - cannot override node:" << spath; - break; - } - if(options & PN_DELETE) { - if(att.type() == DbFsAttrs::Dir && !readChildAttrs(att.inode()).isEmpty()) { - qfWarning() << "cannot delete not empty path:" << spath; - break; - } - if(sqlDeleteNode(att.inode())) { - ret = att; - - invalid_file_cache_path = spath; - invalid_file_cache_mode = CRM_Single; - QPair pf = splitPathFile(spath); - invalid_dir_cache_path = pf.first; - invalid_dir_cache_mode = CRM_Single; - } - } - else if(options & PN_RENAME) { - QPair pf = splitPathFile(spath); - QString new_path = joinPath(pf.first, new_attrs.name()); - DbFsAttrs check_new_exists_attrs = readAttrs(new_path, 0); - if(!check_new_exists_attrs.isNull()) { - /// old nd new name have to be a same type - if(att.type() != check_new_exists_attrs.type()) { - qfWarning() << spath << "and" << new_path << "are of different types"; - break; - } - /// remove existing file/dir with new name - sqlDeleteNode(check_new_exists_attrs.inode()); - } - if(sqlRenameNode(att.inode(), new_attrs.name())) { - att.setName(new_attrs.name()); - ret = att; - - invalid_file_cache_path = new_path; - invalid_file_cache_mode = CRM_Recursive; - invalid_file_cache_path2 = spath; - invalid_file_cache_mode2 = CRM_Recursive; - invalid_dir_cache_path = pf.first; - invalid_dir_cache_mode = CRM_Recursive; - } - } - else { - if(att.type() != DbFsAttrs::File) { - qfWarning() << "Data can be put to FILE node only:" << spath; - break; - } - QByteArray ba = data; - if(options & PN_TRUNCATE) { - DbFsAttrs a = sqlSelectNode(att.inode(), &ba); - if(a.isNull()) { - qfWarning() << "Data canot be loaded to be truncated:" << spath; - break; - } - ba = truncateArray(ba, new_size); - } - if(sqlUpdateNode(att.inode(), ba)) { - invalid_file_cache_path = spath; - invalid_file_cache_mode = CRM_Single; - ret = att; - } - } - } - locker.commit(); - cacheRemove(invalid_file_cache_path, invalid_file_cache_mode, invalid_dir_cache_path, invalid_dir_cache_mode, O_POST_NOTIFY); - if(invalid_file_cache_mode2 != CRM_Noop) { - cacheRemove(invalid_file_cache_path2, invalid_file_cache_mode2, QString(), CRM_Noop, O_POST_NOTIFY); - } - } while(false); - - return ret; -} - -QString DbFsDriver::cacheRemoveModeToString(DbFsDriver::CacheRemoveMode opt) -{ - switch(opt) { - case CRM_Single: - return CRM_SINGLE_STR; - case CRM_Recursive: - return CRM_RECURSIVE_STR; - default: - return CRM_NOOP_STR; - } - return CRM_NOOP_STR; -} - -DbFsDriver::CacheRemoveMode DbFsDriver::cacheRemoveModeFromString(const QString &str) -{ - if(str == CRM_SINGLE_STR) - return CRM_Single; - if(str == CRM_RECURSIVE_STR) - return CRM_Recursive; - return CRM_Noop; -} - -template -void DbFsDriver::cacheRemove_helper(T &map, const QString &path, DbFsDriver::CacheRemoveMode mode) -{ - qfLogFuncFrame() << "path:" << path << DbFsDriver::cacheRemoveModeToString(mode); - if(mode != DbFsDriver::CRM_Noop) { - auto it = map.lowerBound(path); - while(it != map.end()) { - QString s = it.key(); - qfDebug() << "checking:" << s; - if(s.startsWith(path)) { - if(mode == DbFsDriver::CRM_Single) { - if(s == path) { - qfDebug() << "removing" << s << "from cache"; - map.erase(it); - break; - } - else { - ++it; - } - } - else { - if(path.isEmpty() || s.length() == path.length() || s[path.length()] == '/') { - qfDebug() << "removing" << s << "from cache"; - it = map.erase(it); - } - else { - ++it; - } - } - } - else { - break; - } - } - } -} - -void DbFsDriver::cacheRemove(const QString &file_path, CacheRemoveMode file_mode, const QString &dir_path, CacheRemoveMode dir_mode, bool post_notify) -{ - qfLogFuncFrame() << "file:" << file_path << cacheRemoveModeToString(file_mode) << "dir:" << dir_path << cacheRemoveModeToString(dir_mode) << "post notify:" << post_notify; - { - QMutexLocker locker(&s_cacheRemoveMutex); - cacheRemove_helper(m_fileAttributesCache, file_path, file_mode); - cacheRemove_helper(m_directoryCache, dir_path, dir_mode); - } - if(post_notify) { - QString pay_load = QString("{") - + "\"file\": {\"path\":\"%1\", \"mode\": \"%2\"}, " - + "\"dir\": {\"path\":\"%3\", \"mode\": \"%4\"}, " - + "\"pid\": \"%5\"" - + "}"; - pay_load = pay_load.arg(file_path).arg(cacheRemoveModeToString(file_mode)) - .arg(dir_path).arg(cacheRemoveModeToString(dir_mode)) - .arg(QCoreApplication::applicationPid()); - postAttributesChangedNotify(pay_load); - } -} - -void DbFsDriver::postAttributesChangedNotify(const QString &pay_load) -{ - Query q(connection()); - QString qs = "NOTIFY " + CHANNEL_INVALIDATE_DBFS_DRIVER_CACHE + ", '" + pay_load + "'"; - sqlDebug() << qs; - if(!q.exec(qs)) { - qfError() << "postAttributesChangedNotify Error:" << qs << q.lastError().text(); - } -} - -void DbFsDriver::onSqlNotify(const QString &channel, QSqlDriver::NotificationSource source, const QVariant &payload) -{ - qfLogFuncFrame() << channel << payload; - //qfWarning() << "GOT NOTIFY" << channel << payload; - if(source != QSqlDriver::SelfSource) { - if(channel == CHANNEL_INVALIDATE_DBFS_DRIVER_CACHE) { - QJsonParseError err; - QJsonDocument json = QJsonDocument::fromJson(payload.toString().toUtf8(), &err); - if(err.error == QJsonParseError::NoError) { - QString pid = json.object().value("pid").toString(); - if(pid == QString::number(QCoreApplication::applicationPid())) { - // ignore own messages - qfDebug() << "self notification - ignored"; - } - else { - QJsonObject o = json.object().value("file").toObject(); - QString file_path = o.value("path").toString(); - CacheRemoveMode file_mode = DbFsDriver::cacheRemoveModeFromString(o.value("mode").toString()); - o = json.object().value("dir").toObject(); - QString dir_path = o.value("path").toString(); - CacheRemoveMode dir_mode = DbFsDriver::cacheRemoveModeFromString(o.value("mode").toString()); - - cacheRemove(file_path, file_mode, dir_path, dir_mode, !O_POST_NOTIFY); - } - - } - else { - qfError() << "invalid SQL notify - channel:" << channel << " payload:" << payload << "error:" << err.errorString(); - } - } - } -} - -DbFsAttrs DbFsDriver::sqlSelectNode(int inode, QByteArray *pdata) -{ - DbFsAttrs ret; - QString cols = attributesColumns(); - if(pdata) - cols + ", " + COL_DATA; - QString qs = "SELECT " + cols + " FROM " + tableName() + " WHERE inode=" + QString::number(inode); - Connection conn = connection(); - Query q(conn); - //sqlDebug() << qs; - do { - if(!q.exec(qs)) { - qfError() << "Error get file:" << qs << '\n' << q.lastError().text(); - break; - } - if(!q.next()) { - qfError() << "Error get file: empty result set!"; - break; - } - if(pdata) { - QByteArray ba = q.value(COL_DATA).toByteArray(); - *pdata = ba; - } - ret = attributesFromQuery(q); - } while(false); - return ret; -} - -DbFsAttrs DbFsDriver::sqlInsertNode(const DbFsAttrs &attrs, const QByteArray &data) -{ - qfLogFuncFrame() << attrs.toString(); - Connection conn = connection(); - Query q(conn); - /* - QString qs = "SELECT nextval('" + tableName() + "_id_seq')"; - sqlDebug() << qs; - bool ok = q.exec(qs); - if(!ok) { - qfError() << "SQLINSERTNODE Error:" << qs << '\n' << q.lastError().text(); - return DbFsAttrs(); - } - q.next(); - int id = q.value(0).toInt(); - if(id <= 0) { - qfError() << "SQLINSERTNODE internal error, sequence number is invalid!"; - return DbFsAttrs(); - } - */ - DbFsAttrs ret = attrs; - //ret.setId(id); - //ret.setSnapshot(latestSnapshotNumber()); - QString qs = "INSERT INTO " + tableName() + " (" - //+ COL_ID + ", " - //+ COL_INODE + ", " - + COL_PINODE + ", " - + COL_MTIME + ", " - + COL_TYPE + ", " - + COL_NAME + ", " - + COL_DATA - + ") " - + "VALUES (" - //+ QString::number(ret.id()) + ", " - //+ QString::number(ret.inode()) + ", " - + QString::number(ret.pinode()) + ", " - + "now(), " - + '\'' + ret.typeChar() + "', " - + '\'' + ret.name() + "', " - + ":data" - + ")"; - bool ok = q.prepare(qs); - if(!ok) { - qfError() << "SQLINSERTNODE Error:" << qs << '\n' << q.lastError().text(); - return DbFsAttrs(); - } - q.bindValue(":data", data); - sqlDebug() << qs; - ok = q.exec(); - if(!ok) { - qfError() << "SQLINSERTNODE Error:" << qs << '\n' << q.lastError().text(); - return DbFsAttrs(); - } - int inode = q.lastInsertId().toInt(); - if(inode <= 0) { - qfError() << "SQLINSERTNODE lastInsertId Error:" << qs << '\n' << q.lastError().text(); - return DbFsAttrs(); - } - ret.setInode(inode); - return ret; -} - -bool DbFsDriver::sqlDeleteNode(int inode) -{ - qfLogFuncFrame() << inode; - Query q(connection()); - - QString qs = "DELETE FROM " + tableName() + " WHERE inode=" + QString::number(inode); - sqlDebug() << qs; - bool ok = q.exec(qs); - if(!ok) { - qfError() << "SQLDELETENODE Error:" << qs << '\n' << q.lastError().text(); - return false; - } - return true; -} - -bool DbFsDriver::sqlUpdateNode(int inode, const QByteArray &data) -{ - qfLogFuncFrame() << inode; - Connection conn = connection(); - Query q(conn); - QString qs = "UPDATE " + tableName() + " SET " - + COL_MTIME + "=now(), " - + COL_DATA + "=:data" - + " WHERE " + COL_INODE + "=:inode"; - bool ok = q.prepare(qs); - if(!ok) { - qfError() << "SQLUPDATENODE Error:" << qs << '\n' << q.lastError().text(); - return false; - } - q.bindValue(":data", data); - q.bindValue(":inode", inode); - sqlDebug() << qs; - ok = q.exec(); - if(!ok) { - qfError() << "SQLUPDATENODE Error:" << qs << '\n' << q.lastError().text(); - return false; - } - int n = q.numRowsAffected(); - if(n == 0) { - qfError() << "SQLUPDATENODE Error 0 rows affected:" << qs; - return false; - } - return true; -} - -bool DbFsDriver::sqlRenameNode(int inode, const QString &new_name) -{ - qfLogFuncFrame() << inode << new_name; - Connection conn = connection(); - Query q(conn); - QString qs = "UPDATE " + tableName() + " SET " - + COL_MTIME + "=now(), " - + COL_NAME + "=:name" - + " WHERE " + COL_INODE + "=:inode"; - bool ok = q.prepare(qs); - if(!ok) { - qfError() << "SQLUPDATENODE Error:" << qs << '\n' << q.lastError().text(); - return false; - } - q.bindValue(":name", new_name); - q.bindValue(":inode", inode); - sqlDebug() << qs; - ok = q.exec(); - if(!ok) { - qfError() << "SQLUPDATENODE Error:" << qs << '\n' << q.lastError().text(); - return false; - } - int n = q.numRowsAffected(); - if(n == 0) { - qfError() << "SQLUPDATENODE Error 0 rows affected:" << qs; - return false; - } - return true; -} - -bool DbFsDriver::checkDbFs() -{ - qfLogFuncFrame(); - Connection conn = connection(); - bool ok = conn.tableExists(tableName()); - return ok; -} - -bool DbFsDriver::createDbFs() -{ - qfLogFuncFrame(); - bool init_ok = false; - Connection conn = connection(); - do { - Query q(conn); - if(conn.tableExists(tableName())) { - qfWarning() << "Cannot create DBFS, table" << tableName() << "exists already!"; - return false; - } - Transaction transaction(conn); - { - /// create table - qfInfo() << "Creating table:" << tableName(); - QStringList qlst; - qlst << "CREATE TABLE " + tableName() + " " + - "(" - + COL_INODE + " serial NOT NULL, " - + COL_PINODE + " integer NOT NULL DEFAULT -1, " - + COL_MTIME + " timestamp without time zone DEFAULT now(), " - + COL_TYPE + " character(1) NOT NULL DEFAULT 'f'::bpchar, " - + COL_NAME + " character varying, " - + COL_META + " character varying, " - + COL_DATA + " bytea, " - + "CONSTRAINT " + tableName() + "_pkey PRIMARY KEY (" + COL_INODE + "), " - + "CONSTRAINT " + tableName() + "_pinode_name_key UNIQUE (" + COL_PINODE + ", " + COL_NAME + ") " - + ") WITH (OIDS=FALSE)"; - qlst << "COMMENT ON COLUMN " + tableName() + ".pinode IS 'number of parent directory inode'"; - qlst << "CREATE INDEX " + tableName() + "_pinode_idx ON " + tableName() + " (pinode)"; - Query q(conn); - init_ok = q.execCommands(qlst); - if(!init_ok) { - qfError() << "Error creating DBFS table" << tableName(); - break; - } - } - transaction.commit(); - } while(false); - return init_ok; -} - -QString DbFsDriver::attributesColumns(const QString &table_alias) -{ - QString ta = table_alias; - if(!ta.isEmpty()) - ta += '.'; - QString ret = - ta%COL_INODE%", "% - ta%COL_PINODE%", "% - ta%COL_MTIME%", "% - ta%COL_TYPE%", "% - ta%COL_NAME%", "% - "length("%ta%COL_DATA%") AS "%COL_SIZE%", "% - ta%COL_META; - return ret; -} - -DbFsAttrs DbFsDriver::attributesFromQuery(const Query &q) -{ - qfLogFuncFrame(); - DbFsAttrs ret; - ret.setInode(q.value(COL_INODE).toInt()); - ret.setPinode(q.value(COL_PINODE).toInt()); - ret.setMtime(q.value(COL_MTIME).toDateTime()); - ret.setName(q.value(COL_NAME).toString()); - DbFsAttrs::NodeType node_type = DbFsAttrs::Invalid; - QString s = q.value(COL_TYPE).toString(); - if(!s.isEmpty()) { - QChar c = s.at(0).toLower(); - if(c == 'd') - node_type = DbFsAttrs::Dir; - else if(c == 'f') - node_type = DbFsAttrs::File; - } - ret.setSize(q.value(COL_SIZE).toInt()); - ret.setType(node_type); - return ret; -} - -DbFsAttrs DbFsDriver::readAttrs(const QString &spath, int pinode) -{ - qfLogFuncFrame() << "path:" << spath; - static DbFsAttrs root_attrs; - if(root_attrs.isNull()) { - root_attrs.setType(DbFsAttrs::Dir); - root_attrs.setInode(0); - root_attrs.setPinode(0); - } - - QStringList pathlst = splitPath(spath); - - DbFsAttrs ret; - if(pathlst.isEmpty()) { - ret = root_attrs; - } - else { - QString cols = attributesColumns(); - QString single_select = "SELECT %3 FROM " + tableName() + " WHERE name='%1' AND pinode=(%2)"; - QString qs = QString::number(pinode); - for(int i=0; i DbFsDriver::readChildAttrs(int parent_inode) -{ - qfLogFuncFrame() << "parent_inode:" << parent_inode; - QList ret; - Connection conn = connection(); - Query q(conn); - QString cols = attributesColumns(); - QString qs = "SELECT " + cols + " FROM " + tableName() - + " WHERE " + COL_PINODE + '=' + QString::number(parent_inode); - sqlDebug() << qs; - bool ok = q.exec(qs); - if(ok) { - while (q.next()) { - DbFsAttrs att = attributesFromQuery(q); - qfDebug() << "\t adding child:" << att.toString(); - ret << att; - } - } - else { - qfError() << "SQL ERROR:" << qs << '\n' << q.lastError().text(); - } - return ret; -} - -QByteArray DbFsDriver::get(const QString &path, bool *pok) -{ - qfLogFuncFrame() << path; - QByteArray ret; - QString spath = cleanPath(path); - bool ok = false; - do { - DbFsAttrs attrs = attributes(spath); - if(attrs.isNull()) { - qfWarning() << "Cannot get attributes for:" << spath; - break; - } - int inode = attrs.inode(); - QString cols = attributesColumns() + ", " + COL_DATA; - QString qs = "SELECT " + cols + " FROM " + tableName() + " WHERE inode=" + QString::number(inode); - Connection conn = connection(); - Query q(conn); - sqlDebug() << qs; - if(!q.exec(qs)) { - qfError() << "Error get file:" << qs << '\n' << q.lastError().text(); - break; - } - if(!q.next()) { - qfError() << "Error get file: empty result set!"; - break; - } - DbFsAttrs attrs2 = attributesFromQuery(q); - if(attrs2.mtime() > attrs.mtime()) { - /// cached attributes are older than loded ones, refresh cache record - qfDebug() << "Cached data invalid and updated from data query."; - m_fileAttributesCache[spath] = attrs2; - } - ret = q.value(COL_DATA).toByteArray(); - ok = true; - } while(false); - if(pok) - *pok = ok; - qfDebug() << "\t returned" << ret.length() << "bytes od data:" << ((ret.size() < 100)? ret : ret.mid(100)); - return ret; -} - -bool DbFsDriver::put(const QString &path, const QByteArray &data, bool create_if_not_exist) -{ - qfLogFuncFrame() << path << ((data.size() < 100)? data : data.mid(100)); - - QString spath = cleanPath(path); - int opts = 0; - opts |= PN_OVERRIDE; - if(create_if_not_exist) { - opts |= PN_CREATE; - } - DbFsAttrs att = put_helper(spath, DbFsAttrs::File, data, opts, -1); - return !att.isNull(); -} - -bool DbFsDriver::putmkdir(const QString &path, const QByteArray &data) -{ - qfLogFuncFrame() << path << ((data.size() < 100)? data : data.mid(100)); - - QString spath = cleanPath(path); - auto pf = splitPathFile(spath); - if(mkdirs(pf.first)) { - return put(path, data, true); - } - return false; -} - -bool DbFsDriver::truncate(const QString &path, int new_size) -{ - qfLogFuncFrame() << path; - - QString spath = cleanPath(path); - int opts = 0; - opts |= PN_OVERRIDE; - opts |= PN_TRUNCATE; - //opts |= PN_CREATE; - DbFsAttrs att = put_helper(spath, DbFsAttrs::File, QByteArray(), opts, new_size); - return !att.isNull(); -} - -bool DbFsDriver::mkfile(const QString &path, const QByteArray &data) -{ - qfLogFuncFrame() << path; - bool ok = mknod(path, DbFsAttrs::File, data); - return ok; -} - -bool DbFsDriver::mkdir(const QString &path) -{ - qfLogFuncFrame() << path; - bool ok = mknod(path, DbFsAttrs::Dir, QByteArray()); - return ok; -} - -bool DbFsDriver::mkdirs(const QString &path) -{ - qfLogFuncFrame() << path; - - QStringList dirs = splitPath(cleanPath(path)); - QString new_path; - for (int i = 0; i < dirs.count(); ++i) { - new_path = (new_path.isEmpty())? dirs[i]: new_path + '/' + dirs[i]; - DbFsAttrs attrs = attributes(new_path); - if(attrs.isNull()) { - if(!mkdir(new_path)) - return false; - } - else if(attrs.type() == DbFsAttrs::File) { - qfError() << "Cannot override exiting file:" << new_path; - return false; - } - } - return true; -} - -bool DbFsDriver::mknod(const QString &path, DbFsAttrs::NodeType node_type, const QByteArray &data) -{ - qfLogFuncFrame() << path; - - QString spath = cleanPath(path); - int opts = 0; - //opts |= PN_OVERRIDE; - opts |= PN_CREATE; - DbFsAttrs att = put_helper(spath, node_type, data, opts, -1); - return !att.isNull(); -} - -bool DbFsDriver::rmnod(const QString &path) -{ - QString spath = cleanPath(path); - int opts = 0; - opts |= PN_DELETE; - opts |= PN_OVERRIDE; - DbFsAttrs att = put_helper(spath, DbFsAttrs::Invalid, QByteArray(), opts, -1); - return !att.isNull(); -} - -bool DbFsDriver::rename(const QString &old_path, const QString &new_path) -{ - qfLogFuncFrame() << old_path << "->" << new_path; - - QString sopath = cleanPath(old_path); - QString snpath = cleanPath(new_path); - QPair opf = splitPathFile(sopath); - QPair npf = splitPathFile(snpath); - if(opf.first != npf.first) { - qfError() << old_path << "->" << new_path << "move across directories is not supported yet"; - return false; - } - int opts = 0; - opts |= PN_OVERRIDE; - opts |= PN_RENAME; - DbFsAttrs att; - att.setName(npf.second); - att = put_helper(sopath, att, QByteArray(), opts, -1); - return !att.isNull(); -} - -QPair DbFsDriver::splitPathFile(const QString &path) -{ - QPair ret; - int ix = path.lastIndexOf('/'); - if(ix < 0) { - ret.second = path; - } - else { - ret.first = path.mid(0, ix); - ret.second = path.mid(ix + 1); - } - return ret; -} - -QStringList DbFsDriver::splitPath(const QString &path) -{ - QStringList ret = path.split('/', SkipEmptyParts); - return ret; -} - -QString DbFsDriver::joinPath(const QString &p1, const QString &p2) -{ - QString ret = p1; - if(!p1.isEmpty()) - ret += '/'; - ret += p2; - return ret; -} - -QString DbFsDriver::cleanPath(const QString &path) -{ - QString ret = QDir::cleanPath(path); - while(ret.startsWith('/')) - ret = ret.mid(1); - while(ret.endsWith('/')) - ret = ret.mid(0, ret.length() - 1); - //if(ret.isEmpty() && !path.isEmpty() && path[0] == '/') - // ret = "/"; - return ret; -} - diff --git a/libqf/libqfcore/src/sql/dbfsdriver.h b/libqf/libqfcore/src/sql/dbfsdriver.h deleted file mode 100644 index 14953c9e4..000000000 --- a/libqf/libqfcore/src/sql/dbfsdriver.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef QF_CORE_SQL_DBFSDRIVER_H -#define QF_CORE_SQL_DBFSDRIVER_H - -#include "dbfsattrs.h" -#include "connection.h" - -#include "../core/coreglobal.h" -#include "../core/utils.h" -#include "../utils/table.h" - -#include -#include - -#include - -namespace qf { -namespace core { -namespace sql { - -class Query; - -class QFCORE_DECL_EXPORT DbFsDriver : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString connectionName READ connectionName WRITE setConnectionName NOTIFY connectionNameChanged) - Q_PROPERTY(QString tableName READ tableName WRITE setTableName NOTIFY tableNameChanged) -public: - enum PutNodeOptions {PN_CREATE = 1, PN_TRUNCATE = 2, PN_OVERRIDE = 4, PN_DELETE = 8, PN_RENAME = 16}; - static const QString CHANNEL_INVALIDATE_DBFS_DRIVER_CACHE; -private: - enum CacheRemoveMode {CRM_Noop, CRM_Single, CRM_Recursive}; -public: - explicit DbFsDriver(QObject *parent = nullptr); - ~DbFsDriver() Q_DECL_OVERRIDE; - - QF_PROPERTY_IMPL(QString, c, C, onnectionName) - QF_PROPERTY_IMPL2(QString, t, T, ableName, QStringLiteral("dbfs")) - - bool checkDbFs(); - bool createDbFs(); - DbFsAttrs attributes(const QString &path); - QList childAttributes(const QString &parent_path); - QByteArray get(const QString &path, bool *pok = nullptr); - bool put(const QString &path, const QByteArray &data, bool create_if_not_exist = false); - /// create all the necessarry directories and file - bool putmkdir(const QString &path, const QByteArray &data); - bool truncate(const QString &path, int new_size); - bool mkfile(const QString &path, const QByteArray &data = QByteArray()); - bool mkdir(const QString &path); - bool mkdirs(const QString &path); - bool rmnod(const QString &path); - bool rename(const QString &old_path, const QString &new_path); - - static QPair splitPathFile(const QString &path); - static QStringList splitPath(const QString &path); - static QString joinPath(const QString &p1, const QString &p2); - static QString cleanPath(const QString &path); -private: - static QString attributesColumns(const QString &table_alias = QString()); - DbFsAttrs attributesFromQuery(const Query &q); - Connection connection(); - - bool checkWritePermissions(); - bool mknod(const QString &path, DbFsAttrs::NodeType node_type, const QByteArray &data); - DbFsAttrs put_helper(const QString &spath, const DbFsAttrs &new_attrs, const QByteArray &data, int options, int new_size); - - static QString cacheRemoveModeToString(CacheRemoveMode opt); - static CacheRemoveMode cacheRemoveModeFromString(const QString &str); - template - void cacheRemove_helper(T &map, const QString &path, DbFsDriver::CacheRemoveMode mode); - void cacheRemove(const QString &file_path, CacheRemoveMode file_mode, const QString &dir_path, CacheRemoveMode dir_mode, bool post_notify); - void postAttributesChangedNotify(const QString &pay_load); - Q_SLOT void onSqlNotify(const QString &channel, QSqlDriver::NotificationSource source, const QVariant &payload); - - DbFsAttrs sqlSelectNode(int inode, QByteArray *pdata = nullptr); - DbFsAttrs sqlInsertNode(const DbFsAttrs &attrs, const QByteArray &data); - bool sqlDeleteNode(int inode); - bool sqlUpdateNode(int inode, const QByteArray &data); - bool sqlRenameNode(int inode, const QString &new_name); - - DbFsAttrs readAttrs(const QString &spath, int pinode); - QList readChildAttrs(int parent_inode); -private: - typedef QMap FileAttributesCache; - FileAttributesCache m_fileAttributesCache; - typedef QMap DirectoryCache; - DirectoryCache m_directoryCache; - int m_latestSnapshotNumber = -1; - //bool m_isNotifyRegistered = false; -}; - -}}} - -#endif // QF_CORE_SQL_DBFSDRIVER_H diff --git a/libqf/libqfcore/src/sql/querybuilder.cpp b/libqf/libqfcore/src/sql/querybuilder.cpp index 46d002091..4e4d0a571 100644 --- a/libqf/libqfcore/src/sql/querybuilder.cpp +++ b/libqf/libqfcore/src/sql/querybuilder.cpp @@ -64,7 +64,7 @@ QString QueryBuilder::buildSelect(const BuildOptions &opts) const { QStringList select_fields; QVariant v = m_queryMap.value(SelectKey); - const SelectTableFieldsList lst = v.value(); + const auto lst = v.value(); for(const SelectTableFields &flds : lst) { if(flds.table.isEmpty()) { select_fields << flds.fields; @@ -99,7 +99,7 @@ QString QueryBuilder::JoinDefinition::buildString(const QueryBuilder::BuildOptio QString relation; if(joinRelation.isValid()) { if(joinRelation.userType() == qMetaTypeId()) { - QueryBuilder qb = joinRelation.value(); + auto qb = joinRelation.value(); relation = qb.toString(opts); } else { @@ -148,7 +148,7 @@ QString QueryBuilder::buildFrom(const QueryBuilder::BuildOptions &opts) const { QString ret; QVariant v = m_queryMap.value(FromKey); - const JoinDefinitionList lst = v.value(); + const auto lst = v.value(); for(const JoinDefinition &join_def : lst) { ret += ' ' + join_def.buildString(opts); } @@ -170,7 +170,7 @@ void QueryBuilder::addSelect(const QueryBuilder::SelectTableFields &sf, const QS if(!flags.isEmpty()) m_queryMap[SelectFlagsKey] = flags; QVariant v = m_queryMap.value(SelectKey); - SelectTableFieldsList lst = v.value(); + auto lst = v.value(); lst << sf; v = QVariant::fromValue(lst); m_queryMap[SelectKey] = v; @@ -339,7 +339,7 @@ void QueryBuilder::addJoin(const QueryBuilder::JoinDefinition &jd) { qfLogFuncFrame(); QVariant v = m_queryMap.value(FromKey); - JoinDefinitionList lst = v.value(); + auto lst = v.value(); lst << jd; v = QVariant::fromValue(lst); m_queryMap[FromKey] = v; diff --git a/libqf/libqfcore/src/sql/tablelocker.cpp b/libqf/libqfcore/src/sql/tablelocker.cpp deleted file mode 100644 index c2df71d4b..000000000 --- a/libqf/libqfcore/src/sql/tablelocker.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "tablelocker.h" - -#include "query.h" - -#include "../core/log.h" - -#include - -using namespace qf::core::sql; - -TableLocker::TableLocker(const Connection &conn, const QString &table_name, const QString &lock_type) - : Transaction(conn), m_tableName(table_name), m_lockType(lock_type) -{ - lock(); -} - -TableLocker::~TableLocker() -{ -} - -void TableLocker::lock() -{ - Query q(m_connection); - QString qs = "LOCK TABLE " + m_tableName + " IN " + m_lockType + " MODE"; - qfInfo() << qs; - bool ok = q.exec(qs); - if(!ok) { - qfError() << "LOCK table error -" << q.lastError().text(); - } -} diff --git a/libqf/libqfcore/src/sql/tablelocker.h b/libqf/libqfcore/src/sql/tablelocker.h deleted file mode 100644 index 4f5006b17..000000000 --- a/libqf/libqfcore/src/sql/tablelocker.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef QF_CORE_SQL_TABLELOCKER_H -#define QF_CORE_SQL_TABLELOCKER_H - -#include "transaction.h" - -#include "../core/coreglobal.h" - -namespace qf { -namespace core { -namespace sql { - -class QFCORE_DECL_EXPORT TableLocker : public Transaction -{ -public: - TableLocker(const Connection &conn, const QString &table_name, const QString &lock_type); - ~TableLocker() Q_DECL_OVERRIDE; - - void lock(); -private: - QString m_tableName; - QString m_lockType; -}; - -}}} - -#endif // TABLELOCKER_H diff --git a/libqf/libqfcore/src/utils/clioptions.cpp b/libqf/libqfcore/src/utils/clioptions.cpp index 543c713ea..0d79d9fd9 100644 --- a/libqf/libqfcore/src/utils/clioptions.cpp +++ b/libqf/libqfcore/src/utils/clioptions.cpp @@ -103,8 +103,7 @@ CLIOptions::CLIOptions(QObject *parent) } CLIOptions::~CLIOptions() -{ -} += default; CLIOptions::Option& CLIOptions::addOption(const QString key, const CLIOptions::Option& opt) { @@ -193,14 +192,13 @@ bool CLIOptions::setValue(const QString& name, const QVariant val, bool throw_ex orf.setValue(val); return true; } - else { - QString msg = "setValue():"%val.toString()%" Key '"%name%"' not found."; + QString msg = "setValue():"%val.toString()%" Key '"%name%"' not found."; qfWarning() << msg; if(throw_exc) { throw Exception(msg); } return false; - } + } QString CLIOptions::takeArg() @@ -293,7 +291,7 @@ QPair CLIOptions::applicationDirAndName() const static QString app_dir; static QString app_name; if(app_name.isEmpty()) { - if(m_allArgs.size()) { + if(!m_allArgs.empty()) { #ifdef Q_OS_WIN //static constexpr int MAX_PATH = 1024; QString app_file_path; diff --git a/libqf/libqfcore/src/utils/crypt.cpp b/libqf/libqfcore/src/utils/crypt.cpp index 6adca8e68..b5d1b0048 100644 --- a/libqf/libqfcore/src/utils/crypt.cpp +++ b/libqf/libqfcore/src/utils/crypt.cpp @@ -7,13 +7,14 @@ using namespace qf::core::utils; -static uint32_t myrand() +namespace { +uint32_t myrand() { return QRandomGenerator::global()->generate(); } - +} //=================================================================== -// Crypt +// Crypt //=================================================================== /// http://www.math.utah.edu/~pa/Random/Random.html Crypt::Crypt(Crypt::Generator gen) @@ -36,12 +37,13 @@ Crypt::Generator Crypt::createGenerator(quint32 a, quint32 b, quint32 max_rand) return ret; } -static QByteArray code_byte(quint8 b) +namespace { +QByteArray code_byte(quint8 b) { QByteArray ret; /// hodnoty, ktere nejsou pismena se ukladaji jako cislo /// format cisla je 4 bity cislo % 10 [0-9] + 4 bity cislo / 10 [A-Z] - char buff[] = {0,0,0}; + std::array buff = {0, 0, 0}; if((b>='A' && b<='Z') || (b>='a' && b<='z')) { ret.append(b); } @@ -54,23 +56,24 @@ static QByteArray code_byte(quint8 b) } return ret; } +} QByteArray Crypt::encrypt(const QByteArray &data, int min_length) const { QByteArray dest; /// nahodne se vybere hodnota, kterou se string zaxoruje a ta se ulozi na zacatek - unsigned val = (unsigned)myrand(); + auto val = (unsigned)myrand(); val += QTime::currentTime().msec(); val %= 256; if(val == 0) val = 1;/// fix case vhen val == 0 and generator C == 0 also - quint8 b = (quint8)val; + auto b = (quint8)val; dest += code_byte(b); /// a tou se to zaxoruje - for(int i=0; i='A' && b<='Z') || (b>='a' && b<='z')) { @@ -106,6 +110,7 @@ static quint8 take_byte(const QByteArray &ba, int &i) } return b; } +} QByteArray Crypt::decodeArray(const QByteArray &ba) const { diff --git a/libqf/libqfcore/src/utils/csvreader.cpp b/libqf/libqfcore/src/utils/csvreader.cpp index 9d3c469aa..3b5637a03 100644 --- a/libqf/libqfcore/src/utils/csvreader.cpp +++ b/libqf/libqfcore/src/utils/csvreader.cpp @@ -11,9 +11,7 @@ CSVReader::CSVReader(QTextStream *ts, char _separator, char _quote) { } -CSVReader::~CSVReader() -{ -} +CSVReader::~CSVReader() = default; QTextStream &CSVReader::textStream() { @@ -70,19 +68,24 @@ QStringList CSVReader::readCSVLineSplitted() return ret; } -static int indexOfOneOf(const QString &str, const QString &chars, char quote = '\0') +namespace { +int indexOfOneOf(const QString &str, const QString &chars, char quote = '\0') { bool in_quotes = false; for(int i=0; i +#include using namespace qf::core::utils; @@ -113,8 +114,7 @@ void TreeItemBase::insertChild(int before_ix, TreeItemBase *it_child) before_ix = 0; } //qfInfo() << "before_ix:" << before_ix << "parent:" << parent() << "child it parent:" << it_child->parent(); - if(before_ix > childrenCount()) - before_ix = childrenCount(); + before_ix = std::min(before_ix, childrenCount()); if(it_child->parent() == this) { /// pokud presouvam v ramci stejneho parentu, vyjmuti it_child zpusobi posunuti indexu /// takze ho vlastne musim vlozit na index o jednicku nizsi @@ -237,14 +237,6 @@ TreeItemPath TreeItemBase::path() const it = par_it; par_it = par_it->parent(); } - //if(ret.isEmpty()) ret = TreeItemPath::rootPath(); - #if 0 //defined QT_DEBUG - { - QStringList sl; - foreach(int i, ret) sl << QString::number(i); - //qfDebug() << "\t return:" << sl.join("-"); - } - #endif return ret; } @@ -255,7 +247,7 @@ TreeItemBase* TreeItemBase::cd(const TreeItemPath &path) const TreeItemBase *ret = nullptr; qfDebug() << "\t path:" << path.toString() << "is valid:" << path.isValid(); if(path.isValid()) { - ret = const_cast(this); + ret = const_cast(this); // NOLINT(cppcoreguidelines-pro-type-const-cast) for(int i=0; ichild(ix); diff --git a/libqf/libqfcore/src/utils/treetable.cpp b/libqf/libqfcore/src/utils/treetable.cpp index 9b1d78fe4..c18b2fdee 100644 --- a/libqf/libqfcore/src/utils/treetable.cpp +++ b/libqf/libqfcore/src/utils/treetable.cpp @@ -6,6 +6,7 @@ #include "../utils/timescope.h" #include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) static const auto SkipEmptyParts = QString::SkipEmptyParts; @@ -318,10 +319,8 @@ void TreeTable::setName(const QString &n) int TreeTable::insertRow(int ix, const QVariantList &vals) { - if(ix < 0) - ix = 0; - if(ix >= rowCount()) - ix = rowCount(); + ix = std::max(ix, 0); + ix = std::min(ix, rowCount()); appendRow(); QVariantList rr = rows(); for (int i = rr.count() - 1; i > ix; --i) { @@ -469,7 +468,7 @@ QVariant TreeTable::value(const QString &_key_name, const QVariant &default_val, } } else { - if(key.compare(key, key_name, Qt::CaseInsensitive) == 0) { + if(QString::compare(key, key_name, Qt::CaseInsensitive) == 0) { ret = it.value(); //qfDebug() << "\t\t equal"; break; diff --git a/libqf/libqfqmlwidgets/src/action.cpp b/libqf/libqfqmlwidgets/src/action.cpp index 83f2e9126..9a40e8b4b 100644 --- a/libqf/libqfqmlwidgets/src/action.cpp +++ b/libqf/libqfqmlwidgets/src/action.cpp @@ -70,7 +70,7 @@ void Action::addActionAfter(QAction *new_act) new_act->setParent(parent_w); Action *next_act = nullptr; Q_FOREACH(auto a, parent_w->actions()) { - Action *aa = qobject_cast(a); + auto *aa = qobject_cast(a); if(!aa) continue; if(aa == this) { @@ -93,7 +93,7 @@ Action *Action::addMenuInto(const QString &id, const QString &text) Action *ret = nullptr; QWidget *parent_w = this->menu(); if(parent_w) { - QMenu *m = new QMenu(parent_w); + auto *m = new QMenu(parent_w); //m->setTitle(text); ret = new Action(parent_w); ret->setMenu(m); @@ -107,9 +107,9 @@ Action *Action::addMenuInto(const QString &id, const QString &text) Action* Action::addMenuAfter(const QString &id, const QString &text) { QWidget *parent_w = parentMenu(); - QMenu *m = new QMenu(parent_w); + auto *m = new QMenu(parent_w); //m->setTitle(text); - Action *new_act = new Action(parent_w); + auto *new_act = new Action(parent_w); new_act->setMenu(m); new_act->setOid(id); new_act->setText(text); @@ -120,8 +120,8 @@ Action* Action::addMenuAfter(const QString &id, const QString &text) Action *Action::addMenuBefore(const QString &id, const QString &text) { QWidget *parent_w = parentMenu(); - QMenu *m = new QMenu(parent_w); - Action *new_act = new Action(parent_w); + auto *m = new QMenu(parent_w); + auto *new_act = new Action(parent_w); new_act->setMenu(m); new_act->setOid(id); new_act->setText(text); @@ -134,7 +134,7 @@ Action* Action::addSeparatorInto(const QString &id) QMenu *w = menu(); QF_ASSERT(w != nullptr, "bad menu", return nullptr); - Action *a = new Action(w); + auto *a = new Action(w); a->setObjectName(id); a->setSeparator(true); w->addAction(a); @@ -146,7 +146,7 @@ Action* Action::addSeparatorBefore(const QString &id) QWidget *w = parentMenu(); QF_ASSERT(w != nullptr, "bad parent", return nullptr); - Action *a = new Action(w); + auto *a = new Action(w); a->setObjectName(id); a->setSeparator(true); w->insertAction(this, a); diff --git a/libqf/libqfqmlwidgets/src/actiongroup.cpp b/libqf/libqfqmlwidgets/src/actiongroup.cpp index 02c87ce1c..1a956fd79 100644 --- a/libqf/libqfqmlwidgets/src/actiongroup.cpp +++ b/libqf/libqfqmlwidgets/src/actiongroup.cpp @@ -1,13 +1,13 @@ #include "actiongroup.h" -namespace qf { -namespace qmlwidgets { + +namespace qf::qmlwidgets { ActionGroup::ActionGroup(QObject *parent) : Super(parent) { } -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets + diff --git a/libqf/libqfqmlwidgets/src/combobox.cpp b/libqf/libqfqmlwidgets/src/combobox.cpp index c2bdec6b0..b6a8dfee4 100644 --- a/libqf/libqfqmlwidgets/src/combobox.cpp +++ b/libqf/libqfqmlwidgets/src/combobox.cpp @@ -24,9 +24,7 @@ ComboBox::ComboBox(QWidget *parent) } ComboBox::~ComboBox() -{ - -} += default; void ComboBox::setCurrentData(const QVariant &val) { @@ -52,7 +50,7 @@ void ComboBox::setItems(const QVariantList &items) { blockSignals(true); clear(); - for(auto v : items) { + for(const auto &v : items) { QVariantList vl = v.toList(); if(vl.isEmpty()) { Super::addItem(v.toString()); @@ -205,43 +203,18 @@ void ForeignKeyComboBox::loadItems(bool force) if(caption_format.contains(referencedCaptionFieldPlaceHolder, Qt::CaseInsensitive)) caption_format.replace(referencedCaptionFieldPlaceHolder, "{{" + capfldname + "}}", Qt::CaseInsensitive); field_captions = qf::core::Utils::findCaptions(caption_format); - /* - QRegExp rx; - rx.setPattern("\\{\\{([A-Za-z][A-Za-z0-9]*(\\.[A-Za-z][A-Za-z0-9]*)*)\\}\\}"); - rx.setPatternSyntax(QRegExp::RegExp); - int ix = 0; - while((ix = rx.indexIn(caption_format, ix)) != -1) { - qfDebug() << "\t caption:" << rx.cap(0) << rx.cap(1); - caption_fields << rx.cap(1); - ix += rx.matchedLength(); - } - */ } qfDebug() << "\t capname:" << capfldname; q.exec(query_str); while(q.next()) { - QString caption = caption_format; - Q_FOREACH(QString fld, field_captions) { + QString format_str = caption_format; + for (const auto &fld : field_captions) { qfDebug() << "\t replacing caption field:" << fld; QVariant fld_val = q.value(fld); - caption = qf::core::Utils::replaceCaptions(caption, fld, fld_val); + format_str = qf::core::Utils::replaceCaptions(format_str, fld, fld_val); } QVariant id = q.value(fldname); - /* - QVariant decor; - if(!decorationField().isEmpty()) { - decor = q.value(decorationField()); - QString decor_str = decor.toString(); - if(decor_str.startsWith("#")) { - QColor c; - c.setNamedColor(decor_str); - decor = c; - } - } - */ - addItem(caption, id); - //cached_items << CachedItem(caption, id, decor); - //qfTrash() << "\t adding item:" << caption << id.toString() << decor.toString(); + addItem(format_str, id); } } } diff --git a/libqf/libqfqmlwidgets/src/datacontroller.cpp b/libqf/libqfqmlwidgets/src/datacontroller.cpp index 1a594d231..2dc73625b 100644 --- a/libqf/libqfqmlwidgets/src/datacontroller.cpp +++ b/libqf/libqfqmlwidgets/src/datacontroller.cpp @@ -13,9 +13,7 @@ DataController::DataController(QObject *parent) } DataController::~DataController() -{ - -} += default; qf::core::model::DataDocument *DataController::document(bool throw_exc) const { @@ -40,7 +38,7 @@ QList DataController::dataWidgets() if(m_dataWidgets.isEmpty()) { const QList lst = m_dataWidgetsParent->findChildren(); for(auto w : lst) { - IDataWidget *dw = dynamic_cast(w); + auto *dw = dynamic_cast(w); if(dw) m_dataWidgets << dw; } diff --git a/libqf/libqfqmlwidgets/src/datetimeedit.cpp b/libqf/libqfqmlwidgets/src/datetimeedit.cpp index 17090cb31..9359921d1 100644 --- a/libqf/libqfqmlwidgets/src/datetimeedit.cpp +++ b/libqf/libqfqmlwidgets/src/datetimeedit.cpp @@ -2,8 +2,8 @@ #include -namespace qf { -namespace qmlwidgets { + +namespace qf::qmlwidgets { DateTimeEdit::DateTimeEdit(QWidget *parent) : Super(parent) @@ -54,5 +54,5 @@ void DateTimeEdit::onDateTimeChanged(const QDateTime &new_datetime) emit dataValueChanged(new_datetime); } -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets + diff --git a/libqf/libqfqmlwidgets/src/dialogs/dialog.cpp b/libqf/libqfqmlwidgets/src/dialogs/dialog.cpp index 02a873adb..fc943f3c4 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/dialog.cpp +++ b/libqf/libqfqmlwidgets/src/dialogs/dialog.cpp @@ -48,7 +48,7 @@ void Dialog::setCentralWidget(QWidget *central_widget) sp.setVerticalPolicy(QSizePolicy::MinimumExpanding); m_centralWidget->setSizePolicy(sp); } - qf::qmlwidgets::framework::DialogWidget *dialog_widget = qobject_cast(central_widget); + auto *dialog_widget = qobject_cast(central_widget); if(dialog_widget) { connect(dialog_widget, &qf::qmlwidgets::framework::DialogWidget::closeDialogRequest, this, &Dialog::done); QMetaObject::invokeMethod(this, "settleDownDialogWidget", Qt::QueuedConnection); @@ -62,7 +62,7 @@ void Dialog::setCentralWidget(QWidget *central_widget) void Dialog::settleDownDialogWidget() { - qf::qmlwidgets::framework::DialogWidget *dialog_widget = qobject_cast(m_centralWidget); + auto *dialog_widget = qobject_cast(m_centralWidget); if(dialog_widget) { QVariant dlg = QVariant::fromValue(this); bool ok = QMetaObject::invokeMethod(dialog_widget, "settleDownInDialog_qml", Q_ARG(QVariant, dlg)); @@ -201,7 +201,7 @@ void Dialog::updateLayout() ly_root->addWidget(tb); } else if(!m_toolBars.isEmpty()) { - QHBoxLayout *ly1 = new QHBoxLayout(nullptr); + auto *ly1 = new QHBoxLayout(nullptr); Q_FOREACH(auto tb_name, m_toolBars.keys()) { ToolBar *tb = m_toolBars.value(tb_name); tb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); @@ -227,7 +227,7 @@ void Dialog::updateLayout() qf::qmlwidgets::framework::DialogWidget *Dialog::dialogWidget() { - qf::qmlwidgets::framework::DialogWidget *ret = qobject_cast(m_centralWidget); + auto *ret = qobject_cast(m_centralWidget); return ret; } @@ -250,8 +250,8 @@ void Dialog::showEvent(QShowEvent *ev) void Dialog::updateCaptionFrame() { qfLogFuncFrame() << m_centralWidget; - qf::qmlwidgets::framework::DialogWidget *dialog_widget = qobject_cast(m_centralWidget); - qf::qmlwidgets::framework::DataDialogWidget *data_dialog_widget = qobject_cast(m_centralWidget); + auto *dialog_widget = qobject_cast(m_centralWidget); + auto *data_dialog_widget = qobject_cast(m_centralWidget); if(dialog_widget) { if(!m_captionFrame) { m_captionFrame = new qf::qmlwidgets::dialogs::internal::CaptionFrame(this); @@ -283,7 +283,7 @@ void Dialog::setButtonBox(DialogButtonBox *dbb) qfDebug() << "\t adding:" << m_dialogButtonBox << "to layout:" << layout(); /// widget cannot be simply reparented /// NULL parent should be set first - m_dialogButtonBox->setParent(0); + m_dialogButtonBox->setParent(nullptr); m_dialogButtonBox->setParent(this); updateLayout(); connect(m_dialogButtonBox, &DialogButtonBox::accepted, this, &Dialog::accept); diff --git a/libqf/libqfqmlwidgets/src/dialogs/getiteminputdialog.cpp b/libqf/libqfqmlwidgets/src/dialogs/getiteminputdialog.cpp index d5b7f926d..4593fa982 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/getiteminputdialog.cpp +++ b/libqf/libqfqmlwidgets/src/dialogs/getiteminputdialog.cpp @@ -15,7 +15,7 @@ GetItemInputDialog::GetItemInputDialog(QWidget *parent) : m_label->setBuddy(m_comboBox); m_label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); - QDialogButtonBox *button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + auto *button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); QObject::connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); QObject::connect(button_box, SIGNAL(rejected()), this, SLOT(reject())); @@ -28,8 +28,7 @@ GetItemInputDialog::GetItemInputDialog(QWidget *parent) : } GetItemInputDialog::~GetItemInputDialog() -{ -} += default; void GetItemInputDialog::setLabelText(const QString &text) { diff --git a/libqf/libqfqmlwidgets/src/dialogs/internal/captionframe.cpp b/libqf/libqfqmlwidgets/src/dialogs/internal/captionframe.cpp index a000fff9b..78cace2d1 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/internal/captionframe.cpp +++ b/libqf/libqfqmlwidgets/src/dialogs/internal/captionframe.cpp @@ -105,7 +105,7 @@ void CaptionFrame::update() qfLogFuncFrame() << "text:" << text(); QString label_text = text(); if(m_recordEditMode >= 0) { - qf::core::model::DataDocument::RecordEditMode mode = qf::core::model::DataDocument::RecordEditMode(m_recordEditMode); + auto mode = qf::core::model::DataDocument::RecordEditMode(m_recordEditMode); if(mode == qf::core::model::DataDocument::ModeDelete) { label_text = tr("Delete ") + label_text; setAlert(true); diff --git a/libqf/libqfqmlwidgets/src/dialogs/messagebox.cpp b/libqf/libqfqmlwidgets/src/dialogs/messagebox.cpp index 87756297a..b8aefeb18 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/messagebox.cpp +++ b/libqf/libqfqmlwidgets/src/dialogs/messagebox.cpp @@ -8,9 +8,9 @@ #include #include -namespace qf { -namespace qmlwidgets { -namespace dialogs { + + +namespace qf::qmlwidgets::dialogs { MessageBox::MessageBox(QWidget *parent) : Super(parent) @@ -90,7 +90,7 @@ void MessageBox::saveShowAgainDisabled(bool b) settings.setValue(id, b); } -QString MessageBox::showAgainPersistentSettingsId() +QString MessageBox::showAgainPersistentSettingsId() const { QString key = doNotShowAgainPersistentKey(); if(key.isEmpty()) { @@ -99,4 +99,4 @@ QString MessageBox::showAgainPersistentSettingsId() return framework::IPersistentSettings::defaultPersistentSettingsPathPrefix() + QStringLiteral("/doNotShowMessageAgain/") + key; } -}}} +} diff --git a/libqf/libqfqmlwidgets/src/dialogs/messagebox.h b/libqf/libqfqmlwidgets/src/dialogs/messagebox.h index 0d46c7a79..492d91ff3 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/messagebox.h +++ b/libqf/libqfqmlwidgets/src/dialogs/messagebox.h @@ -37,7 +37,7 @@ class QFQMLWIDGETS_DECL_EXPORT MessageBox : public QMessageBox private: bool loadShowAgainDisabled(); void saveShowAgainDisabled(bool b); - QString showAgainPersistentSettingsId(); + QString showAgainPersistentSettingsId() const; }; }}} diff --git a/libqf/libqfqmlwidgets/src/dialogs/previewdialog.cpp b/libqf/libqfqmlwidgets/src/dialogs/previewdialog.cpp index 5aafaf0d0..84c003e60 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/previewdialog.cpp +++ b/libqf/libqfqmlwidgets/src/dialogs/previewdialog.cpp @@ -18,7 +18,7 @@ using namespace qf::qmlwidgets::dialogs; PreviewDialog::PreviewDialog(QWidget *parent) : Super(parent) { - QWidget *w = new QWidget(); + auto *w = new QWidget(); setCentralWidget(w); ui = new Ui::PreviewDialog; ui->setupUi(w); diff --git a/libqf/libqfqmlwidgets/src/dialogs/qmldialog.cpp b/libqf/libqfqmlwidgets/src/dialogs/qmldialog.cpp index 2f5c13e7f..608cd7306 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/qmldialog.cpp +++ b/libqf/libqfqmlwidgets/src/dialogs/qmldialog.cpp @@ -21,8 +21,7 @@ QmlDialog::QmlDialog(QWidget *parent) : } QmlDialog::~QmlDialog() -{ -} += default; int QmlDialog::standardButtons() { diff --git a/libqf/libqfqmlwidgets/src/dialogs/qmldialog.h b/libqf/libqfqmlwidgets/src/dialogs/qmldialog.h index b02aa7ba5..57c71e433 100644 --- a/libqf/libqfqmlwidgets/src/dialogs/qmldialog.h +++ b/libqf/libqfqmlwidgets/src/dialogs/qmldialog.h @@ -20,8 +20,8 @@ class QFQMLWIDGETS_DECL_EXPORT QmlDialog : public Dialog, public QQmlParserStatu { Q_OBJECT Q_INTERFACES(QQmlParserStatus) - Q_ENUMS(DoneResult) - Q_ENUMS(QDialogButtonBox::StandardButton) + Q_ENUM(DoneResult) + Q_ENUM(QDialogButtonBox::StandardButton) Q_CLASSINFO("DefaultProperty", "widgets") Q_PROPERTY(QQmlListProperty widgets READ widgets) Q_PROPERTY(qf::qmlwidgets::framework::DialogWidget* dialogWidget READ dialogWidget WRITE setDialogWidget NOTIFY dialogWidgetChanged) diff --git a/libqf/libqfqmlwidgets/src/exportcsvtableviewwidget.cpp b/libqf/libqfqmlwidgets/src/exportcsvtableviewwidget.cpp index efc903590..202b5b294 100644 --- a/libqf/libqfqmlwidgets/src/exportcsvtableviewwidget.cpp +++ b/libqf/libqfqmlwidgets/src/exportcsvtableviewwidget.cpp @@ -3,8 +3,8 @@ #include -namespace qf { -namespace qmlwidgets { + +namespace qf::qmlwidgets { ExportCsvTableViewWidget::ExportCsvTableViewWidget(QTableView *table_view, QWidget *parent) : Super(table_view, parent) @@ -54,6 +54,6 @@ void ExportCsvTableViewWidget::setExportOptions(const QVariant& opts) const ui->lstCodec->setCurrentIndex(ui->lstCodec->findText(text_opts.codecName())); } -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets + diff --git a/libqf/libqfqmlwidgets/src/exporttableviewwidget.cpp b/libqf/libqfqmlwidgets/src/exporttableviewwidget.cpp index 85039cf5e..c0cb3fd73 100644 --- a/libqf/libqfqmlwidgets/src/exporttableviewwidget.cpp +++ b/libqf/libqfqmlwidgets/src/exporttableviewwidget.cpp @@ -6,8 +6,8 @@ #include -namespace qf { -namespace qmlwidgets { + +namespace qf::qmlwidgets { ExportTableViewWidget::ExportTableViewWidget(QTableView *table_view, QWidget *parent) : Super(parent) @@ -98,5 +98,5 @@ void ExportTableViewWidget::setExportOptions(const QVariant &opts) const ui->edToLine->setValue(text_opts.toLine()); } -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets + diff --git a/libqf/libqfqmlwidgets/src/frame.cpp b/libqf/libqfqmlwidgets/src/frame.cpp index eca8cb004..8822123cf 100644 --- a/libqf/libqfqmlwidgets/src/frame.cpp +++ b/libqf/libqfqmlwidgets/src/frame.cpp @@ -39,9 +39,9 @@ void Frame::setLayoutType(Frame::LayoutType ly_type) if(ly_type != layoutType()) { //QList layout_items; QLayout *old_ly = layout(); - if(old_ly) { + delete old_ly; - } + m_layoutType = ly_type; Q_FOREACH(auto w, m_childWidgets) { addToLayout(w); @@ -65,7 +65,7 @@ void Frame::setVisible(bool b) QQmlListProperty Frame::widgets() { - return QQmlListProperty(this, 0, + return QQmlListProperty(this, nullptr, Frame::addWidgetFunction, Frame::countWidgetsFunction, Frame::widgetAtFunction, @@ -76,27 +76,27 @@ QQmlListProperty Frame::widgets() void Frame::addWidgetFunction(QQmlListProperty *list_property, QWidget *value) { if (value) { - Frame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); that->add(value); } } QWidget * Frame::widgetAtFunction(QQmlListProperty *list_property, WidgetIndexType index) { - Frame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); return that->at(index); } void Frame::removeAllWidgetsFunction(QQmlListProperty *list_property) { - Frame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); that->removeAll(); } Frame::WidgetIndexType Frame::countWidgetsFunction(QQmlListProperty *list_property) { - Frame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); return that->count(); } @@ -106,7 +106,7 @@ void Frame::add(QWidget *widget) //qDebug() << "adding widget" << widget << widget->parent(); /// widget cannot be simply reparented /// NULL parent should be set first - widget->setParent(0); + widget->setParent(nullptr); widget->setParent(this); m_childWidgets << widget; //Super::layout()->addWidget(widget); @@ -146,7 +146,7 @@ void Frame::addToLayout(QWidget *widget) qfDebug() << "\tnew layout:" << layout() << this; } qfDebug() << "\tadding:" << widget << "to layout:" << layout() << this; - LayoutPropertiesAttached *layout_props_attached = qobject_cast(qmlAttachedPropertiesObject(widget, false)); + auto *layout_props_attached = qobject_cast(qmlAttachedPropertiesObject(widget, false)); if(layout_props_attached) { LayoutTypeProperties::SizePolicy sph = layout_props_attached->horizontalSizePolicy(); LayoutTypeProperties::SizePolicy spv = layout_props_attached->verticalSizePolicy(); @@ -154,7 +154,7 @@ void Frame::addToLayout(QWidget *widget) widget->setSizePolicy((QSizePolicy::Policy)sph, (QSizePolicy::Policy)spv); } { - QGridLayout *ly = qobject_cast(layout()); + auto *ly = qobject_cast(layout()); if(ly) { LayoutTypeProperties *props = layoutTypeProperties(); LayoutTypeProperties::Flow flow = LayoutTypeProperties::LeftToRight; @@ -193,7 +193,7 @@ void Frame::addToLayout(QWidget *widget) } } { - QFormLayout *ly = qobject_cast(layout()); + auto *ly = qobject_cast(layout()); if(ly) { QString buddy_text; int column_span = 1; @@ -217,7 +217,7 @@ void Frame::addToLayout(QWidget *widget) } } { - QBoxLayout *ly = qobject_cast(layout()); + auto *ly = qobject_cast(layout()); if(ly) { ly->addWidget(widget); return; diff --git a/libqf/libqfqmlwidgets/src/frame.h b/libqf/libqfqmlwidgets/src/frame.h index 5cee3939d..73ad1ec9c 100644 --- a/libqf/libqfqmlwidgets/src/frame.h +++ b/libqf/libqfqmlwidgets/src/frame.h @@ -20,7 +20,6 @@ class QFQMLWIDGETS_DECL_EXPORT Frame : public QFrame Q_PROPERTY(QQmlListProperty widgets READ widgets) Q_CLASSINFO("DefaultProperty", "widgets") Q_PROPERTY(LayoutType layoutType READ layoutType WRITE setLayoutType NOTIFY layoutTypeChanged) - Q_ENUMS(LayoutType) Q_PROPERTY(qf::qmlwidgets::LayoutTypeProperties* layoutProperties READ layoutTypeProperties WRITE setLayoutTypeProperties) /// attachedObjects is a workaround for https://github.com/fvacek/quickbox/issues/2 Q_PROPERTY(QQmlListProperty attachedObjects READ attachedObjects) @@ -29,6 +28,7 @@ class QFQMLWIDGETS_DECL_EXPORT Frame : public QFrame typedef QFrame Super; public: enum LayoutType {LayoutInvalid, LayoutHorizontal, LayoutVertical, LayoutGrid, LayoutForm}; + Q_ENUM(LayoutType) public: explicit Frame(QWidget *parent = nullptr); ~Frame() Q_DECL_OVERRIDE; diff --git a/libqf/libqfqmlwidgets/src/framework/application.cpp b/libqf/libqfqmlwidgets/src/framework/application.cpp index feb3929e9..fa7520c9a 100644 --- a/libqf/libqfqmlwidgets/src/framework/application.cpp +++ b/libqf/libqfqmlwidgets/src/framework/application.cpp @@ -18,12 +18,11 @@ Application::Application(int &argc, char **argv) : } Application::~Application() -{ -} += default; Application *Application::instance(bool must_exist) { - Application *ret = qobject_cast(Super::instance()); + auto *ret = qobject_cast(Super::instance()); if(!ret && must_exist) { qfFatal("qf::qmlwidgets::framework::Application instance MUST exist."); } diff --git a/libqf/libqfqmlwidgets/src/framework/centralwidget.h b/libqf/libqfqmlwidgets/src/framework/centralwidget.h index 3f9282976..feb42abb7 100644 --- a/libqf/libqfqmlwidgets/src/framework/centralwidget.h +++ b/libqf/libqfqmlwidgets/src/framework/centralwidget.h @@ -27,7 +27,7 @@ class QFQMLWIDGETS_DECL_EXPORT CentralWidget : public QWidget } Q_INVOKABLE virtual int featureToIndex(const QString &feature_id) = 0; - Q_SIGNAL void partActivated(const QString &feature_id, bool is_active); + // Q_SIGNAL void partActivatedS(const QString &feature_id, bool is_active); Q_SIGNAL void partActivated(int part_index, bool is_active); public: virtual void addPartWidget(PartWidget *widget) = 0; diff --git a/libqf/libqfqmlwidgets/src/framework/datadialogwidget.cpp b/libqf/libqfqmlwidgets/src/framework/datadialogwidget.cpp index bc0868f6c..a7206c05d 100644 --- a/libqf/libqfqmlwidgets/src/framework/datadialogwidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/datadialogwidget.cpp @@ -10,13 +10,9 @@ using namespace qf::qmlwidgets::framework; DataDialogWidget::DataDialogWidget(QWidget *parent) : Super(parent) { - } -DataDialogWidget::~DataDialogWidget() -{ - -} +DataDialogWidget::~DataDialogWidget() = default; qf::qmlwidgets::DataController *DataDialogWidget::dataController() { diff --git a/libqf/libqfqmlwidgets/src/framework/dialogwidget.cpp b/libqf/libqfqmlwidgets/src/framework/dialogwidget.cpp index b9ae32819..ed492d181 100644 --- a/libqf/libqfqmlwidgets/src/framework/dialogwidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/dialogwidget.cpp @@ -15,8 +15,7 @@ DialogWidget::DialogWidget(QWidget *parent) : } DialogWidget::~DialogWidget() -{ -} += default; bool DialogWidget::acceptDialogDone(int result) { @@ -32,8 +31,8 @@ QVariant DialogWidget::acceptDialogDone_qml(const QVariant &result) */ void DialogWidget::settleDownInDialog_qml(const QVariant &dlg) { - QObject *o = dlg.value(); - qf::qmlwidgets::dialogs::Dialog *pdlg = qobject_cast(o); + auto *o = dlg.value(); + auto *pdlg = qobject_cast(o); QF_ASSERT(pdlg != nullptr, "Invalid dialog", return); settleDownInDialog(pdlg); } diff --git a/libqf/libqfqmlwidgets/src/framework/dockablewidget.cpp b/libqf/libqfqmlwidgets/src/framework/dockablewidget.cpp index 9aa72ab68..d44ec46c5 100644 --- a/libqf/libqfqmlwidgets/src/framework/dockablewidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/dockablewidget.cpp @@ -2,9 +2,9 @@ #include -namespace qf { -namespace qmlwidgets { -namespace framework { + + +namespace qf::qmlwidgets::framework { DockableWidget::DockableWidget(QWidget *parent) : Super(parent) @@ -12,7 +12,7 @@ DockableWidget::DockableWidget(QWidget *parent) } -} // namespace framework -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets::framework + + diff --git a/libqf/libqfqmlwidgets/src/framework/dockwidget.cpp b/libqf/libqfqmlwidgets/src/framework/dockwidget.cpp index 0bd6bbfca..19e9222dd 100644 --- a/libqf/libqfqmlwidgets/src/framework/dockwidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/dockwidget.cpp @@ -50,7 +50,7 @@ void DockWidget::showEvent(QShowEvent *ev) */ void DockWidget::setQmlWidget(QWidget *w) { - w->setParent(0); + w->setParent(nullptr); w->show(); Super::setWidget(w); } diff --git a/libqf/libqfqmlwidgets/src/framework/ipersistentsettings.cpp b/libqf/libqfqmlwidgets/src/framework/ipersistentsettings.cpp index 58905f389..29333400a 100644 --- a/libqf/libqfqmlwidgets/src/framework/ipersistentsettings.cpp +++ b/libqf/libqfqmlwidgets/src/framework/ipersistentsettings.cpp @@ -90,7 +90,7 @@ QString IPersistentSettings::effectivePersistentSettingsPathPrefix() if(!pp.isEmpty()) return pp; for(QObject *obj=m_controlledObject->parent(); obj!=nullptr; obj=obj->parent()) { - IPersistentSettings *ps = dynamic_cast(obj); + auto *ps = dynamic_cast(obj); if(ps) return ps->effectivePersistentSettingsPathPrefix(); } @@ -104,7 +104,7 @@ QString IPersistentSettings::rawPersistentSettingsPath() QStringList raw_path; if(!persistent_id.isEmpty()) { for(QObject *obj=m_controlledObject->parent(); obj!=nullptr; obj=obj->parent()) { - IPersistentSettings *ps = dynamic_cast(obj); + auto *ps = dynamic_cast(obj); if(ps) { QString pp = ps->rawPersistentSettingsPath(); if(!pp.isEmpty()) @@ -113,13 +113,12 @@ QString IPersistentSettings::rawPersistentSettingsPath() //qfWarning() << "\tcorrect value should be:" << parent_id; break; } - else { - QVariant vid = obj->property("persistentSettingsId"); + QVariant vid = obj->property("persistentSettingsId"); QString parent_id = vid.toString(); if(!parent_id.isEmpty()) { raw_path.insert(0, parent_id); } - } + // reading property using QQmlProperty is crashing my app Qt 5.3.1 commit a83826dad0f62d7a96f5a6093240e4c8f7f2e06e //QQmlProperty p(obj, "persistentSettingsId"); //QVariant v2 = p.read(); diff --git a/libqf/libqfqmlwidgets/src/framework/logwidget.cpp b/libqf/libqfqmlwidgets/src/framework/logwidget.cpp index bea4c92ad..6d07036c4 100644 --- a/libqf/libqfqmlwidgets/src/framework/logwidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/logwidget.cpp @@ -20,9 +20,9 @@ namespace qfm = qf::core::model; -namespace qf { -namespace qmlwidgets { -namespace framework { + + +namespace qf::qmlwidgets::framework { LogWidgetTableView::LogWidgetTableView(QWidget *parent) : Super(parent) @@ -98,7 +98,7 @@ LogWidget::LogWidget(QWidget *parent) ui->btCopyToClipboard->setDefaultAction(ui->tableView->copySelectionToClipboardAction()); { - QAction *a = new QAction(tr("Maximal log length"), this); + auto *a = new QAction(tr("Maximal log length"), this); connect(a, &QAction::triggered, this, [this]() { qf::core::model::LogTableModel *m = this->logTableModel(); int max_rows = m->maximumRowCount(); @@ -110,7 +110,7 @@ LogWidget::LogWidget(QWidget *parent) tableMenuButton()->addAction(a); } { - QAction *a = new QAction(this); + auto *a = new QAction(this); a->setSeparator(true); tableMenuButton()->addAction(a); } @@ -227,10 +227,9 @@ bool LogWidget::isAutoScroll() //fprintf(stderr, "BOTTOM scrollbar min: %d max: %d value: %d\n", sb->minimum(), sb->maximum(), sb->value()); return (sb->value() == sb->maximum()); } - else { - //fprintf(stderr, "TOP scrollbar min: %d max: %d value: %d\n", sb->minimum(), sb->maximum(), sb->value()); + //fprintf(stderr, "TOP scrollbar min: %d max: %d value: %d\n", sb->minimum(), sb->maximum(), sb->value()); return (sb->value() == sb->minimum()); - } + } return false; } @@ -255,18 +254,18 @@ void LogWidget::clearCategoryActions() void LogWidget::addCategoryActions(const QString &caption, const QString &id, NecroLog::Level level) { QString menu_caption = "[%1] " + caption; - QMenu *m = new QMenu(this); + auto *m = new QMenu(this); m_loggingCategoriesMenus << m; - QAction *a = new QAction(caption, m); + auto *a = new QAction(caption, m); a->setData(id); a->setMenu(m); tableMenuButton()->addAction(a); - QActionGroup *ag_loglevel = new QActionGroup(a); + auto *ag_loglevel = new QActionGroup(a); for (int i = static_cast(NecroLog::Level::Invalid); i <= static_cast(NecroLog::Level::Debug); i++) { if(i == static_cast(NecroLog::Level::Fatal)) continue; QString cap = NecroLog::levelToString(static_cast(i)); - QAction *a2 = new QAction(cap, a); + auto *a2 = new QAction(cap, a); ag_loglevel->addAction(a2); m->addAction(a2); a2->setCheckable(true); @@ -309,7 +308,7 @@ QMap LogWidget::selectedLogCategories() const QMap categories; for(QAction *a : m_logLevelActions) { if(a->isChecked()) { - QAction *pa = qobject_cast(a->parent()); + auto *pa = qobject_cast(a->parent()); QF_ASSERT(pa != nullptr, "Bad parent", continue); NecroLog::Level level = static_cast(a->data().toInt()); QChar level_c = (level == NecroLog::Level::Invalid)? ' ': NecroLog::levelToString(level)[0]; @@ -366,6 +365,6 @@ void LogWidget::checkScrollToLastEntry() } } -} // namespace framework -} // namespace qmlwiggets -} // namespace qf +} // namespace qf::qmlwidgets::framework +// namespace qmlwiggets + diff --git a/libqf/libqfqmlwidgets/src/framework/mainwindow.cpp b/libqf/libqfqmlwidgets/src/framework/mainwindow.cpp index 5acdbbeba..7f4c913a0 100644 --- a/libqf/libqfqmlwidgets/src/framework/mainwindow.cpp +++ b/libqf/libqfqmlwidgets/src/framework/mainwindow.cpp @@ -198,7 +198,7 @@ void MainWindow::setPersistentSettingDomains(const QString &organization_domain, qf::qmlwidgets::MenuBar *MainWindow::menuBar() { QMenuBar *mb = Super::menuBar(); - MenuBar *menu_bar = qobject_cast(mb); + auto *menu_bar = qobject_cast(mb); if(!menu_bar) { QF_SAFE_DELETE(mb); menu_bar = new MenuBar(this); @@ -221,7 +221,7 @@ qf::qmlwidgets::ToolBar *MainWindow::toolBar(const QString &name, bool create_if qf::qmlwidgets::StatusBar *MainWindow::statusBar() { QStatusBar *sb = Super::statusBar(); - StatusBar *status_bar = qobject_cast(sb); + auto *status_bar = qobject_cast(sb); if(!status_bar) { QF_SAFE_DELETE(sb) status_bar = new StatusBar(this); @@ -242,7 +242,7 @@ void MainWindow::setStatusBar(qf::qmlwidgets::StatusBar *sbar) CentralWidget *MainWindow::centralWidget() { QWidget *cw = Super::centralWidget(); - CentralWidget *central_widget = qobject_cast(cw); + auto *central_widget = qobject_cast(cw); if(!central_widget) { QF_SAFE_DELETE(cw) central_widget = new StackedCentralWidget(this); @@ -256,16 +256,17 @@ CentralWidget *MainWindow::centralWidget() void MainWindow::setCentralWidget(CentralWidget *widget) { qfLogFuncFrame() << widget; - widget->setParent(0); + widget->setParent(nullptr); Super::setCentralWidget(widget); } void MainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget) { - qf::qmlwidgets::framework::IPersistentSettings* ps = dynamic_cast(dockwidget); - if(ps) + Q_ASSERT(dockwidget); + if(auto* ps = dynamic_cast(dockwidget)) { ps->loadPersistentSettingsRecursively(); - dockwidget->setParent(0); + } + dockwidget->setParent(nullptr); Super::addDockWidget(area, dockwidget); } @@ -307,7 +308,7 @@ Plugin *MainWindow::pluginForObject(QObject *qml_object) qfLogFuncFrame(); Plugin *ret = nullptr; for(QObject *o = qml_object; o!=nullptr; o=o->parent()) { - PartWidget *pw = qobject_cast(o); + auto *pw = qobject_cast(o); qfDebug() << o << "->" << pw; if(pw) { QString id = pw->featureId(); @@ -324,7 +325,7 @@ qf::qmlwidgets::dialogs::QmlDialog *MainWindow::createQmlDialog(QWidget *parent) { if(parent == nullptr) parent = this; - qf::qmlwidgets::dialogs::QmlDialog *ret = new qf::qmlwidgets::dialogs::QmlDialog(parent); + auto *ret = new qf::qmlwidgets::dialogs::QmlDialog(parent); //Application *app = Application::instance(); //QQmlEngine *qe = app->qmlEngine(); //qe->setObjectOwnership(ret, QQmlEngine::JavaScriptOwnership); diff --git a/libqf/libqfqmlwidgets/src/framework/partswitch.cpp b/libqf/libqfqmlwidgets/src/framework/partswitch.cpp index 9882f41cf..9b8f39f36 100644 --- a/libqf/libqfqmlwidgets/src/framework/partswitch.cpp +++ b/libqf/libqfqmlwidgets/src/framework/partswitch.cpp @@ -20,13 +20,9 @@ PartSwitchToolButton::PartSwitchToolButton(QWidget *parent) setAutoRaise(true); setCheckable(true); setAutoExclusive(false); - //setIconSize(QSize(64, 64)); - //setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); connect(this, &Super::clicked, [this]() { - //qfInfo() << "clicked" << this->m_partIndex; - //this->setIconSize(this->size()); - emit clicked(this->m_partIndex); + emit partClicked(this->m_partIndex); }); } @@ -35,20 +31,20 @@ PartSwitch::PartSwitch(StackedCentralWidget *central_widget, QWidget *parent) : { setObjectName("partSwitch"); setWindowTitle(tr("Part switch")); - //setStyleSheet("background-color: rgb(118, 118, 118);"); } qf::qmlwidgets::framework::PartSwitch::~PartSwitch() -{ -} += default; void PartSwitch::addPartWidget(PartWidget *widget) { qfLogFuncFrame() << widget << widget->featureId() << widget->title(); - PartSwitchToolButton *bt = new PartSwitchToolButton(); + auto *bt = new PartSwitchToolButton(); bt->setCheckable(true); - connect(bt, SIGNAL(clicked(int)), this, SLOT(setCurrentPartIndex(int))); + connect(bt, &PartSwitchToolButton::partClicked, this, [this](int ix) { + setCurrentPartIndex(ix); + }); bt->setText(widget->title()); bt->setPartIndex(buttonCount()); addWidget(bt); diff --git a/libqf/libqfqmlwidgets/src/framework/partswitch.h b/libqf/libqfqmlwidgets/src/framework/partswitch.h index 21c51b396..7fd888663 100644 --- a/libqf/libqfqmlwidgets/src/framework/partswitch.h +++ b/libqf/libqfqmlwidgets/src/framework/partswitch.h @@ -17,7 +17,6 @@ class StackedCentralWidget; class PartSwitchToolButton : public QToolButton { Q_OBJECT - //friend class PartSwitch; private: typedef QToolButton Super; public: @@ -26,7 +25,7 @@ class PartSwitchToolButton : public QToolButton int partIndex() {return m_partIndex;} void setPartIndex(int ix) {m_partIndex = ix;} - Q_SIGNAL void clicked(int part_index); + Q_SIGNAL void partClicked(int part_index); private: int m_partIndex; }; @@ -43,8 +42,8 @@ class PartSwitch : public QToolBar void addPartWidget(PartWidget *widget); Q_SIGNAL void partActivated(int ix, bool is_active); + void setCurrentPartIndex(int ix, bool is_active = true); private: - Q_SLOT void setCurrentPartIndex(int ix, bool is_active = true); int buttonCount(); PartSwitchToolButton* buttonAt(int part_index); private: diff --git a/libqf/libqfqmlwidgets/src/framework/partwidget.cpp b/libqf/libqfqmlwidgets/src/framework/partwidget.cpp index 6ef80586c..0965a90e1 100644 --- a/libqf/libqfqmlwidgets/src/framework/partwidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/partwidget.cpp @@ -82,7 +82,7 @@ qf::qmlwidgets::MenuBar *PartWidget::menuBar() { if(!m_menuBar) { m_menuBar = new MenuBar(); - QBoxLayout *ly = qobject_cast(layout()); + auto *ly = qobject_cast(layout()); QF_ASSERT_EX(ly != nullptr, "wrong layout"); ly->insertWidget(1, m_menuBar); } @@ -99,8 +99,8 @@ qf::qmlwidgets::ToolBar *PartWidget::toolBar(const QString &name, bool create_if return nullptr; } if(m_toolBarsLayout == nullptr) { - QFrame *frm = new QFrame(this); - QBoxLayout *ly = qobject_cast(layout()); + auto *frm = new QFrame(this); + auto *ly = qobject_cast(layout()); QF_ASSERT_EX(ly != nullptr, "wrong layout"); int ix = (m_menuBar)? 2: 1; ly->insertWidget(ix, frm); diff --git a/libqf/libqfqmlwidgets/src/framework/plugin.cpp b/libqf/libqfqmlwidgets/src/framework/plugin.cpp index 06847a687..7a4c8b901 100644 --- a/libqf/libqfqmlwidgets/src/framework/plugin.cpp +++ b/libqf/libqfqmlwidgets/src/framework/plugin.cpp @@ -9,6 +9,7 @@ #include #include #include +#include using namespace qf::qmlwidgets::framework; diff --git a/libqf/libqfqmlwidgets/src/framework/stackedcentralwidget.cpp b/libqf/libqfqmlwidgets/src/framework/stackedcentralwidget.cpp index 43b1eb535..ed6beffef 100644 --- a/libqf/libqfqmlwidgets/src/framework/stackedcentralwidget.cpp +++ b/libqf/libqfqmlwidgets/src/framework/stackedcentralwidget.cpp @@ -10,9 +10,9 @@ #include #include -namespace qf { -namespace qmlwidgets { -namespace framework { + + +namespace qf::qmlwidgets::framework { StackedCentralWidget::StackedCentralWidget(MainWindow *parent) : Super(parent) @@ -26,13 +26,12 @@ StackedCentralWidget::StackedCentralWidget(MainWindow *parent) : setLayout(ly); m_partSwitch = new PartSwitch(this); - connect(this, SIGNAL(partActivated(int, bool)), m_partSwitch, SLOT(setCurrentPartIndex(int, bool))); + connect(this, &StackedCentralWidget::partActivated, m_partSwitch, &PartSwitch::setCurrentPartIndex); MainWindow::frameWork()->addToolBar(Qt::LeftToolBarArea, m_partSwitch); } StackedCentralWidget::~StackedCentralWidget() -{ -} += default; void StackedCentralWidget::addPartWidget(PartWidget *widget) { @@ -61,7 +60,7 @@ bool StackedCentralWidget::setActivePart(int part_index, bool set_active) pw->setActive(set_active); if(set_active) m_centralWidget->setCurrentIndex(part_index); - emit partActivated(pw->featureId(), set_active); + // emit partActivatedS(pw->featureId(), set_active); emit partActivated(part_index, set_active); } } @@ -81,11 +80,11 @@ int StackedCentralWidget::featureToIndex(const QString &feature_id) PartWidget *StackedCentralWidget::partWidget(int part_index) { - PartWidget *pw = qobject_cast(m_centralWidget->widget(part_index)); + auto *pw = qobject_cast(m_centralWidget->widget(part_index)); if(pw == nullptr) { //qfWarning() << "invalid part index:" << part_index << "of count:" << m_centralWidget->count(); } return pw; } -}}} +} diff --git a/libqf/libqfqmlwidgets/src/headerview.cpp b/libqf/libqfqmlwidgets/src/headerview.cpp index acc46d418..134a0d661 100644 --- a/libqf/libqfqmlwidgets/src/headerview.cpp +++ b/libqf/libqfqmlwidgets/src/headerview.cpp @@ -37,8 +37,7 @@ HeaderView::HeaderView(Qt::Orientation orientation, QWidget *parent) : } HeaderView::~HeaderView() -{ -} += default; void HeaderView::setSeekString(const QString &str) { @@ -77,7 +76,7 @@ void HeaderView::contextMenuEvent(QContextMenuEvent *event) << &a_sections_natural_order; QAction *a = QMenu::exec(lst, viewport()->mapToGlobal(event->pos())); if(a == &a_resize_section) { - QAbstractItemView *view = qobject_cast(parent()); + auto *view = qobject_cast(parent()); QF_ASSERT(view != nullptr, "Bad parent!", return); int log_ix = logicalIndexAt(event->pos()); int sz = view->sizeHintForColumn(log_ix); @@ -152,7 +151,7 @@ void HeaderView::paintSection(QPainter *painter, const QRect §ion_rect, int int horiz_margin = arrow_w / 2; int vert_margin = arrow_w; int arrow_h = arrow_w / 2; - r.setRect(x + w - horiz_margin * 2 - arrow_w, y + vert_margin, + r.setRect(x + w - (horiz_margin * 2) - arrow_w, y + vert_margin, arrow_w, arrow_h); return r; }; @@ -163,7 +162,7 @@ void HeaderView::paintSection(QPainter *painter, const QRect §ion_rect, int painter->setBrush(Qt::yellow); if (sortIndicatorOrder() == Qt::AscendingOrder) { const QPoint points[] = { - QPoint(rect.x() + rect.width() / 2, rect.y() + rect.height()), + QPoint(rect.x() + (rect.width() / 2), rect.y() + rect.height()), QPoint(rect.x(), rect.y()), QPoint(rect.x() + rect.width(), rect.y()), }; @@ -173,7 +172,7 @@ void HeaderView::paintSection(QPainter *painter, const QRect §ion_rect, int const QPoint points[] = { QPoint(rect.x(), rect.y() + rect.height()), QPoint(rect.x() + rect.width(), rect.y() + rect.height()), - QPoint(rect.x() + rect.width() / 2, rect.y()), + QPoint(rect.x() + (rect.width() / 2), rect.y()), }; painter->drawPolygon(points, sizeof points / sizeof *points); } diff --git a/libqf/libqfqmlwidgets/src/htmlviewwidget.cpp b/libqf/libqfqmlwidgets/src/htmlviewwidget.cpp index 698904b85..5531660f7 100644 --- a/libqf/libqfqmlwidgets/src/htmlviewwidget.cpp +++ b/libqf/libqfqmlwidgets/src/htmlviewwidget.cpp @@ -1,8 +1,8 @@ #include "htmlviewwidget.h" #include "ui_htmlviewwidget.h" -namespace qf { -namespace qmlwidgets { + +namespace qf::qmlwidgets { HtmlViewWidget::HtmlViewWidget(QWidget *parent) : Super(parent), @@ -79,5 +79,5 @@ void HtmlViewWidget::settleDownInDialog(dialogs::Dialog *dlg) Super::settleDownInDialog(dlg); } -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets + diff --git a/libqf/libqfqmlwidgets/src/idatawidget.cpp b/libqf/libqfqmlwidgets/src/idatawidget.cpp index 72addf272..67d37cab0 100644 --- a/libqf/libqfqmlwidgets/src/idatawidget.cpp +++ b/libqf/libqfqmlwidgets/src/idatawidget.cpp @@ -14,8 +14,7 @@ IDataWidget::IDataWidget(QWidget *data_widget) } IDataWidget::~IDataWidget() -{ -} += default; void IDataWidget::loadDataValue(DataController *dc) { diff --git a/libqf/libqfqmlwidgets/src/internal/desktoputils.cpp b/libqf/libqfqmlwidgets/src/internal/desktoputils.cpp index ca851e086..dce440a08 100644 --- a/libqf/libqfqmlwidgets/src/internal/desktoputils.cpp +++ b/libqf/libqfqmlwidgets/src/internal/desktoputils.cpp @@ -3,9 +3,9 @@ #include #include -namespace qf { -namespace qmlwidgets { -namespace internal { + + +namespace qf::qmlwidgets::internal { QRect DesktopUtils::moveRectToVisibleDesktopScreen(const QRect &rect) { @@ -20,14 +20,13 @@ QRect DesktopUtils::moveRectToVisibleDesktopScreen(const QRect &rect) if(screen_rect.contains(rect.topLeft())) { return rect; } - else { - auto ret = rect; + auto ret = rect; ret.moveCenter(screen_rect.center()); return ret; - } + } -} // namespace internal -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets::internal + + diff --git a/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.cpp b/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.cpp index dcb98962b..a363a39f1 100644 --- a/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.cpp +++ b/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.cpp @@ -17,6 +17,14 @@ TableViewChooseColumnsWidget::TableViewChooseColumnsWidget(QWidget *parent) ui = new Ui::TableViewChooseColumnsWidget; ui->setupUi(this); + connect(ui->btColumnsAll, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnsAllClicked); + connect(ui->btColumnsNone, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnsNoneClicked); + connect(ui->btColumnsInvert, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnsInvertClicked); + connect(ui->btColumnsAppendSelected, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnsAppendSelectedClicked); + connect(ui->btColumnsRemoveSelected, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnsRemoveSelectedClicked); + connect(ui->btColumnShiftUp, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnShiftUpClicked); + connect(ui->btColumnShiftDown, &QAbstractButton::clicked, this, &TableViewChooseColumnsWidget::onColumnShiftDownClicked); + QStyle *sty = style(); ui->btColumnShiftUp->setIcon(sty->standardIcon(QStyle::SP_ArrowUp)); ui->btColumnShiftDown->setIcon(sty->standardIcon(QStyle::SP_ArrowDown)); @@ -41,7 +49,7 @@ void TableViewChooseColumnsWidget::loadColumns(qf::core::model::TableModel *mode QListWidget *w = ui->lstModelColumns; for(int i=0; icolumnCount(); i++) { QString caption = model->headerData(i, Qt::Horizontal).toString(); - QListWidgetItem *it = new QListWidgetItem(caption); + auto *it = new QListWidgetItem(caption); it->setData(Qt::UserRole, "model"); it->setData(Qt::UserRole+1, i); it->setFlags(it->flags() | Qt::ItemIsEditable); @@ -55,7 +63,7 @@ void TableViewChooseColumnsWidget::loadColumns(qf::core::model::TableModel *mode int i = 0; Q_FOREACH(const qf::core::utils::Table::Field &fld, tbl.fields()) { /// pokud je field soucasti modelu - QListWidgetItem *it = new QListWidgetItem(fld.name()); + auto *it = new QListWidgetItem(fld.name()); it->setData(Qt::UserRole, "table"); it->setData(Qt::UserRole+1, i++); it->setFlags(it->flags() | Qt::ItemIsEditable); @@ -66,25 +74,25 @@ void TableViewChooseColumnsWidget::loadColumns(qf::core::model::TableModel *mode } } -void TableViewChooseColumnsWidget::on_btColumnsAll_clicked() +void TableViewChooseColumnsWidget::onColumnsAllClicked() { QListWidget *w = ui->lstModelColumns->isVisible()? ui->lstModelColumns: ui->lstTableColumns; for(int i=0; icount(); i++) w->item(i)->setSelected(true); } -void TableViewChooseColumnsWidget::on_btColumnsNone_clicked() +void TableViewChooseColumnsWidget::onColumnsNoneClicked() { QListWidget *w = ui->lstModelColumns->isVisible()? ui->lstModelColumns: ui->lstTableColumns; for(int i=0; icount(); i++) w->item(i)->setSelected(false); } -void TableViewChooseColumnsWidget::on_btColumnsInvert_clicked() +void TableViewChooseColumnsWidget::onColumnsInvertClicked() { QListWidget *w = ui->lstModelColumns->isVisible()? ui->lstModelColumns: ui->lstTableColumns; for(int i=0; icount(); i++) w->item(i)->setSelected(!w->item(i)->isSelected()); } -void TableViewChooseColumnsWidget::on_btColumnsAppendSelected_clicked() +void TableViewChooseColumnsWidget::onColumnsAppendSelectedClicked() { QListWidget *w = ui->lstModelColumns->isVisible()? ui->lstModelColumns: ui->lstTableColumns; QStandardItemModel *m = f_exportedColumnsModel; @@ -96,7 +104,7 @@ void TableViewChooseColumnsWidget::on_btColumnsAppendSelected_clicked() QString origin = it->data(Qt::UserRole).toString(); if(origin == "table") qf::core::Utils::parseFieldName(fld_name, &fld_name); - QStandardItem *it2 = new QStandardItem(fld_name); + auto *it2 = new QStandardItem(fld_name); it2->setData(it->data(Qt::UserRole), Qt::UserRole); it2->setData(it->data(Qt::UserRole+1), Qt::UserRole+1); m->setItem(row, 0, it2); @@ -108,7 +116,7 @@ void TableViewChooseColumnsWidget::on_btColumnsAppendSelected_clicked() ui->tblExportedColumns->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); } -void TableViewChooseColumnsWidget::on_btColumnsRemoveSelected_clicked() +void TableViewChooseColumnsWidget::onColumnsRemoveSelectedClicked() { QStandardItemModel *m = f_exportedColumnsModel; QModelIndexList lst = ui->tblExportedColumns->selectionModel()->selectedIndexes(); @@ -121,7 +129,7 @@ void TableViewChooseColumnsWidget::on_btColumnsRemoveSelected_clicked() } } -void TableViewChooseColumnsWidget::on_btColumnShiftUp_clicked() +void TableViewChooseColumnsWidget::onColumnShiftUpClicked() { QModelIndex ix = ui->tblExportedColumns->currentIndex(); int row = ix.row(); @@ -135,7 +143,7 @@ void TableViewChooseColumnsWidget::on_btColumnShiftUp_clicked() } } -void TableViewChooseColumnsWidget::on_btColumnShiftDown_clicked() +void TableViewChooseColumnsWidget::onColumnShiftDownClicked() { QStandardItemModel *m = f_exportedColumnsModel; QModelIndex ix = ui->tblExportedColumns->currentIndex(); @@ -184,7 +192,7 @@ void TableViewChooseColumnsWidget::setExportedColumns(const QVariant& cols) else if(origin == "model") { if(index < 0 || index >= ui->lstModelColumns->count()) continue; } - QStandardItem *it2 = new QStandardItem(mp.value("caption").toString()); + auto *it2 = new QStandardItem(mp.value("caption").toString()); it2->setData(origin, Qt::UserRole); it2->setData(mp.value("index"), Qt::UserRole+1); m->setItem(row, 0, it2); diff --git a/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.h b/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.h index bfc57ffb9..d28a4c5b0 100644 --- a/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.h +++ b/libqf/libqfqmlwidgets/src/internal/tableviewchoosecolumnswidget.h @@ -32,13 +32,13 @@ class TableViewChooseColumnsWidget : public QWidget public: void loadColumns(qf::core::model::TableModel *model); protected slots: - void on_btColumnsAll_clicked(); - void on_btColumnsNone_clicked(); - void on_btColumnsInvert_clicked(); - void on_btColumnsAppendSelected_clicked(); - void on_btColumnsRemoveSelected_clicked(); - void on_btColumnShiftUp_clicked(); - void on_btColumnShiftDown_clicked(); + void onColumnsAllClicked(); + void onColumnsNoneClicked(); + void onColumnsInvertClicked(); + void onColumnsAppendSelectedClicked(); + void onColumnsRemoveSelectedClicked(); + void onColumnShiftUpClicked(); + void onColumnShiftDownClicked(); public: /// [{caption:"",origin:("table" | "model"),index:(col_ix | fld_ix)}, ...] QVariantList exportedColumns() const; diff --git a/libqf/libqfqmlwidgets/src/internal/tableviewcopytodialogwidget.cpp b/libqf/libqfqmlwidgets/src/internal/tableviewcopytodialogwidget.cpp index f54027bba..ee038879f 100644 --- a/libqf/libqfqmlwidgets/src/internal/tableviewcopytodialogwidget.cpp +++ b/libqf/libqfqmlwidgets/src/internal/tableviewcopytodialogwidget.cpp @@ -14,7 +14,7 @@ TableViewCopyToDialogWidget::TableViewCopyToDialogWidget(QWidget *parent) ui = new Ui::TableViewCopyToDialogWidget; ui->setupUi(this); - qfm::TableModel *m = new qfm::TableModel(this); + auto *m = new qfm::TableModel(this); //m->setElideDisplayedTextAt(0); //qfTrash() << QF_FUNC_NAME << "model created:" << f_model; tableView()->setTableModel(m); diff --git a/libqf/libqfqmlwidgets/src/layouttypeproperties.h b/libqf/libqfqmlwidgets/src/layouttypeproperties.h index 23af92214..720327746 100644 --- a/libqf/libqfqmlwidgets/src/layouttypeproperties.h +++ b/libqf/libqfqmlwidgets/src/layouttypeproperties.h @@ -17,7 +17,6 @@ namespace qmlwidgets { class QFQMLWIDGETS_DECL_EXPORT LayoutTypeProperties : public QObject { Q_OBJECT - Q_ENUMS(SizePolicy) Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) @@ -34,6 +33,7 @@ class QFQMLWIDGETS_DECL_EXPORT LayoutTypeProperties : public QObject MinimumExpanding = QSizePolicy::MinimumExpanding, Ignored = QSizePolicy::Ignored }; + Q_ENUM(SizePolicy) public: explicit LayoutTypeProperties(QObject *parent = nullptr); public: diff --git a/libqf/libqfqmlwidgets/src/lineedit.h b/libqf/libqfqmlwidgets/src/lineedit.h index 8037a45b6..7f753a715 100644 --- a/libqf/libqfqmlwidgets/src/lineedit.h +++ b/libqf/libqfqmlwidgets/src/lineedit.h @@ -12,7 +12,7 @@ namespace qmlwidgets { class QFQMLWIDGETS_DECL_EXPORT LineEdit : public QLineEdit, public IDataWidget { Q_OBJECT - Q_ENUMS(EchoMode) + Q_ENUM(EchoMode) Q_PROPERTY(QVariant dataValue READ dataValue WRITE setDataValue NOTIFY dataValueChanged) Q_PROPERTY(QString dataId READ dataId WRITE setDataId) private: diff --git a/libqf/libqfqmlwidgets/src/log.h b/libqf/libqfqmlwidgets/src/log.h index c45c8af00..749b09650 100644 --- a/libqf/libqfqmlwidgets/src/log.h +++ b/libqf/libqfqmlwidgets/src/log.h @@ -4,7 +4,8 @@ #include -inline NecroLog &operator<<(NecroLog log, const QModelIndex &ix) { +inline NecroLog &operator<<(NecroLog &log, const QModelIndex &ix) +{ QString s = "QModelIndex(%1, %2)"; return log.operator<<(s.arg(ix.row()).arg(ix.column()).toStdString()); } diff --git a/libqf/libqfqmlwidgets/src/menubar.cpp b/libqf/libqfqmlwidgets/src/menubar.cpp index c460a207d..4ae837d5e 100644 --- a/libqf/libqfqmlwidgets/src/menubar.cpp +++ b/libqf/libqfqmlwidgets/src/menubar.cpp @@ -32,7 +32,7 @@ Action* MenuBar::actionForPath(const QString &path, bool create_if_not_exists) ret = nullptr; Q_FOREACH(auto a, parent_w->actions()) { qfDebug() << a; - Action *act = qobject_cast(a); + auto *act = qobject_cast(a); //if(!ret) continue; QF_ASSERT(act!=nullptr, "bad action", return ret); if(act->oid() == id) { @@ -45,7 +45,7 @@ Action* MenuBar::actionForPath(const QString &path, bool create_if_not_exists) if(!create_if_not_exists) { break; } - QMenu *m = new QMenu(parent_w); + auto *m = new QMenu(parent_w); ret = new Action(parent_w); ret->setMenu(m); ret->setOid(id); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/banddatamodel.cpp b/libqf/libqfqmlwidgets/src/reports/processor/banddatamodel.cpp index 68f85ca47..946f8d767 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/banddatamodel.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/banddatamodel.cpp @@ -6,7 +6,6 @@ #include -namespace qfc = qf::core; namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -44,7 +43,7 @@ BandDataModel* BandDataModel::createFromData(const QVariant &data, QObject *pare else { tt = qfu::TreeTable(data); } - TreeTableBandDataModel *m = new TreeTableBandDataModel(parent); + auto *m = new TreeTableBandDataModel(parent); m->setTreeTable(tt); ret = m; return ret; @@ -86,7 +85,7 @@ QVariant TreeTableBandDataModel::headerData(int col_no, BandDataModel::DataRole if(role == Qt::DisplayRole) { return treeTable().column(col_no).header(); } - else if(role == Qt::SizeHintRole) { + if(role == Qt::SizeHintRole) { return treeTable().column(col_no).width(); } return QVariant(); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportdocument.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportdocument.cpp index 397306cb0..e28f53350 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportdocument.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportdocument.cpp @@ -9,7 +9,6 @@ //#include #include -namespace qfc = qf::core; //namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitem.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitem.cpp index e6b093414..eab8dea22 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitem.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitem.cpp @@ -21,8 +21,6 @@ #include #include -namespace qfc = qf::core; -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -37,147 +35,26 @@ ReportItem::ReportItem(ReportItem *parent) { m_keepAll = false; m_visible = true; - //QF_ASSERT_EX(processor != nullptr, "Processor can not be NULL."); m_recentPrintNotFinished = false; - //--keepAll = qfc::String(element.attribute("keepall")).toBool(); - //if(keepAll) { qfInfo() << "KEEP ALL is true" << element.attribute("keepall"); } } -ReportItem::~ReportItem() -{ - //qfDebug() << QF_FUNC_NAME << "##################" << element.tagName(); -} -/*-- -bool ReportItem::childrenSynced() -{ - qfDebug() << QF_FUNC_NAME<< element.tagName() << "children count:" << itemCount(); - bool synced = true; - int i = 0; - for(QDomElement el = element.firstChildElement(); !!el; el = el.nextSiblingElement()) { - qfDebug() << "\t checking:" << el.tagName() << "i:" << i; - if(!ReportProcessor::isProcessible(el)) continue; /// nezname elementy ignoruj - qfDebug() << "\t processible"; - if(i >= itemCount()) { - /// vic znamych elementu nez deti => neco pribylo - synced = false; - qfDebug() << "\t more elements"; - break; - } - if(el == childAt(i)->element) { - /// stejny element na stejne posici - i++; - continue; - } - /// doslo k nejaky zmene nebo deti nejsou dosud vytvoreny - qfDebug() << "\t other element"; - synced = false; - break; - } - if(i != itemCount()) { - qfDebug() << "\t divny"; - synced = false; - } - qfDebug() << "\treturn:" << synced; - return synced; -} - -void ReportItem::deleteChildren() -{ - clearChildren(); -} +ReportItem::~ReportItem() = default; -void ReportItem::syncChildren() -{ - qfDebug() << QF_FUNC_NAME << element.tagName() << "id:" << element.attribute("id"); - deleteChildren(); - for(QDomElement el = element.firstChildElement(); !!el; el = el.nextSiblingElement()) { - if(el.tagName() == "script") { - QString code; - for(QDomNode nd = el.firstChild(); !nd.isNull(); nd = nd.nextSibling()) { - if(nd.isCDATASection()) { - code = nd.toCDATASection().data(); - } - } - if(!code.isEmpty()) processor()->scriptDriver()->evaluate(code); - continue; - } - if(!ReportProcessor::isProcessible(el)) continue; - /// vytvor chybejici item - processor()->createProcessibleItem(el, this); - } -} - -QString ReportItem::elementAttribute(const QString & attr_name, const QString &default_val) -{ - QString ret = element.attribute(attr_name, default_val); - static QRegExp rx("script:([A-Za-z]\\S*)\\((.*)\\)"); - if(rx.exactMatch(ret)) { - QF_ASSERT(processor, "Processor is NULL."); - QString fn = rx.cap(1); - ret = rx.cap(2); - QStringList sl = ret.splitAndTrim(',', '\''); - QVariantList vl; - foreach(QString s, sl) vl << s; - ReportProcessorScriptDriver *sd = processor()->scriptDriver(); - if(sd) { - sd->setCurrentCallContextItem(this); - QScriptValue sv = processor()->scriptDriver()->call(this, fn, vl); - ret = sv.toString(); - //qfInfo() << fn << sl.join(",") << "ret:" << ret; - } - else { - ret = "no script driver"; - } - } - return ret; -} ---*/ bool ReportItem::isVisible() { bool ret = processor()->isDesignMode() || m_visible; return ret; } -/*-- -ReportItemBand* ReportItem::parentBand() -{ - ReportItem *it = this->parent(); - while(it) { - if(it->toBand()) return it->toBand(); - it = it->parent(); - } - return nullptr; -} ---*/ + ReportItemBand* ReportItem::parentBand() { - ReportItemBand *ret = qf::core::Utils::findParent(this, false); - return ret; -} -/*-- -qfu::TreeTable ReportItem::findDataTable(const QString &name) -{ - qfLogFuncFrame(); - qfu::TreeTable ret; - ReportItemDetail *d = currentDetail(); - qfDebug() << "\tparent:" << parent() << "parent detail:" << d; - if(d) { - qfDebug() << "\tdata row is null:" << d->dataRow().isNull(); - if(d->dataRow().isNull() && !processor()->isDesignMode()) qfWarning().nospace() << "'" << name << "' parent detail datarow is NULL"; - ret = d->dataRow().table(name); - /// pokud ji nenajde a name neni specifikovano, vezmi 1. tabulku - if(ret.isNull() && name.isEmpty()) ret = d->dataRow().table(0); - //qfInfo() << "\ttable name:" << name << "is null:" << ret.isNull(); - //qfInfo() << name << ret.element().toString(); - } + auto *ret = qf::core::Utils::findParent(this, false); return ret; } ---*/ + ReportItem::PrintResult ReportItem::checkPrintResult(ReportItem::PrintResult res) { PrintResult ret = res; - //if(res.value == PrintNotFit) { - //qfWarning().noSpace() << "PrintNotFit element: '" << element.tagName() << "' id: '" << element.attribute("id") << "' recentlyPrintNotFit: " << recentlyPrintNotFit << " keepall: " << keepAll; - //} if(!canBreak() && m_recentPrintNotFinished && !res.isPrintFinished()) { //qfWarning().noSpace() << "PrintNeverFit element: '" << element.tagName() << "' id: '" << element.attribute("id") << "'"; ret = PrintResult::createPrintError(); @@ -191,7 +68,7 @@ ReportProcessor *ReportItem::processor(bool throw_exc) ReportProcessor *ret = nullptr; QObject *it = this; while(it) { - ReportItemReport *rir = qobject_cast(it); + auto *rir = qobject_cast(it); if(rir) { ret = rir->reportProcessor(); break; @@ -211,7 +88,7 @@ ReportItem::PrintResult ReportItem::printHtml(ReportItem::HTMLElement &out) return PrintResult::createPrintFinished(); } -void ReportItem::createHtmlExportAttributes(ReportItem::HTMLElement &out) +void ReportItem::createHtmlExportAttributes(ReportItem::HTMLElement &out) const { QMapIterator it(htmlExportAttributes()); while(it.hasNext()) { @@ -245,7 +122,7 @@ style::Text *ReportItem::effectiveTextStyle() style::Text *ret = nullptr; ReportItem *it = this; while(it) { - ReportItemFrame *frit = qobject_cast(it); + auto *frit = qobject_cast(it); if(frit) { ret = frit->textStyle(); if(ret) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitem.h b/libqf/libqfqmlwidgets/src/reports/processor/reportitem.h index 6f4439240..abd11cedd 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitem.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitem.h @@ -45,7 +45,6 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItem : public QObject, public QQmlParserSta { Q_OBJECT Q_INTERFACES(QQmlParserStatus) - Q_ENUMS(Layout) /// Pokud ma frame keepAll atribut a dvakrat za sebou se nevytiskne, znamena to, ze se nevytiskne uz nikdy. Q_PROPERTY(bool keepAll READ isKeepAll WRITE setKeepAll) Q_PROPERTY(bool keepWithPrev READ isKeepWithPrev WRITE setKeepWithPrev) @@ -66,7 +65,7 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItem : public QObject, public QQmlParserSta LayoutVertical = graphics::LayoutVertical, LayoutStacked = graphics::LayoutStacked }; - //typedef graphics::Layout Layout; + Q_ENUM(Layout) Q_INVOKABLE bool isVisible(); Q_SLOT void setVisible(bool b) { @@ -368,7 +367,7 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItem : public QObject, public QQmlParserSta protected: style::Text* effectiveTextStyle(); - void createHtmlExportAttributes(HTMLElement &out); + void createHtmlExportAttributes(HTMLElement &out) const; void classBegin() Q_DECL_OVERRIDE; void componentComplete() Q_DECL_OVERRIDE; diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitem_html.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitem_html.cpp index 3ac46c3bc..7b55c2136 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitem_html.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitem_html.cpp @@ -20,7 +20,6 @@ #include -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -102,7 +101,7 @@ ReportItem::PrintResult ReportItemBand::printHtml(ReportItem::HTMLElement &out) ReportItem::PrintResult ReportItemDetail::printHtml(HTMLElement & out) { qfLogFuncFrame() << "current index:" << currentIndex(); - ReportItemBand *band = qobject_cast(parent()); + auto *band = qobject_cast(parent()); BandDataModel *model = nullptr; if(band) { model = band->model(); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemband.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitemband.cpp index 9f765e401..6a3ee81ca 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemband.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemband.cpp @@ -9,8 +9,6 @@ #include #include -namespace qfc = qf::core; -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -149,7 +147,7 @@ bool ReportItemBand::canBreak() ReportItemDetail *ReportItemBand::detail() { - ReportItemDetail *ret = findChild(QString(), Qt::FindDirectChildrenOnly); + auto *ret = findChild(QString(), Qt::FindDirectChildrenOnly); return ret; } @@ -158,13 +156,13 @@ void ReportItemBand::createChildItemsFromData() BandDataModel *mod = model(); qfLogFuncFrame() << "model:" << mod; if(mod) { - style::Brush *brush_lightgray = new style::Brush(this); + auto *brush_lightgray = new style::Brush(this); { - style::Color *c = new style::Color(brush_lightgray); + auto *c = new style::Color(brush_lightgray); c->setDefinition(QColor(Qt::lightGray)); brush_lightgray->setColor(c); } - ReportItemFrame *it_header_frm = new ReportItemFrame(this); + auto *it_header_frm = new ReportItemFrame(this); { it_header_frm->setWidth("%"); it_header_frm->setLayout(ReportItemFrame::LayoutHorizontal); @@ -173,23 +171,23 @@ void ReportItemBand::createChildItemsFromData() //it_header_frm->setVinset(3); } addItem(it_header_frm); - style::Pen *pen_black1 = new style::Pen(this); + auto *pen_black1 = new style::Pen(this); { pen_black1->setWidth(1); - style::Color *c = new style::Color(pen_black1); + auto *c = new style::Color(pen_black1); c->setDefinition(QColor(Qt::black)); pen_black1->setColor(c); } int col_cnt = mod->columnCount(); for(int i=0; isetBorder(pen_black1); it_para->setWidth(mod->headerData(i, Qt::SizeHintRole)); it_para->setText(mod->headerData(i).toString()); it_para->setHinset(1); it_header_frm->addItem(it_para); } - ReportItemDetail *it_det = new ReportItemDetail(this); + auto *it_det = new ReportItemDetail(this); { it_det->setWidth("%"); it_det->setLayout(ReportItemFrame::LayoutHorizontal); @@ -197,7 +195,7 @@ void ReportItemBand::createChildItemsFromData() } addItem(it_det); for(int i=0; isetBorder(pen_black1); it_para->setWidth(mod->headerData(i, Qt::SizeHintRole)); it_para->setHinset(1); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.cpp index 43c001ce6..8fc7de0d9 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.cpp @@ -2,9 +2,9 @@ #include -namespace qf { -namespace qmlwidgets { -namespace reports { + + +namespace qf::qmlwidgets::reports { ReportItemBreak::ReportItemBreak(ReportItem *parent) : Super(parent) @@ -41,7 +41,7 @@ ReportItem::PrintResult ReportItemBreak::printMetaPaint(ReportItemMetaPaint *out return ret; } -} // namespace reports -} // namespace qmlwidgets -} // namespace qf +} // namespace qf::qmlwidgets::reports + + diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.h b/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.h index 5c19d3827..5c6cfeb01 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitembreak.h @@ -12,7 +12,6 @@ namespace reports { class QFQMLWIDGETS_DECL_EXPORT ReportItemBreak : public ReportItem { Q_OBJECT - Q_ENUMS(BreakType) Q_PROPERTY(BreakType breakType READ breakType WRITE setBreakType NOTIFY breakTypeChanged) Q_PROPERTY(bool skipFirst READ isSkipFirst WRITE setSkipFirst) private: @@ -21,6 +20,7 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItemBreak : public ReportItem ReportItemBreak(ReportItem *parent = nullptr); enum BreakType { Column, Page }; + Q_ENUM(BreakType) QF_PROPERTY_IMPL2(BreakType, b, B, reakType, Column) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemdetail.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitemdetail.cpp index 27bf673db..2a4421a71 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemdetail.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemdetail.cpp @@ -9,8 +9,6 @@ #include -namespace qfc = qf::core; -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -83,7 +81,7 @@ ReportItem::PrintResult ReportItemDetail::printMetaPaint(ReportItemMetaPaint *ou { qfLogFuncFrame(); QF_TIME_SCOPE("ReportItemDetail::printMetaPaint"); - ReportItemBand *band = qobject_cast(parent()); + auto *band = qobject_cast(parent()); BandDataModel *model = nullptr; if(band) { model = band->model(); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.cpp index 94c8f6330..43d76c9e5 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.cpp @@ -12,7 +12,6 @@ #include namespace qfc = qf::core; -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; //========================================================== @@ -153,7 +152,7 @@ QString ReportItemFrame::toString(int indent, int indent_offset) QQmlListProperty ReportItemFrame::items() { - return QQmlListProperty(this, 0, + return QQmlListProperty(this, nullptr, ReportItemFrame::addItemFunction, ReportItemFrame::countItemsFunction, ReportItemFrame::itemAtFunction, @@ -163,11 +162,11 @@ QQmlListProperty ReportItemFrame::items() void ReportItemFrame::insertItem(int ix, QObject *item_object) { - ReportItem *item = qobject_cast(item_object); + auto *item = qobject_cast(item_object); if (item) { item->setParent(this); this->m_items.insert(ix, item); - ReportItemFrame *frm = qobject_cast(item); + auto *frm = qobject_cast(item); if(frm) frm->initDesignedRect(); } @@ -181,7 +180,7 @@ void ReportItemFrame::addItem(QObject *item_object) void ReportItemFrame::addItemFunction(QQmlListProperty *list_property, ReportItem *item) { if (item) { - ReportItemFrame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); item->setParent(that); that->m_items << item; } @@ -189,20 +188,20 @@ void ReportItemFrame::addItemFunction(QQmlListProperty *list_propert ReportItem *ReportItemFrame::itemAtFunction(QQmlListProperty *list_property, WidgetIndexType index) { - ReportItemFrame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); return that->m_items.value(index); } void ReportItemFrame::removeAllItemsFunction(QQmlListProperty *list_property) { - ReportItemFrame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); qDeleteAll(that->m_items); that->m_items.clear(); } ReportItemFrame::WidgetIndexType ReportItemFrame::countItemsFunction(QQmlListProperty *list_property) { - ReportItemFrame *that = static_cast(list_property->object); + auto *that = static_cast(list_property->object); return that->itemCount(); } @@ -484,7 +483,7 @@ ReportItem::PrintResult ReportItemFrame::printMetaPaintChildren(ReportItemMetaPa d = sz.size; } else { - ReportItemFrame *frit = qobject_cast(child_item_to_print); + auto *frit = qobject_cast(child_item_to_print); if(frit) qfWarning() << "This should never happen" << child_item_to_print; } @@ -572,7 +571,7 @@ ReportItem::PrintResult ReportItemFrame::printMetaPaint(ReportItemMetaPaint *out double ly_size = frame_content_br.width() - (columns_gap * (sl.count() - 1)); column_sizes = qf::qmlwidgets::graphics::makeLayoutSizes(sl, ly_size); } - ReportItemMetaPaintFrame *metapaint_frame = new ReportItemMetaPaintFrame(out, this); + auto *metapaint_frame = new ReportItemMetaPaintFrame(out, this); QF_ASSERT_EX(metapaint_frame != nullptr, "Meta paint item for item " + QString(this->metaObject()->className()) + " not created."); metapaint_frame->setInset(hinset(), vinset()); metapaint_frame->setLayout((qf::qmlwidgets::graphics::Layout)layout()); @@ -614,9 +613,8 @@ ReportItem::PrintResult ReportItemFrame::printMetaPaint(ReportItemMetaPaint *out //qfWarning() << "new m_indexToPrint:" << parent_frame->m_indexToPrint; continue; } - else { - qfWarning() << "Index to print == 0: Internal error!"; - } + qfWarning() << "Index to print == 0: Internal error!"; + } break; } @@ -650,9 +648,9 @@ ReportItem::PrintResult ReportItemFrame::printMetaPaint(ReportItemMetaPaint *out if(designedRect.horizontalUnit == Rect::UnitPercent) dirty_rect.setWidth(frame_content_br.width()); /// horizontalni rozmer musi ctit procenta else if(designedRect.horizontalUnit == Rect::UnitMM && designedRect.width() > Epsilon) - dirty_rect.setWidth(designedRect.width() - 2*hinset()); + dirty_rect.setWidth(designedRect.width() - (2*hinset())); if(designedRect.verticalUnit == Rect::UnitMM && designedRect.height() > Epsilon) - dirty_rect.setHeight(designedRect.height() - 2*vinset()); + dirty_rect.setHeight(designedRect.height() - (2*vinset())); /// pri rendrovani se muze stat, ze dirtyRect nezacina na bbr, to ale alignment zase spravi dirty_rect.moveTopLeft(frame_content_br.topLeft()); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.h b/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.h index 2990ea7da..f9047fe72 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemframe.h @@ -21,8 +21,6 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItemFrame : public ReportItem typedef ReportItem Super; public: Q_CLASSINFO("DefaultProperty", "items") - Q_ENUMS(HAlignment) - Q_ENUMS(VAlignment) Q_PROPERTY(QQmlListProperty items READ items) Q_PROPERTY(qreal hinset READ hinset WRITE setHinset NOTIFY hinsetChanged) Q_PROPERTY(qreal vinset READ vinset WRITE setVinset NOTIFY vinsetChanged) @@ -79,6 +77,9 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItemFrame : public ReportItem enum VAlignment { AlignTop = Qt::AlignTop, AlignBottom = Qt::AlignBottom, AlignVCenter = Qt::AlignVCenter }; + Q_ENUM(HAlignment) + Q_ENUM(VAlignment) + QF_PROPERTY_IMPL2(qreal, h, H, inset, 0) QF_PROPERTY_IMPL2(qreal, v, V, inset, 0) QF_PROPERTY_IMPL2(qreal, r, R, enderedWidth, 0) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.cpp index f85698e04..938f916bd 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.cpp @@ -12,7 +12,6 @@ #include #include -namespace qfc = qf::core; namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -312,7 +311,7 @@ ReportItemImage::PrintResult ReportItemImage::printMetaPaintChildren(ReportItemM } if(im.isNull()) qfWarning() << "Printing an empty image"; - ReportItemMetaPaintImage *img = new ReportItemMetaPaintImage(out, this); + auto *img = new ReportItemMetaPaintImage(out, this); img->setSuppressPrintOut(isSuppressPrintout()); //qfInfo() << "\t src:" << src; //qfInfo() << "\t processor()->images().contains(" << src << "):" << processor()->images().contains(src); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.h b/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.h index 2ab3cb9bf..f26cb16bd 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemimage.h @@ -18,11 +18,6 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItemImage : public ReportItemFrame { Q_OBJECT - Q_ENUMS(DataFormat) - Q_ENUMS(DataEncoding) - Q_ENUMS(DataCompression) - Q_ENUMS(AspectRatio) - Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource NOTIFY dataSourceChanged) Q_PROPERTY(QString data READ data WRITE setData NOTIFY dataChanged) Q_PROPERTY(DataFormat dataFormat READ dataFormat WRITE setDataFormat NOTIFY dataFormatChanged) @@ -56,6 +51,11 @@ class QFQMLWIDGETS_DECL_EXPORT ReportItemImage : public ReportItemFrame AspectRatioKeep = Qt::KeepAspectRatio, AspectRatioKeepExpanding = Qt::KeepAspectRatioByExpanding }; + Q_ENUM(DataFormat) + Q_ENUM(DataEncoding) + Q_ENUM(DataCompression) + Q_ENUM(AspectRatio) + QF_PROPERTY_IMPL(QString, d, D, ataSource) QF_PROPERTY_IMPL(QString, d, D, ata) QF_PROPERTY_IMPL2(DataFormat, d, D, ataFormat, FormatAuto) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitempara.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitempara.cpp index b2322ac4d..5e4263960 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitempara.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitempara.cpp @@ -9,8 +9,6 @@ #include -namespace qfc = qf::core; -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; @@ -68,7 +66,7 @@ ReportItem::PrintResult ReportItemPara::printMetaPaintChildren(ReportItemMetaPai text_option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); //alignment_flags |= Qt::TextWordWrap; int al = static_cast(textHAlign()) | static_cast(textVAlign()); - Qt::Alignment alignment_flags = (Qt::Alignment)al; + auto alignment_flags = (Qt::Alignment)al; text_option.setAlignment(alignment_flags); } Rect device_bounding_rect; @@ -117,12 +115,11 @@ ReportItem::PrintResult ReportItemPara::printMetaPaintChildren(ReportItemMetaPai text_item_should_be_created = false; break; } - else { - /// neco se preci jenom veslo + /// neco se preci jenom veslo int pos = line.textStart(); m_indexToPrint += pos; break; - } + } height += interline_space; line.setPosition(QPointF(0., height)); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportitemreport.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportitemreport.cpp index a8ef764ff..17e6db68b 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportitemreport.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportitemreport.cpp @@ -2,8 +2,6 @@ #include -namespace qfc = qf::core; -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; //========================================================== diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportpainter.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportpainter.cpp index 72a7afcd1..3300daf50 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportpainter.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportpainter.cpp @@ -15,63 +15,48 @@ #include +#include #include using namespace qf::qmlwidgets::reports; //================================================= -// ReportItemMetaPaint +// ReportItemMetaPaint //================================================= -//const QString ReportItemMetaPaint::currentPageReportSubstitution = "@{#}"; const QString ReportItemMetaPaint::pageCountReportSubstitution = "@{n}"; -//const QString ReportItemMetaPaint::checkOnReportSubstitution = "@{check:1}"; const QString ReportItemMetaPaint::checkReportSubstitution = "@{check:${STATE}}"; -const QRegularExpression ReportItemMetaPaint::checkReportSubstitutionRegExp = QRegularExpression(QRegularExpression::anchoredPattern("@\\{check:(\\d)\\}")); +const QRegularExpression ReportItemMetaPaint::checkReportSubstitutionRegExp = QRegularExpression(QRegularExpression::anchoredPattern(R"(@\{check:(\d)\})")); ReportItemMetaPaint::ReportItemMetaPaint() : Super(nullptr) { - //f_layoutSettings = nullptr; } ReportItemMetaPaint::ReportItemMetaPaint(ReportItemMetaPaint *_parent, ReportItem *report_item) : Super(_parent) { - if(!report_item) - QF_EXCEPTION("report_item is NULL."); - if(!report_item->processor()) - QF_EXCEPTION("report_item->processor is NULL."); - //f_reportItem = report_item; - { - double fill_vertical_layout_ratio = report_item->childSize(ReportItem::LayoutVertical).fillLayoutRatio(); - setFillVLayoutRatio(fill_vertical_layout_ratio); - } + Q_ASSERT(report_item); + Q_ASSERT(report_item->processor()); + double fill_vertical_layout_ratio = report_item->childSize(ReportItem::LayoutVertical).fillLayoutRatio(); + setFillVLayoutRatio(fill_vertical_layout_ratio); } -ReportItemMetaPaint::~ ReportItemMetaPaint() -{ - //SAFE_DELETE(f_layoutSettings); -} +ReportItemMetaPaint::~ ReportItemMetaPaint() = default; ReportItemMetaPaint* ReportItemMetaPaint::child(int ix) const { - ReportItemMetaPaint *ret = dynamic_cast(Super::child(ix)); + auto *ret = dynamic_cast(Super::child(ix)); if(!ret) { qfWarning() << "Child at index" << ix << "is not a kind of ReportItemMetaPaint."; //qfInfo() << NecroLog::stackTrace(); } return ret; } -/* -ReportItem* ReportItemMetaPaint::reportItem() -{ - return f_reportItem; -} -*/ + void ReportItemMetaPaint::paint(ReportPainter *painter, unsigned mode) { foreach(Super *_it, children()) { - ReportItemMetaPaint *it = static_cast(_it); + auto *it = static_cast(_it); it->paint(painter, mode); } } @@ -89,7 +74,7 @@ void ReportItemMetaPaint::setInset(qreal hinset, qreal vinset) void ReportItemMetaPaint::shiftChildren(const ReportItem::Point offset) { foreach(Super *_it, children()) { - ReportItemMetaPaint *it = static_cast(_it); + auto *it = static_cast(_it); it->renderedRect.translate(offset); it->shiftChildren(offset); } @@ -113,7 +98,7 @@ void ReportItemMetaPaint::expandChildFrames() } foreach(Super *_it, children()) { /// ve smeru ortogonalnim k layoutu natahni vsechny deti - ReportItemMetaPaint *it = static_cast(_it); + auto *it = static_cast(_it); if(it->isExpandable()) { if(renderedRect.flags & ReportItem::Rect::LayoutHorizontalFlag) { it->renderedRect.setTop(renderedRect.top() + insetVertical()); @@ -194,16 +179,14 @@ void ReportItemMetaPaint::expandChildVerticalSpringFrames() } } qreal rest_percent = 1 - sum_percent; - if(rest_percent < 0) - rest_percent = 0; + rest_percent = std::max(rest_percent, 0); qreal percent_0 = 0; if(cnt_0_percent > 0) percent_0 = rest_percent / cnt_0_percent; if(spring_children_ixs.count()) { double rest_mm = layout_size - sum_mm; - if(rest_mm < 0) - rest_mm = 0; + rest_mm = std::max(rest_mm, 0); double children_ly_offset = 0; //insetVertical(); for(int i=0; irenderedRect.toString(); - if(i == 0) r1 = it->renderedRect; - else r1 = r1.united(it->renderedRect); + if(i == 0) + r1 = it->renderedRect; // NOLINT(cppcoreguidelines-slicing) + else + r1 = r1.united(it->renderedRect); } qfDebug() << "\t potisknuty blok:" << r1.toString(); qreal al = 0, d; if(layout() == qf::qmlwidgets::graphics::LayoutHorizontal) { - if(alignment() & Qt::AlignHCenter) al = 0.5; - else if(alignment() & Qt::AlignRight) al = 1; + if(alignment() & Qt::AlignHCenter) + al = 0.5; + else if(alignment() & Qt::AlignRight) + al = 1; d = dirty_rect.width() - r1.width(); if(al > 0 && d > 0) { offset.rx() = d * al - (r1.left() - dirty_rect.left()); @@ -338,13 +325,13 @@ QString ReportItemMetaPaint::dump(int indent) QString indent_str; indent_str.fill(' ', indent); const char *type_name = typeid(*this).name(); - QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(type_name).arg((qulonglong)this, 0, 16); + QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(type_name).arg(reinterpret_cast(this), 0, 16); //QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(type_name).arg((qulonglong)this, 0, 16); - ReportItemMetaPaintFrame *frm = dynamic_cast(this); + auto *frm = dynamic_cast(this); if(frm) ret += " : " + frm->renderedRect.toString(); ret += "\n"; foreach(Super *_it, children()) { - ReportItemMetaPaint *it = static_cast(_it); + auto *it = static_cast(_it); ret += it->dump(indent + 2); } return ret; @@ -369,7 +356,11 @@ ReportItemMetaPaintReport::ReportItemMetaPaintReport(ReportItem *report_item) // ReportItemMetaPaintFrame //================================================= ReportItemMetaPaintFrame::ReportItemMetaPaintFrame(ReportItemMetaPaint *_parent, ReportItem *report_item) - : ReportItemMetaPaint(_parent, report_item), lbrd(Qt::NoPen), rbrd(Qt::NoPen), tbrd(Qt::NoPen), bbrd(Qt::NoPen) + : ReportItemMetaPaint(_parent, report_item) + , lbrd(Qt::NoPen) + , rbrd(Qt::NoPen) + , tbrd(Qt::NoPen) + , bbrd(Qt::NoPen) { //qfDebug() << QF_FUNC_NAME << reportElement.tagName(); QF_ASSERT_EX(report_item != nullptr, "ReportItem is NULL"); @@ -378,7 +369,7 @@ ReportItemMetaPaintFrame::ReportItemMetaPaintFrame(ReportItemMetaPaint *_parent, ReportProcessor *proc = report_item->processor(); if(proc) design_mode = proc->isDesignMode(); - ReportItemFrame *frame_item = qobject_cast(report_item); + auto *frame_item = qobject_cast(report_item); if(frame_item) { { style::Brush *b = frame_item->fill(); @@ -409,31 +400,6 @@ ReportItemMetaPaintFrame::ReportItemMetaPaintFrame(ReportItemMetaPaint *_parent, } } } - /*-- - QString s = report_item->property("fill").toString(); - if(!s.isEmpty()) { - if(s.startsWith("{grid:")) { - s.replace('|', '"'); - QJsonDocument json_doc = QJsonDocument::fromJson(s.toUtf8()); - alternativeFillDef = json_doc.toVariant(); - } - else - fill = context().styleCache().brush(s); - } - s = report_item->property("lbrd").toString(); - if(!s.isEmpty()) - lbrd = context().styleCache().pen(s); - s = report_item->property("rbrd").toString(); - if(!s.isEmpty()) - rbrd = context().styleCache().pen(s); - s = report_item->property("tbrd").toString(); - if(!s.isEmpty()) - tbrd = context().styleCache().pen(s); - s = report_item->property("bbrd").toString(); - if(!s.isEmpty()) - bbrd = context().styleCache().pen(s); - --*/ - //qfDebug() << "\tRETURN"; } void ReportItemMetaPaintFrame::paint(ReportPainter *painter, unsigned mode) @@ -462,7 +428,7 @@ void ReportItemMetaPaintFrame::fillItem(QPainter *painter, bool selected) //qfInfo() << "\t br:" << r.toString(); //qfDebug() << "\tbrush color:" if(selected) { - painter->fillRect(r, QColor("#FFEEEE")); + painter->fillRect(r, QColor(0xFFEEEE)); } else { if(fill.style() != Qt::NoBrush) @@ -516,26 +482,7 @@ void ReportItemMetaPaintFrame::drawLine(QPainter *painter, LinePos where, const } } //================================================= -// ReportItemMetaPaintPage -//================================================= -/* -ReportItemMetaPaintPage::ReportItemMetaPaintPage(ReportItemMetaPaint *parent, const QFDomElement &el, const ReportProcessor::Context &context) - : ReportItemMetaPaintFrame(parent, el, context) -{ -} - -void ReportItemMetaPaintPage::paint(ReportPainter *painter) -{ - qfDebug() << QF_FUNC_NAME << reportElement.tagName(); - qfDebug() << "\trenderedRect:" << renderedRect.toString(); - //qfDebug() << "\tchildren cnt:" << children.count(); - //painter->fillRect(renderedRect, context().brushFromString("color: white")); - ReportItemMetaPaintFrame::paint(painter); -} - */ - -//================================================= -// ReportItemMetaPaintText +// ReportItemMetaPaintText //================================================= void ReportItemMetaPaintText::paint(ReportPainter *painter, unsigned mode) { @@ -545,10 +492,10 @@ void ReportItemMetaPaintText::paint(ReportPainter *painter, unsigned mode) return; //bool is_yellow = false; - ReportPainter *rep_painter = dynamic_cast(painter); + auto *rep_painter = painter; if(rep_painter && rep_painter->isMarkEditableSqlText() && !sqlId.isEmpty()) { /// zazlut cely parent frame, az do ktereho se muze editovatelny text roztahnout - ReportItemMetaPaintFrame *it = dynamic_cast(parent()); + auto *it = dynamic_cast(parent()); if(it) { Rect r = qf::qmlwidgets::graphics::mm2device(it->renderedRect, painter->device()); painter->fillRect(r, Qt::yellow); @@ -568,25 +515,21 @@ void ReportItemMetaPaintText::paint(ReportPainter *painter, unsigned mode) //s = s.replace(currentPageReportSubstitution, QString::number(painter->currentPage + 1)); s = s.replace(pageCountReportSubstitution, QString::number(painter->pageCount)); } - Rect br = renderedRect; + Rect br = renderedRect; // NOLINT(cppcoreguidelines-slicing) auto parent_item = parent(); if(parent_item) { - Rect pbr = parent_item->renderedRect; + Rect pbr = parent_item->renderedRect; // NOLINT(cppcoreguidelines-slicing) qreal hinset = br.left() - pbr.left(); if(textOption.alignment() & Qt::AlignRight) { br.moveLeft(br.left() + pbr.width() - br.width() - hinset - hinset); } else if(textOption.alignment() & Qt::AlignHCenter) { - br.moveLeft(br.left() + (pbr.width() - br.width()) / 2 - hinset); + br.moveLeft(br.left() + ((pbr.width() - br.width()) / 2) - hinset); } } br = qf::qmlwidgets::graphics::mm2device(br, painter->device()); br.adjust(0, 0, 1, 1); /// nekdy se stane, kvuji nepresnostem prepocitavani jednotek, ze se to vyrendruje pri tisku jinak, nez pri kompilaci, tohle trochu pomaha:) - //qfWarning().noSpace() << "'" << s << "' flags: " << flags; - //painter->drawRect(br); -#if 0 - painter->drawText(br, flags, s); -#else + /// to samy jako v #if 0, jen se to tiskne stejnym zpusobem, jako se to kompilovalo, coz muze ukazat, proc to vypada jinak, nez cekam qreal leading = font_metrics.leading(); qreal height = 0; @@ -599,7 +542,7 @@ void ReportItemMetaPaintText::paint(ReportPainter *painter, unsigned mode) textLayout.setFont(painter->font()); textLayout.setText(s); textLayout.beginLayout(); - while (1) { + while (true) { QTextLine line = textLayout.createLine(); if(!line.isValid()) { break; @@ -613,18 +556,17 @@ void ReportItemMetaPaintText::paint(ReportPainter *painter, unsigned mode) } textLayout.endLayout(); textLayout.draw(painter, br.topLeft()); -#endif } QString ReportItemMetaPaintText::dump(int indent) { QString indent_str; indent_str.fill(' ', indent); - QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(typeid(*this).name()).arg((qulonglong)this, 0, 16); + QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(typeid(*this).name()).arg(reinterpret_cast(this), 0, 16); //QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(typeid(*this).name()).arg((qulonglong)this, 0, 16); ret += QString(" '%1'\n").arg(text); foreach(auto _it, children()) { - ReportItemMetaPaint *it = static_cast(_it); + auto *it = static_cast(_it); ret += it->dump(indent + 2); } return ret; @@ -663,7 +605,7 @@ void ReportItemMetaPaintCheck::paint(ReportPainter * painter, unsigned mode) painter->drawRect(qf::qmlwidgets::graphics::mm2device(r, painter->device())); if(check_on) { -#if 0 +#ifdef CHECK_MARK_HOOK /// CHECK hook static QString s_check = "color: teal; style: solid; size:2"; painter->setPen(context().styleCache().pen(s_check)); @@ -696,7 +638,7 @@ void ReportItemMetaPaintImage::paint(ReportPainter *painter, unsigned mode) { //qfDebug().color(QFLog::Green) << QF_FUNC_NAME << reportElement.tagName() << "mode:" << mode; QF_ASSERT(painter, "painter is nullptr", return); - QPrinter *printer = dynamic_cast(painter->device()); + auto *printer = dynamic_cast(painter->device()); //if(printer) { qfInfo() << "printer output format:" << printer->outputFormat() << "is native printer:" << (printer->outputFormat() == QPrinter::NativeFormat); } if(printer && printer->outputFormat() == QPrinter::NativeFormat) { if(isSuppressPrintOut()) { @@ -750,7 +692,7 @@ QString ReportItemMetaPaintImage::dump(int indent) { QString indent_str; indent_str.fill(' ', indent); - QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(typeid(*this).name()).arg((qulonglong)this, 0, 16); + QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(typeid(*this).name()).arg(reinterpret_cast(this), 0, 16); //QString ret = QString("%1[%2] 0x%3").arg(indent_str).arg(typeid(*this).name()).arg((qulonglong)this, 0, 16); ret += QString(" '%1'\n").arg("image"); return ret; diff --git a/libqf/libqfqmlwidgets/src/reports/processor/reportprocessor.cpp b/libqf/libqfqmlwidgets/src/reports/processor/reportprocessor.cpp index 1ea02fb6b..4c31c7315 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/reportprocessor.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/reportprocessor.cpp @@ -177,17 +177,16 @@ void ReportProcessor::process(ReportProcessor::ProcessorMode mode) //qfInfo() << "pageProcessed:" << fProcessedPageNo; break; } + if(m_singlePageProcessResult.isPrintAgain()) { + setProcessedPageNo(processedPageNo() + 1); + } else { - if(m_singlePageProcessResult.isPrintAgain()) { - setProcessedPageNo(processedPageNo() + 1); - } - else { - break; - } + break; } - } - else break; + else { + break; + } } } @@ -422,7 +421,7 @@ ReportItemMetaPaintFrame* ReportProcessor::getPage(int n) if(!processorOutput()) return nullptr; if(n < 0 || n >= processorOutput()->childrenCount()) return nullptr; ReportItemMetaPaint *it = processorOutput()->child(n); - ReportItemMetaPaintFrame *frm = dynamic_cast(it); + auto *frm = dynamic_cast(it); qfDebug() << "\treturn:" << frm; return frm; } diff --git a/libqf/libqfqmlwidgets/src/reports/processor/style/brush.cpp b/libqf/libqfqmlwidgets/src/reports/processor/style/brush.cpp index 04f59f165..51d0fd01b 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/style/brush.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/style/brush.cpp @@ -9,10 +9,7 @@ Brush::Brush(QObject *parent) : { } -Brush::~Brush() -{ - //qfLogFuncFrame(); -} +Brush::~Brush() = default; QBrush Brush::brush() { @@ -24,7 +21,7 @@ QBrush Brush::brush() qfDebug() << "\t based on:" << v.toString(); if(v.isValid()) { QObject *o = styleobjectFromVariant(v); - Brush *based_on = qobject_cast(o); + auto *based_on = qobject_cast(o); qfDebug() << "\t\t based on object:" << based_on; if(based_on) { m_brush = based_on->brush(); diff --git a/libqf/libqfqmlwidgets/src/reports/processor/style/brush.h b/libqf/libqfqmlwidgets/src/reports/processor/style/brush.h index 934108a39..732a227a9 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/style/brush.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/style/brush.h @@ -19,7 +19,6 @@ namespace style { class QFQMLWIDGETS_DECL_EXPORT Brush : public StyleObject { Q_OBJECT - Q_ENUMS(BrushStyle) // there are some restrictions for assigning primitive types to default properties, see: pen.h Q_CLASSINFO("DefaultProperty", "basedOn") Q_PROPERTY(QVariant basedOn READ basedOn WRITE setBasedOn) @@ -39,6 +38,7 @@ class QFQMLWIDGETS_DECL_EXPORT Brush : public StyleObject FDiagPattern = Qt::FDiagPattern, DiagCrossPattern = Qt::DiagCrossPattern }; + Q_ENUM(BrushStyle) QF_PROPERTY_OBJECT_IMPL(Color*, c, C, olor) QF_PROPERTY_IMPL(QVariant, b, B, asedOn) QF_PROPERTY_IMPL2(BrushStyle, s, S, tyle, NoBrush) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/style/color.cpp b/libqf/libqfqmlwidgets/src/reports/processor/style/color.cpp index 926ec47b2..9b64e2640 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/style/color.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/style/color.cpp @@ -33,7 +33,7 @@ QColor Color::color() if(!m_color.isValid()) { Sheet *ss = rootStyleSheet(); if(ss) { - Color *pco = qobject_cast(ss->styleObjectForName(SGColor, v.toString())); + auto *pco = qobject_cast(ss->styleObjectForName(SGColor, v.toString())); if(pco) m_color = pco->color(); } diff --git a/libqf/libqfqmlwidgets/src/reports/processor/style/font.h b/libqf/libqfqmlwidgets/src/reports/processor/style/font.h index 6c9228440..2bcec3879 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/style/font.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/style/font.h @@ -18,9 +18,6 @@ namespace style { class QFQMLWIDGETS_DECL_EXPORT Font : public StyleObject { Q_OBJECT - Q_ENUMS(FontStyle) - Q_ENUMS(FontStyleHint) - Q_ENUMS(FontWeight) // there are some restrictions for assigning primitive types to default properties, see: pen.h Q_CLASSINFO("DefaultProperty", "basedOn") Q_PROPERTY(QVariant basedOn READ basedOn WRITE setBasedOn) @@ -63,6 +60,10 @@ class QFQMLWIDGETS_DECL_EXPORT Font : public StyleObject WeightBlack = QFont::Black, WeightInherited }; + Q_ENUM(FontStyle) + Q_ENUM(FontStyleHint) + Q_ENUM(FontWeight) + QF_PROPERTY_IMPL(QVariant, b, B, asedOn) QF_PROPERTY_IMPL(QString, f, F, amily) QF_PROPERTY_IMPL2(FontStyle, s, S, tyle, StyleInherited) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/style/pen.h b/libqf/libqfqmlwidgets/src/reports/processor/style/pen.h index 3e112931e..3acadaf1b 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/style/pen.h +++ b/libqf/libqfqmlwidgets/src/reports/processor/style/pen.h @@ -18,7 +18,6 @@ namespace style { class QFQMLWIDGETS_DECL_EXPORT Pen : public StyleObject { Q_OBJECT - Q_ENUMS(PenStyle) // From qt doc: // A default property is the property to which a value is assigned // if an object is declared within another object's definition without declaring it @@ -48,6 +47,7 @@ class QFQMLWIDGETS_DECL_EXPORT Pen : public StyleObject DashDotDotLine = Qt::DashDotDotLine, CustomDashLine = Qt::CustomDashLine }; + Q_ENUM(PenStyle) //QF_PROPERTY_IMPL(QString, n, N, ame) QF_PROPERTY_OBJECT_IMPL(Color*, c, C, olor) QF_PROPERTY_IMPL(QVariant, b, B, asedOn) diff --git a/libqf/libqfqmlwidgets/src/reports/processor/style/sheet.cpp b/libqf/libqfqmlwidgets/src/reports/processor/style/sheet.cpp index fb0ed665c..99c2b0ecb 100644 --- a/libqf/libqfqmlwidgets/src/reports/processor/style/sheet.cpp +++ b/libqf/libqfqmlwidgets/src/reports/processor/style/sheet.cpp @@ -30,7 +30,7 @@ void Sheet::createStyleCache_helper(QObject *parent) if(!parent) return; Q_FOREACH(auto child, parent->children()) { - StyleObject *so = dynamic_cast(child); + auto *so = dynamic_cast(child); if(so) { QString name = so->name(); if(!name.isEmpty()) { diff --git a/libqf/libqfqmlwidgets/src/reports/widgets/reportviewwidget.cpp b/libqf/libqfqmlwidgets/src/reports/widgets/reportviewwidget.cpp index 714a1dd9b..51d49e462 100644 --- a/libqf/libqfqmlwidgets/src/reports/widgets/reportviewwidget.cpp +++ b/libqf/libqfqmlwidgets/src/reports/widgets/reportviewwidget.cpp @@ -44,7 +44,6 @@ #include -namespace qfu = qf::core::utils; using namespace qf::qmlwidgets::reports; //==================================================== @@ -90,12 +89,12 @@ bool ReportViewWidget::showReport2(QWidget *parent parent = qf::qmlwidgets::framework::MainWindow::frameWork(); qf::qmlwidgets::dialogs::Dialog dlg(parent); dlg.setCentralWidget(w); - bool report_printed = false; - connect(w, &qf::qmlwidgets::reports::ReportViewWidget::reportPrinted, [&report_printed](int) { - report_printed = true; + auto report_printed = std::make_shared(false); + connect(w, &qf::qmlwidgets::reports::ReportViewWidget::reportPrinted, [report_printed](int) { + *report_printed = true; }); dlg.exec(); - return report_printed; + return *report_printed; } void ReportViewWidget::ScrollArea::wheelEvent(QWheelEvent * ev) @@ -113,8 +112,7 @@ void ReportViewWidget::ScrollArea::wheelEvent(QWheelEvent * ev) ev->accept(); return; } - else { - QScrollBar *sb = verticalScrollBar(); + QScrollBar *sb = verticalScrollBar(); if(sb) { if(sb->value() == sb->minimum() && delta > 0) { emit showPreviousPage(); @@ -139,7 +137,7 @@ void ReportViewWidget::ScrollArea::wheelEvent(QWheelEvent * ev) ev->accept(); return; } - } + } QScrollArea::wheelEvent(ev); } @@ -261,7 +259,7 @@ void ReportViewWidget::PainterWidget::paintEvent(QPaintEvent *ev) /// nakresli ramecek a stranku //painter.setBrush(Qt::yellow); QRect r1 = rect(); - painter.fillRect(r1, QBrush(QColor("#CCFF99"))); + painter.fillRect(r1, QBrush(QColor(0xCCFF99))); reportViewWidget()->setupPainter(&painter); ReportItemMetaPaintFrame *frm = reportViewWidget()->currentPage(); @@ -294,7 +292,7 @@ void ReportViewWidget::PainterWidget::mousePressEvent(QMouseEvent *e) if(selected_item) { if(e->button() == Qt::RightButton) { //qfInfo() << "\t item type:" << typeid(*selected_item).name(); - ReportItemMetaPaintText *it = dynamic_cast(selected_item->firstChild()); + auto *it = dynamic_cast(selected_item->firstChild()); if(it) { QMenu menu(this); menu.setTitle(tr("Item menu")); @@ -317,7 +315,7 @@ void ReportViewWidget::PainterWidget::mousePressEvent(QMouseEvent *e) act_edit->setEnabled(true); QAction *a = menu.exec(mapToGlobal(e->pos())); if(a == act_edit) { - ItemValueEditorWidget *w = new ItemValueEditorWidget(); + auto *w = new ItemValueEditorWidget(); w->setValue(it->text); dialogs::Dialog dlg(this); dlg.setCentralWidget(w); @@ -485,8 +483,8 @@ void ReportViewWidget::view_zoomToFitWidth() qfDebug() << QF_FUNC_NAME; ReportItemMetaPaintFrame *frm = currentPage(); if(!frm) return; - ReportItemMetaPaintFrame::Rect r = frm->renderedRect; - double report_px = (r.width() + 2*PageBorder) * logicalDpiX() / 25.4; + auto r = frm->renderedRect; + double report_px = (r.width() + 2 * PageBorder) * logicalDpiX() / 25.4; double widget_px = m_scrollArea->width(); //QScrollBar *sb = f_scrollArea->verticalScrollBar(); //if(sb) widget_px -= sb->width(); @@ -498,8 +496,8 @@ void ReportViewWidget::view_zoomToFitHeight() { ReportItemMetaPaintFrame *frm = currentPage(); if(!frm) return; - ReportItemMetaPaintFrame::Rect r = frm->renderedRect; - double report_px = (r.height() + 2*PageBorder) * m_painterWidget->logicalDpiY() / 25.4; + auto r = frm->renderedRect; + double report_px = (r.height() + 2 * PageBorder) * m_painterWidget->logicalDpiY() / 25.4; double widget_px = m_scrollArea->height(); double sc = widget_px / report_px * 0.98; setScale(sc); @@ -755,7 +753,7 @@ ReportItemMetaPaintFrame* ReportViewWidget::getPage(int n) if(n < 0 || n >= document()->childrenCount()) return nullptr; ReportItemMetaPaint *it = document()->child(n); - ReportItemMetaPaintFrame *frm = dynamic_cast(it); + auto *frm = dynamic_cast(it); //qfDebug() << "\treturn:" << frm; return frm; } @@ -835,7 +833,7 @@ ReportItemMetaPaint* ReportViewWidget::selectItem_helper(ReportItemMetaPaint *it /// traverse items in reverse order to select top level items in stacked layout auto chlst = it->children(); for(int i=chlst.count()-1; i>=0; i--) { - ReportItemMetaPaint *it1 = static_cast(chlst[i]); + auto *it1 = static_cast(chlst[i]); ReportItemMetaPaint *child_sel_it = selectItem_helper(it1, p); if(child_sel_it) { if(ret == it) @@ -1048,9 +1046,9 @@ void ReportViewWidget::exportPdf(const QString &file_name) if(fn.isEmpty()) QF_EXCEPTION(tr("empty file name")); auto ext = QStringLiteral(".pdf"); - if(!fn.toLower().endsWith(ext)) + if(!fn.endsWith(ext, Qt::CaseInsensitive)) { fn += ext; - + } QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fn); @@ -1071,7 +1069,7 @@ QString addHtmlEnvelope(const QString &html_body_content) QString ret; ret += "" + eoln; ret += "" + eoln; - ret += "" + eoln; + ret += R"()" + eoln; ret += "Data" + eoln; ret += "