diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qlogging.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qdebug.cpp | 41 | ||||
-rw-r--r-- | src/corelib/io/qdebug.h | 33 | ||||
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 40 | ||||
-rw-r--r-- | src/widgets/widgets/qtabbar.h | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qtabbar_p.h | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qtabwidget.cpp | 23 | ||||
-rw-r--r-- | src/widgets/widgets/qtabwidget.h | 4 |
8 files changed, 143 insertions, 10 deletions
diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index 6ebffa3ba1..043f799414 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -65,9 +65,9 @@ class QMessageLogContext { Q_DISABLE_COPY(QMessageLogContext) public: - Q_DECL_CONSTEXPR QMessageLogContext() : version(1), line(0), file(0), function(0), category(0) {} + Q_DECL_CONSTEXPR QMessageLogContext() : version(2), line(0), file(0), function(0), category(0) {} Q_DECL_CONSTEXPR QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) - : version(1), line(lineNumber), file(fileName), function(functionName), category(categoryName) {} + : version(2), line(lineNumber), file(fileName), function(functionName), category(categoryName) {} void copy(const QMessageLogContext &logContext); diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 44d0a788ff..038e9cb0a3 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -202,6 +202,41 @@ QDebug::~QDebug() \sa QDebugStateSaver */ + +/*! + \fn QDebug &QDebug::quote() + \since 5.4 + + Enables automatic insertion of quotation characters around QChar, QString and QByteArray + contents and returns a reference to the stream. + + Quoting is enabled by default. + + \sa noquote(), maybeQuote() +*/ + +/*! + \fn QDebug &QDebug::noquote() + \since 5.4 + + Disables automatic insertion of quotation characters around QChar, QString and QByteArray + contents and returns a reference to the stream. + + \sa quote(), maybeQuote() +*/ + +/*! + \fn QDebug &QDebug::maybeQuote(char c) + \since 5.4 + + Writes a character \a c to the debug stream, depending on the + current setting for automatic insertion of quotes, and returns a reference to the stream. + + The default character is a double quote \c{"}. + + \sa quote(), noquote() +*/ + /*! \fn QDebug &QDebug::operator<<(QChar t) @@ -368,19 +403,25 @@ public: QDebugStateSaverPrivate(QDebug &dbg) : m_dbg(dbg), m_spaces(dbg.autoInsertSpaces()), + m_flags(0), m_streamParams(dbg.stream->ts.d_ptr->params) { + if (m_dbg.stream->context.version > 1) + m_flags = m_dbg.stream->flags; } void restoreState() { m_dbg.setAutoInsertSpaces(m_spaces); m_dbg.stream->ts.d_ptr->params = m_streamParams; + if (m_dbg.stream->context.version > 1) + m_dbg.stream->flags = m_flags; } QDebug &m_dbg; // QDebug state const bool m_spaces; + int m_flags; // QTextStream state const QTextStreamPrivate::Params m_streamParams; diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 584d6bf41f..0bbb617c1f 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -61,9 +61,9 @@ class Q_CORE_EXPORT QDebug friend class QMessageLogger; friend class QDebugStateSaverPrivate; struct Stream { - Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg), space(true), message_output(false) {} - Stream(QString *string) : ts(string, QIODevice::WriteOnly), ref(1), type(QtDebugMsg), space(true), message_output(false) {} - Stream(QtMsgType t) : ts(&buffer, QIODevice::WriteOnly), ref(1), type(t), space(true), message_output(true) {} + Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg), space(true), message_output(false), flags(0) {} + Stream(QString *string) : ts(string, QIODevice::WriteOnly), ref(1), type(QtDebugMsg), space(true), message_output(false), flags(0) {} + Stream(QtMsgType t) : ts(&buffer, QIODevice::WriteOnly), ref(1), type(t), space(true), message_output(true), flags(0) {} QTextStream ts; QString buffer; int ref; @@ -71,6 +71,18 @@ class Q_CORE_EXPORT QDebug bool space; bool message_output; QMessageLogContext context; + + enum FormatFlag { + NoQuotes = 0x1 + }; + + // ### Qt 6: unify with space, introduce own version member + bool testFlag(FormatFlag flag) const { return (context.version > 1) ? (flags & flag) : false; } + void setFlag(FormatFlag flag) { if (context.version > 1) { flags |= flag; } } + void unsetFlag(FormatFlag flag) { if (context.version > 1) { flags &= ~flag; } } + + // added in 5.4 + int flags; } *stream; public: inline QDebug(QIODevice *device) : stream(new Stream(device)) {} @@ -88,7 +100,11 @@ public: bool autoInsertSpaces() const { return stream->space; } void setAutoInsertSpaces(bool b) { stream->space = b; } - inline QDebug &operator<<(QChar t) { stream->ts << '\'' << t << '\''; return maybeSpace(); } + inline QDebug "e() { stream->unsetFlag(Stream::NoQuotes); return *this; } + inline QDebug &noquote() { stream->setFlag(Stream::NoQuotes); return *this; } + inline QDebug &maybeQuote(char c = '"') { if (!(stream->testFlag(Stream::NoQuotes))) stream->ts << c; return *this; } + + inline QDebug &operator<<(QChar t) { maybeQuote('\''); stream->ts << t; maybeQuote('\''); return maybeSpace(); } inline QDebug &operator<<(bool t) { stream->ts << (t ? "true" : "false"); return maybeSpace(); } inline QDebug &operator<<(char t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(signed short t) { stream->ts << t; return maybeSpace(); } @@ -102,10 +118,10 @@ public: inline QDebug &operator<<(float t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(double t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(const char* t) { stream->ts << QString::fromUtf8(t); return maybeSpace(); } - inline QDebug &operator<<(const QString & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); } + inline QDebug &operator<<(const QString & t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); } inline QDebug &operator<<(const QStringRef & t) { return operator<<(t.toString()); } - inline QDebug &operator<<(QLatin1String t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); } - inline QDebug &operator<<(const QByteArray & t) { stream->ts << '\"' << t << '\"'; return maybeSpace(); } + inline QDebug &operator<<(QLatin1String t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); } + inline QDebug &operator<<(const QByteArray & t) { maybeQuote(); stream->ts << t; maybeQuote(); return maybeSpace(); } inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(QTextStreamFunction f) { stream->ts << f; @@ -137,6 +153,9 @@ public: inline QNoDebug &space() { return *this; } inline QNoDebug &nospace() { return *this; } inline QNoDebug &maybeSpace() { return *this; } + inline QNoDebug "e() { return *this; } + inline QNoDebug &noquote() { return *this; } + inline QNoDebug &maybeQuote(const char = '"') { return *this; } template<typename T> inline QNoDebug &operator<<(const T &) { return *this; } diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 789ec2f6fd..e8fdc65711 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -632,6 +632,14 @@ void QTabBarPrivate::layoutWidgets(int start) } } +void QTabBarPrivate::autoHideTabs() +{ + Q_Q(QTabBar); + + if (autoHide) + q->setVisible(q->count() > 1); +} + void QTabBarPrivate::_q_closeTab() { Q_Q(QTabBar); @@ -861,6 +869,7 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text) } tabInserted(index); + d->autoHideTabs(); return index; } @@ -936,6 +945,7 @@ void QTabBar::removeTab(int index) setCurrentIndex(d->currentIndex - 1); } d->refresh(); + d->autoHideTabs(); tabRemoved(index); } } @@ -2267,6 +2277,36 @@ void QTabBar::setDocumentMode(bool enabled) } /*! + \property QTabBar::autoHide + \brief If true, the tab bar is automatically hidden when it contains less + than 2 tabs. + \since 5.4 + + By default, this property is false. + + \sa QWidget::visible +*/ + +bool QTabBar::autoHide() const +{ + Q_D(const QTabBar); + return d->autoHide; +} + +void QTabBar::setAutoHide(bool hide) +{ + Q_D(QTabBar); + if (d->autoHide == hide) + return; + + d->autoHide = hide; + if (hide) + d->autoHideTabs(); + else + setVisible(true); +} + +/*! Sets \a widget on the tab \a index. The widget is placed on the left or right hand side depending upon the \a position. \since 4.5 diff --git a/src/widgets/widgets/qtabbar.h b/src/widgets/widgets/qtabbar.h index a0e52c2f86..a1616b1524 100644 --- a/src/widgets/widgets/qtabbar.h +++ b/src/widgets/widgets/qtabbar.h @@ -70,6 +70,7 @@ class Q_WIDGETS_EXPORT QTabBar: public QWidget Q_PROPERTY(bool expanding READ expanding WRITE setExpanding) Q_PROPERTY(bool movable READ isMovable WRITE setMovable) Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode) + Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide) public: explicit QTabBar(QWidget* parent=0); @@ -166,6 +167,9 @@ public: bool documentMode() const; void setDocumentMode(bool set); + bool autoHide() const; + void setAutoHide(bool hide); + public Q_SLOTS: void setCurrentIndex(int index); diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h index 3228308bc6..1238057e2a 100644 --- a/src/widgets/widgets/qtabbar_p.h +++ b/src/widgets/widgets/qtabbar_p.h @@ -77,7 +77,7 @@ public: :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false), drawBase(true), scrollOffset(0), elideModeSetByUser(false), useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), - dragInProgress(false), documentMode(false), movingTab(0) + dragInProgress(false), documentMode(false), autoHide(false), movingTab(0) #ifdef Q_WS_MAC , previousPressedIndex(-1) #endif @@ -184,6 +184,7 @@ public: void updateMacBorderMetrics(); bool isTabInMacUnifiedToolbarArea() const; void setupMovableTab(); + void autoHideTabs(); void makeVisible(int index); QSize iconSize; @@ -201,6 +202,7 @@ public: bool movable; bool dragInProgress; bool documentMode; + bool autoHide; QWidget *movingTab; #ifdef Q_WS_MAC diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index fced1c01ec..616b66b80b 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -1351,6 +1351,29 @@ void QTabWidget::setDocumentMode(bool enabled) } /*! + \property QTabWidget::tabBarAutoHide + \brief If true, the tab bar is automatically hidden when it contains less + than 2 tabs. + \since 5.4 + + By default, this property is false. + + \sa QWidget::visible +*/ + +bool QTabWidget::tabBarAutoHide() const +{ + Q_D(const QTabWidget); + return d->tabs->autoHide(); +} + +void QTabWidget::setTabBarAutoHide(bool enabled) +{ + Q_D(QTabWidget); + return d->tabs->setAutoHide(enabled); +} + +/*! Removes all the pages, but does not delete them. Calling this function is equivalent to calling removeTab() until the tab widget is empty. */ diff --git a/src/widgets/widgets/qtabwidget.h b/src/widgets/widgets/qtabwidget.h index 83c2e31d28..046e544bf0 100644 --- a/src/widgets/widgets/qtabwidget.h +++ b/src/widgets/widgets/qtabwidget.h @@ -68,6 +68,7 @@ class Q_WIDGETS_EXPORT QTabWidget : public QWidget Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode) Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable) Q_PROPERTY(bool movable READ isMovable WRITE setMovable) + Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide WRITE setTabBarAutoHide) public: explicit QTabWidget(QWidget *parent = 0); @@ -140,6 +141,9 @@ public: bool documentMode() const; void setDocumentMode(bool set); + bool tabBarAutoHide() const; + void setTabBarAutoHide(bool enabled); + void clear(); QTabBar* tabBar() const; |