Changeset 561 for trunk/src/gui/itemviews/qitemdelegate.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/itemviews/qitemdelegate.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 48 48 #include <qlineedit.h> 49 49 #include <qtextedit.h> 50 #include <qplaintextedit.h> 50 51 #include <qpainter.h> 51 52 #include <qpalette.h> … … 185 186 186 187 \ingroup model-view 187 \mainclass 188 188 189 189 190 QItemDelegate can be used to provide custom display features and editor … … 219 220 while editing takes place. Editors are created with a 220 221 QItemEditorFactory; a default static instance provided by 221 QItemEditorFactory is installed on all item del agates. You can set222 QItemEditorFactory is installed on all item delegates. You can set 222 223 a custom factory using setItemEditorFactory() or set a new default 223 224 factory with QItemEditorFactory::setDefaultFactory(). It is the … … 255 256 \row \o \l Qt::BackgroundColorRole \o QColor (obsolete; use Qt::BackgroundRole instead) 256 257 \row \o \l Qt::CheckStateRole \o Qt::CheckState 257 \row \o \l Qt::DecorationRole \o QIcon and QColor258 \row \o \l Qt::DecorationRole \o QIcon, QPixmap and QColor 258 259 \row \o \l Qt::DisplayRole \o QString and types with a string representation 259 260 \row \o \l Qt::EditRole \o See QItemEditorFactory for details … … 352 353 { 353 354 QString text; 354 switch (value.type()) { 355 switch (value.userType()) { 356 case QMetaType::Float: 357 text = option.locale.toString(value.toFloat(), 'g'); 358 break; 355 359 case QVariant::Double: 356 360 text = option.locale.toString(value.toDouble(), 'g', DBL_DIG); … … 574 578 575 579 /*! 576 Gets data drom the \a editor widget and stores it in the specified580 Gets data from the \a editor widget and stores it in the specified 577 581 \a model at the item \a index. 578 582 … … 719 723 elided += option.fontMetrics.elidedText(text.mid(start), 720 724 option.textElideMode, textRect.width()); 721 if (end != -1)722 elided += QChar::LineSeparator;723 725 } 724 726 d->textLayout.setText(elided); … … 861 863 /*! 862 864 \internal 865 866 Code duplicated in QCommonStylePrivate::viewItemLayout 863 867 */ 864 868 … … 882 886 883 887 textRect->adjust(-textMargin, 0, textMargin, 0); // add width padding 884 if (textRect->height() == 0 && !hasPixmap) 888 if (textRect->height() == 0 && (!hasPixmap || !hint)) { 889 //if there is no text, we still want to have a decent height for the item sizeHint and the editor size 885 890 textRect->setHeight(option.fontMetrics.height()); 891 } 886 892 887 893 QSize pm(0, 0); … … 1054 1060 1055 1061 QPixmap selected = QPixmap(QPixmap::fromImage(img)); 1056 int n = (img. numBytes() >> 10) + 1;1062 int n = (img.byteCount() >> 10) + 1; 1057 1063 if (QPixmapCache::cacheLimit() < n) 1058 1064 QPixmapCache::setCacheLimit(n); … … 1195 1201 case Qt::Key_Return: 1196 1202 #ifndef QT_NO_TEXTEDIT 1197 if (qobject_cast<QTextEdit *>(editor))1203 if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor)) 1198 1204 return false; // don't filter enter key events for QTextEdit 1199 1205 // We want the editor to be able to process the key press … … 1219 1225 editor->parentWidget()->setFocus(); 1220 1226 return true; 1221 } else if (event->type() == QEvent::FocusOut || event->type() == QEvent::Hide) {1227 } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) { 1222 1228 //the Hide event will take care of he editors that are in fact complete dialogs 1223 1229 if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor)) { … … 1234 1240 return false; 1235 1241 #endif 1236 // Opening a modal dialog will start a new eventloop 1237 // that will process the deleteLater event. 1238 if (QApplication::activeModalWidget() 1239 && !QApplication::activeModalWidget()->isAncestorOf(editor) 1240 && qobject_cast<QDialog*>(QApplication::activeModalWidget())) 1241 return false; 1242 1242 1243 emit commitData(editor); 1243 1244 emit closeEditor(editor, NoHint); … … 1297 1298 } 1298 1299 1299 Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked 1300 Qt::CheckState state; 1301 if ( flags & Qt::ItemIsTristate ) { 1302 state = static_cast<Qt::CheckState>( (value.toInt() + 1) % 3 ); 1303 } else { 1304 state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked 1300 1305 ? Qt::Unchecked : Qt::Checked); 1306 } 1307 1301 1308 return model->setData(index, state, Qt::CheckStateRole); 1302 1309 } … … 1321 1328 value = index.data(Qt::TextAlignmentRole); 1322 1329 if (value.isValid()) 1323 opt.displayAlignment = (Qt::Alignment)value.toInt();1330 opt.displayAlignment = Qt::Alignment(value.toInt()); 1324 1331 1325 1332 // set foreground brush
Note:
See TracChangeset
for help on using the changeset viewer.