q3listview.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 2,264 行 · 第 1/5 页
CPP
2,264 行
}/*! Constructs an empty list view item that is a child of \a parent and is after item \a after in the parent's list of children.*/Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent, Q3ListViewItem * after){ init(); parent->insertItem(this); moveToJustAfter(after);}/*! Constructs a new top-level list view item in the Q3ListView \a parent, with up to eight constant strings, \a label1, \a label2, \a label3, \a label4, \a label5, \a label6, \a label7 and \a label8 defining its columns' contents. \sa setText()*/Q3ListViewItem::Q3ListViewItem(Q3ListView * parent, const QString &label1, const QString &label2, const QString &label3, const QString &label4, const QString &label5, const QString &label6, const QString &label7, const QString &label8){ init(); parent->insertItem(this); setText(0, label1); setText(1, label2); setText(2, label3); setText(3, label4); setText(4, label5); setText(5, label6); setText(6, label7); setText(7, label8);}/*! Constructs a new list view item as a child of the Q3ListViewItem \a parent with up to eight constant strings, \a label1, \a label2, \a label3, \a label4, \a label5, \a label6, \a label7 and \a label8 as columns' contents. \sa setText()*/Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent, const QString &label1, const QString &label2, const QString &label3, const QString &label4, const QString &label5, const QString &label6, const QString &label7, const QString &label8){ init(); parent->insertItem(this); setText(0, label1); setText(1, label2); setText(2, label3); setText(3, label4); setText(4, label5); setText(5, label6); setText(6, label7); setText(7, label8);}/*! Constructs a new list view item in the Q3ListView \a parent that is included after item \a after and that has up to eight column texts, \a label1, \a label2, \a label3, \a label4, \a label5, \a label6, \a label7 and\a label8. Note that the order is changed according to Q3ListViewItem::key() unless the list view's sorting is disabled using Q3ListView::setSorting(-1). \sa setText()*/Q3ListViewItem::Q3ListViewItem(Q3ListView * parent, Q3ListViewItem * after, const QString &label1, const QString &label2, const QString &label3, const QString &label4, const QString &label5, const QString &label6, const QString &label7, const QString &label8){ init(); parent->insertItem(this); moveToJustAfter(after); setText(0, label1); setText(1, label2); setText(2, label3); setText(3, label4); setText(4, label5); setText(5, label6); setText(6, label7); setText(7, label8);}/*! Constructs a new list view item as a child of the Q3ListViewItem \a parent. It is inserted after item \a after and may contain up to eight strings, \a label1, \a label2, \a label3, \a label4, \a label5, \a label6, \a label7 and \a label8 as column entries. Note that the order is changed according to Q3ListViewItem::key() unless the list view's sorting is disabled using Q3ListView::setSorting(-1). \sa setText()*/Q3ListViewItem::Q3ListViewItem(Q3ListViewItem * parent, Q3ListViewItem * after, const QString &label1, const QString &label2, const QString &label3, const QString &label4, const QString &label5, const QString &label6, const QString &label7, const QString &label8){ init(); parent->insertItem(this); moveToJustAfter(after); setText(0, label1); setText(1, label2); setText(2, label3); setText(3, label4); setText(4, label5); setText(5, label6); setText(6, label7); setText(7, label8);}/*! Sorts all this item's child items using the current sorting configuration (sort column and direction). \sa enforceSortOrder()*/void Q3ListViewItem::sort(){ if (!listView()) return; lsc = Unsorted; enforceSortOrder(); listView()->triggerUpdate();}/*! Returns 0. Make your derived classes return their own values for rtti(), so that you can distinguish between different kinds of list view items. You should use values greater than 1000 to allow for extensions to this class.*/int Q3ListViewItem::rtti() const{ return RTTI;}/* Performs the initializations that's common to the constructors.*/void Q3ListViewItem::init(){ ownHeight = 0; maybeTotalHeight = -1; open = false; nChildren = 0; parentItem = 0; siblingItem = childItem = 0; columns = 0; selected = 0; selectable = true; lsc = Unsorted; lso = true; // unsorted in ascending order :) configured = false; expandable = false; selectable = true; is_root = false; allow_drag = false; allow_drop = false; visible = true; renameBox = 0; enabled = true; mlenabled = false;}/*! If \a b is true, the item is made visible; otherwise it is hidden. If the item is not visible, itemAbove() and itemBelow() will never return this item, although you still can reach it by using e.g. Q3ListViewItemIterator.*/void Q3ListViewItem::setVisible(bool b){ if (b == (bool)visible) return; Q3ListView *lv = listView(); if (!lv) return; if (b && parent() && !parent()->isVisible()) return; visible = b; configured = false; setHeight(0); invalidateHeight(); if (parent()) parent()->invalidateHeight(); else lv->d->r->invalidateHeight(); for (Q3ListViewItem *i = childItem; i; i = i->siblingItem) i->setVisible(b); if (lv) lv->triggerUpdate();}/*! Returns true if the item is visible; otherwise returns false. \sa setVisible()*/bool Q3ListViewItem::isVisible() const{ return (bool)visible;}/*! If \a b is true, this item can be in-place renamed in the column \a col by the user; otherwise it cannot be renamed in-place.*/void Q3ListViewItem::setRenameEnabled(int col, bool b){ Q3ListViewPrivate::ItemColumnInfo * l = (Q3ListViewPrivate::ItemColumnInfo*)columns; if (!l) { l = new Q3ListViewPrivate::ItemColumnInfo; columns = (void*)l; } for(int c = 0; c < col; c++) { if (!l->next) l->next = new Q3ListViewPrivate::ItemColumnInfo; l = l->next; } if (!l) return; l->allow_rename = b;}/*! Returns true if this item can be in-place renamed in column \a col; otherwise returns false.*/bool Q3ListViewItem::renameEnabled(int col) const{ Q3ListViewPrivate::ItemColumnInfo * l = (Q3ListViewPrivate::ItemColumnInfo*)columns; if (!l) return false; while(col && l) { l = l->next; col--; } if (!l) return false; return (bool)l->allow_rename;}/*! If \a b is true the item is enabled; otherwise it is disabled. Disabled items are drawn differently (e.g. grayed-out) and are not accessible by the user.*/void Q3ListViewItem::setEnabled(bool b){ if ((bool)enabled == b) return; enabled = b; if (!enabled) selected = false; Q3ListView *lv = listView(); if (lv) { lv->triggerUpdate();#ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::StateChanged);#endif }}/*! Returns true if this item is enabled; otherwise returns false. \sa setEnabled()*/bool Q3ListViewItem::isEnabled() const{ return (bool)enabled;}/*! If in-place renaming of this item is enabled (see renameEnabled()), this function starts renaming the item in column \a col, by creating and initializing an edit box.*/void Q3ListViewItem::startRename(int col){ if (!renameEnabled(col)) return; if (renameBox) cancelRename(col); Q3ListView *lv = listView(); if (!lv) return; if (lv->d->renameTimer) lv->d->renameTimer->stop(); lv->ensureItemVisible(this); if (lv->d->timer->isActive()) { // make sure that pending calculations get finished lv->d->timer->stop(); lv->updateContents(); } if (lv->currentItem() && lv->currentItem()->renameBox) { if (lv->d->defRenameAction == Q3ListView::Reject) lv->currentItem()->cancelRename(lv->currentItem()->renameCol); else lv->currentItem()->okRename(lv->currentItem()->renameCol); } if (this != lv->currentItem()) lv->setCurrentItem(this); QRect r = lv->itemRect(this); r = QRect(lv->viewportToContents(r.topLeft()), r.size()); r.setLeft(lv->header()->sectionPos(col)); r.setWidth(qMin(lv->header()->sectionSize(col) - 1, lv->contentsX() + lv->visibleWidth() - r.left())); if (col == 0) r.setLeft(r.left() + lv->itemMargin() + (depth() + (lv->rootIsDecorated() ? 1 : 0)) * lv->treeStepSize() - 1); if (pixmap(col)) r.setLeft(r.left() + pixmap(col)->width()); if (r.x() - lv->contentsX() < 0) { lv->scrollBy(r.x() - lv->contentsX(), 0); r.setX(lv->contentsX()); } else if ((lv->contentsX() + lv->visibleWidth()) < (r.x() + r.width())) { lv->scrollBy((r.x() + r.width()) - (lv->contentsX() + lv->visibleWidth()), 0); } if (r.width() > lv->visibleWidth()) r.setWidth(lv->visibleWidth()); renameBox = new QLineEdit(lv->viewport(), "qt_renamebox"); renameBox->setFrame(false); renameBox->setText(text(col)); renameBox->selectAll(); renameBox->installEventFilter(lv); lv->addChild(renameBox, r.x(), r.y()); renameBox->resize(r.size()); lv->viewport()->setFocusProxy(renameBox); renameBox->setFocus(); renameBox->show(); renameCol = col;}/*! This function removes the rename box.*/void Q3ListViewItem::removeRenameBox(){ // Sanity, it should be checked by the functions calling this first anyway Q3ListView *lv = listView(); if (!lv || !renameBox) return; const bool resetFocus = lv->viewport()->focusProxy() == renameBox; delete renameBox; renameBox = 0; if (resetFocus) { lv->viewport()->setFocusProxy(lv); lv->setFocus(); }}/*! This function is called if the user presses Enter during in-place renaming of the item in column \a col. \sa cancelRename()*/void Q3ListViewItem::okRename(int col){ Q3ListView *lv = listView(); if (!lv || !renameBox) return; setText(col, renameBox->text()); removeRenameBox(); // we set the parent lsc to Unsorted if that column is the sorted one if (parent() && (int)parent()->lsc == col) parent()->lsc = Unsorted; emit lv->itemRenamed(this, col); emit lv->itemRenamed(this, col, text(col));}/*! This function is called if the user cancels in-place renaming of this item in column \a col (e.g. by pressing Esc).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?