Ignore:
Timestamp:
Feb 26, 2010, 7:49:00 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

tests/widget: Cleaned up debugging according to r605 changes and added a simple QProcess test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/widget/widget.cpp

    r536 r611  
    33#include <QtGui>
    44
    5 #ifndef Q_WS_PM
    6 
    7 // For printing non-quoted QString's with QDebug)
    8 struct QDbgStr: public QString
    9 {
    10     inline QDbgStr(const QString &str) : QString(str) {}
    11 };
    12 
    13 // Prints a non-quoted QString
    14 inline QDebug operator<<(QDebug dbg, const QDbgStr &str)
    15 { dbg << str.toUtf8().constData(); return dbg; }
    16 
    17 QDbgStr qWidgetName(QWidget *w)
    18 {
    19     if (w)
    20         return QString()
    21             .sprintf("%s.%s", w->metaObject()->className(),
    22                      w->objectName().isEmpty() ? "<noname>" :
    23                      w->objectName().toUtf8().constData());
    24     return QString(QLatin1String("<no-widget>"));
    25 }
    26 
    27 #endif
    28 
    295#define myDefFlagEx(var,fl,varstr,flstr) if (var & fl) { \
    30     if (!varstr.isEmpty()) varstr += QLatin1String("|"); varstr += QLatin1String(flstr); \
     6    if (!varstr.isEmpty()) varstr += ; \
    317} else do {} while(0)
    328
     
    3814QDebug operator<<(QDebug dbg, Qt::WindowStates st)
    3915{
    40     QString name;
     16    Q name;
    4117    myDefFlagEx(st, Qt::WindowMinimized, name, "Min");
    4218    myDefFlagEx(st, Qt::WindowMaximized, name, "Max");
    4319    myDefFlagEx(st, Qt::WindowFullScreen, name, "Full");
    4420    myDefFlagEx(st, Qt::WindowActive, name, "Act");
    45     if (name.isEmpty()) name = QLatin1String("None");
    46     dbg.nospace() << "WindowState(" << QDbgStr(name) << ")";
     21    if (name.isEmpty()) name = ;
     22    dbg.nospace() << "WindowState(" << ) << ")";
    4723    return dbg.space();
    4824}
     
    5026QDebug operator<<(QDebug dbg, Qt::FocusReason r)
    5127{
    52     QString name;
     28    Q name;
    5329    if (r == Qt::MouseFocusReason) name = "Mouse";
    5430    if (r == Qt::TabFocusReason) name = "Tab";
     
    5935    if (r == Qt::MenuBarFocusReason) name = "MenuBar";
    6036    if (r == Qt::OtherFocusReason) name = "Other";
    61     dbg.nospace() << "FocusReason(" << QDbgStr(name) << ")";
     37    dbg.nospace() << "FocusReason(" << ) << ")";
    6238    return dbg.space();
    6339}
     
    8056    void paintEvent(QPaintEvent *aE)
    8157    {
    82         qDebug() << qWidgetName(this) << __FUNCTION__
     58        qDebug() << << __FUNCTION__
    8359                 << ": " << aE->rect() << "focus" << hasFocus();
    8460
     
    10884    void focusInEvent(QFocusEvent *aE)
    10985    {
    110         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
     86        qDebug() << << __FUNCTION__ << ": reason" << aE->reason();
    11187        QWidget::focusInEvent(aE);
    11288    }
     
    11490    void focusOutEvent(QFocusEvent *aE)
    11591    {
    116         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
     92        qDebug() << << __FUNCTION__ << ": reason" << aE->reason();
    11793        QWidget::focusOutEvent(aE);
    11894    }
     
    140116    void focusInEvent(QFocusEvent *aE)
    141117    {
    142         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
     118        qDebug() << << __FUNCTION__ << ":" << text()
    143119                 << "reason" << aE->reason()
    144                  << "focus" << (qApp->focusWidget() ?
    145                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
     120                 << "focus" << qApp->focusWidget();
    146121
    147122        QPushButton::focusInEvent(aE);
     
    150125    void focusOutEvent(QFocusEvent *aE)
    151126    {
    152         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text()
     127        qDebug() << << __FUNCTION__ << ":" << text()
    153128                 << "reason" << aE->reason()
    154                  << "focus" << (qApp->focusWidget() ?
    155                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
     129                 << "focus" << qApp->focusWidget();
    156130        QPushButton::focusOutEvent(aE);
    157131    }
     
    171145    void focusInEvent(QFocusEvent *aE)
    172146    {
    173         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
     147        qDebug() << << __FUNCTION__ << ":" << currentText()
    174148                 << "reason" << aE->reason()
    175                  << "focus" << (qApp->focusWidget() ?
    176                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
     149                 << "focus" << qApp->focusWidget();
    177150        QComboBox::focusInEvent(aE);
    178151    }
     
    180153    void focusOutEvent(QFocusEvent *aE)
    181154    {
    182         qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText()
     155        qDebug() << << __FUNCTION__ << ":" << currentText()
    183156                 << "reason" << aE->reason()
    184                  << "focus" << (qApp->focusWidget() ?
    185                     qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>")));
     157                 << "focus" << qApp->focusWidget();
    186158        QComboBox::focusOutEvent(aE);
    187159    }
     
    218190    {
    219191        qDebug() << __FUNCTION__ << ": btn" << aE->button()
    220                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
    221                                               (int) aE->buttons(), (int) aE->modifiers()))
     192                 <<
     193                 ))
    222194                 << "gpos" << aE->globalPos() << "pos" << aE->pos();
    223195        QComboBox::mousePressEvent(aE);
     
    227199    {
    228200        qDebug() << __FUNCTION__ << ": btn" << aE->button()
    229                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
    230                                               (int) aE->buttons(), (int) aE->modifiers()))
     201                 <<
     202                 ))
    231203                 << "gpos" << aE->globalPos() << "pos" << aE->pos();
    232204        QComboBox::mouseReleaseEvent(aE);
     
    371343    void focusInEvent(QFocusEvent *aE)
    372344    {
    373         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
     345        qDebug() << << __FUNCTION__ << ": reason" << aE->reason();
    374346        QWidget::focusInEvent(aE);
    375347    }
     
    377349    void focusOutEvent(QFocusEvent *aE)
    378350    {
    379         qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason();
     351        qDebug() << << __FUNCTION__ << ": reason" << aE->reason();
    380352        QWidget::focusOutEvent(aE);
    381353    }
     
    401373    void keyPressEvent(QKeyEvent *aE)
    402374    {
    403         qDebug() << __FUNCTION__ << "  : cnt" << aE->count()
    404                  << "rep" << aE->isAutoRepeat()
    405                  << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
    406                  << "text" << aE->text()
    407                  << QDbgStr(aE->text().isEmpty() ? QString() :
    408                             QString().sprintf("(%04X)", aE->text()[0].unicode()));
    409     }
    410 
    411     void keyReleaseEvent(QKeyEvent *aE)
    412     {
    413375        qDebug() << __FUNCTION__ << ": cnt" << aE->count()
    414376                 << "rep" << aE->isAutoRepeat()
    415                  << QDbgStr(QString().sprintf("key %08X mods %08X", aE->key(), (int) aE->modifiers()))
     377                 << "key" << qDebugFmtHex(aE->key())
     378                 << "mods" << qDebugFmtHex(aE->modifiers())
    416379                 << "text" << aE->text()
    417                  << QDbgStr(aE->text().isEmpty() ? QString() :
    418                             QString().sprintf("(%04X)", aE->text()[0].unicode()));
     380                 << qDebugFmtHex((aE->text().isEmpty() ? 0 :
     381                                  aE->text()[0].unicode()));
     382    }
     383
     384    void keyReleaseEvent(QKeyEvent *aE)
     385    {
     386        qDebug() << __FUNCTION__ << ": cnt" << aE->count()
     387                 << "rep" << aE->isAutoRepeat()
     388                 << "key" << qDebugFmtHex(aE->key())
     389                 << "mods" << qDebugFmtHex(aE->modifiers())
     390                 << "text" << aE->text()
     391                 << qDebugFmtHex((aE->text().isEmpty() ? 0 :
     392                                  aE->text()[0].unicode()));
    419393    }
    420394#endif
     
    438412    {
    439413        qDebug() << __FUNCTION__ << ": btn" << aE->button()
    440                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
    441                                               (int) aE->buttons(), (int) aE->modifiers()))
     414                 <<
     415                 ))
    442416                 << "gpos" << aE->globalPos() << "pos" << aE->pos();
    443417
     
    449423    {
    450424        qDebug() << __FUNCTION__ << ": btn" << aE->button()
    451                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
    452                                               (int) aE->buttons(), (int) aE->modifiers()))
     425                 <<
     426                 ))
    453427                 << "gpos" << aE->globalPos() << "pos" << aE->pos();
    454428    }
     
    457431    {
    458432        qDebug() << __FUNCTION__ << ": btn" << aE->button()
    459                  << QDbgStr(QString().sprintf("btns %08X mods %08X",
    460                                               (int) aE->buttons(), (int) aE->modifiers()))
     433                 <<
     434                 ))
    461435                 << "gpos" << aE->globalPos() << "pos" << aE->pos();
    462436    }
     
    509483            QMouseEvent *me = static_cast<QMouseEvent*>(aE);
    510484            qDebug() << this << aE->type() << ": btn" << me->button()
    511                      << QDbgStr(QString().sprintf("btns %08X mods %08X",
    512                                                   (int) me->buttons(), (int) me->modifiers()))
     485                     <<
     486                     ))
    513487                     << "gpos" << me->globalPos() << "pos" << me->pos();
    514488            break;
     
    568542
    569543#if 1
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
    570556    //--------------------------------------------------------------------------
    571557    // QFileInfo test
Note: See TracChangeset for help on using the changeset viewer.