1696 |
1696 |
1697 // insert sections into sectionsHidden |
1697 // insert sections into sectionsHidden |
1698 if (!d->sectionHidden.isEmpty()) { |
1698 if (!d->sectionHidden.isEmpty()) { |
1699 QBitArray sectionHidden(d->sectionHidden); |
1699 QBitArray sectionHidden(d->sectionHidden); |
1700 sectionHidden.resize(sectionHidden.count() + insertCount); |
1700 sectionHidden.resize(sectionHidden.count() + insertCount); |
1701 //sectionHidden.fill(false, logicalFirst, logicalLast + 1); |
1701 sectionHidden.fill(false, logicalFirst, logicalLast + 1); |
1702 for (int i = logicalFirst; i <= logicalLast; ++i) |
|
1703 // visual == logical in this range (see previous block) |
|
1704 sectionHidden.setBit(i, false); |
|
1705 for (int j = logicalLast + 1; j < sectionHidden.count(); ++j) |
1702 for (int j = logicalLast + 1; j < sectionHidden.count(); ++j) |
1706 sectionHidden.setBit(d->visualIndex(j), |
1703 //here we simply copy the old sectionHidden |
1707 d->sectionHidden.testBit(d->visualIndex(j - insertCount))); |
1704 sectionHidden.setBit(j, d->sectionHidden.testBit(j - insertCount)); |
1708 d->sectionHidden = sectionHidden; |
1705 d->sectionHidden = sectionHidden; |
1709 } |
1706 } |
1710 |
1707 |
1711 // insert sections into hiddenSectionSize |
1708 // insert sections into hiddenSectionSize |
1712 QHash<int, int> newHiddenSectionSize; // from logical index to section size |
1709 QHash<int, int> newHiddenSectionSize; // from logical index to section size |
1851 if (modelSectionCount() != sectionCount) |
1848 if (modelSectionCount() != sectionCount) |
1852 q->initializeSections(); |
1849 q->initializeSections(); |
1853 persistentHiddenSections.clear(); |
1850 persistentHiddenSections.clear(); |
1854 return; |
1851 return; |
1855 } |
1852 } |
|
1853 |
|
1854 QBitArray oldSectionHidden = sectionHidden; |
1856 bool sectionCountChanged = false; |
1855 bool sectionCountChanged = false; |
1857 for (int i = 0; i < sectionHidden.count(); ++i) { |
|
1858 if (sectionHidden.testBit(i)) |
|
1859 q->setSectionHidden(logicalIndex(i), false); |
|
1860 } |
|
1861 |
1856 |
1862 for (int i = 0; i < persistentHiddenSections.count(); ++i) { |
1857 for (int i = 0; i < persistentHiddenSections.count(); ++i) { |
1863 QModelIndex index = persistentHiddenSections.at(i); |
1858 QModelIndex index = persistentHiddenSections.at(i); |
1864 if (index.isValid()) { |
1859 if (index.isValid()) { |
1865 const int logical = (orientation == Qt::Horizontal |
1860 const int logical = (orientation == Qt::Horizontal |
1866 ? index.column() |
1861 ? index.column() |
1867 : index.row()); |
1862 : index.row()); |
1868 q->setSectionHidden(logical, true); |
1863 q->setSectionHidden(logical, true); |
|
1864 oldSectionHidden.setBit(logical, false); |
1869 } else if (!sectionCountChanged && (modelSectionCount() != sectionCount)) { |
1865 } else if (!sectionCountChanged && (modelSectionCount() != sectionCount)) { |
1870 sectionCountChanged = true; |
1866 sectionCountChanged = true; |
1871 break; |
1867 break; |
1872 } |
1868 } |
1873 } |
1869 } |
1874 persistentHiddenSections.clear(); |
1870 persistentHiddenSections.clear(); |
|
1871 |
|
1872 for (int i = 0; i < oldSectionHidden.count(); ++i) { |
|
1873 if (oldSectionHidden.testBit(i)) |
|
1874 q->setSectionHidden(logicalIndex(i), false); |
|
1875 } |
1875 |
1876 |
1876 // the number of sections changed; we need to reread the state of the model |
1877 // the number of sections changed; we need to reread the state of the model |
1877 if (sectionCountChanged) |
1878 if (sectionCountChanged) |
1878 q->initializeSections(); |
1879 q->initializeSections(); |
1879 } |
1880 } |
2031 updateSection(oldHover); |
2032 updateSection(oldHover); |
2032 if (d->hover != -1) |
2033 if (d->hover != -1) |
2033 updateSection(d->hover); |
2034 updateSection(d->hover); |
2034 } |
2035 } |
2035 break; } |
2036 break; } |
2036 case QEvent::Timer: { // ### reimplement timerEvent() instead ? |
2037 case QEvent::Timer: { |
2037 QTimerEvent *te = static_cast<QTimerEvent*>(e); |
2038 QTimerEvent *te = static_cast<QTimerEvent*>(e); |
2038 if (te->timerId() == d->delayedResize.timerId()) { |
2039 if (te->timerId() == d->delayedResize.timerId()) { |
2039 d->delayedResize.stop(); |
2040 d->delayedResize.stop(); |
2040 resizeSections(); |
2041 resizeSections(); |
2041 } |
2042 } |
2215 } |
2216 } |
2216 d->lastPos = pos; |
2217 d->lastPos = pos; |
2217 return; |
2218 return; |
2218 } |
2219 } |
2219 case QHeaderViewPrivate::MoveSection: { |
2220 case QHeaderViewPrivate::MoveSection: { |
2220 if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()) { |
2221 if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance() |
2221 int indicatorCenter = (d->orientation == Qt::Horizontal |
2222 || !d->sectionIndicator->isHidden()) { |
2222 ? d->sectionIndicator->width() |
2223 int visual = visualIndexAt(pos); |
2223 : d->sectionIndicator->height()) / 2; |
|
2224 int centerOffset = indicatorCenter - d->sectionIndicatorOffset; |
|
2225 // This will drop the moved section to the position under the center of the indicator. |
|
2226 // If centerOffset is 0, the section will be moved to the position of the mouse cursor. |
|
2227 int visual = visualIndexAt(pos + centerOffset); |
|
2228 if (visual == -1) |
2224 if (visual == -1) |
2229 return; |
2225 return; |
2230 d->target = d->logicalIndex(visual); |
2226 int posThreshold = d->headerSectionPosition(visual) + d->headerSectionSize(visual) / 2; |
|
2227 int moving = visualIndex(d->section); |
|
2228 if (visual < moving) { |
|
2229 if (pos < posThreshold) |
|
2230 d->target = d->logicalIndex(visual); |
|
2231 else |
|
2232 d->target = d->logicalIndex(visual + 1); |
|
2233 } else if (visual > moving) { |
|
2234 if (pos > posThreshold) |
|
2235 d->target = d->logicalIndex(visual); |
|
2236 else |
|
2237 d->target = d->logicalIndex(visual - 1); |
|
2238 } else { |
|
2239 d->target = d->section; |
|
2240 } |
2231 d->updateSectionIndicator(d->section, pos); |
2241 d->updateSectionIndicator(d->section, pos); |
2232 } else { |
|
2233 int visual = visualIndexAt(d->firstPos); |
|
2234 if (visual == -1) |
|
2235 return; |
|
2236 d->target = d->logicalIndex(visual); |
|
2237 d->updateSectionIndicator(d->section, d->firstPos); |
|
2238 } |
2242 } |
2239 return; |
2243 return; |
2240 } |
2244 } |
2241 case QHeaderViewPrivate::SelectSections: { |
2245 case QHeaderViewPrivate::SelectSections: { |
2242 int logical = logicalIndexAt(pos); |
2246 int logical = logicalIndexAt(pos); |
2298 case QHeaderViewPrivate::NoState: |
2302 case QHeaderViewPrivate::NoState: |
2299 if (d->clickableSections) { |
2303 if (d->clickableSections) { |
2300 int section = logicalIndexAt(pos); |
2304 int section = logicalIndexAt(pos); |
2301 if (section != -1 && section == d->pressed) { |
2305 if (section != -1 && section == d->pressed) { |
2302 d->flipSortIndicator(section); |
2306 d->flipSortIndicator(section); |
2303 emit sectionClicked(logicalIndexAt(pos)); |
2307 emit sectionClicked(section); |
2304 } |
2308 } |
2305 if (d->pressed != -1) |
2309 if (d->pressed != -1) |
2306 updateSection(d->pressed); |
2310 updateSection(d->pressed); |
2307 } |
2311 } |
2308 break; |
2312 break; |