Mercurial > projects > qtd
comparison demos/browser/history.d @ 66:3b98e3fecd9b
more porting
author | mandel |
---|---|
date | Tue, 19 May 2009 19:47:40 +0000 |
parents | a62227112f5b |
children | b149ef2cb18b |
comparison
equal
deleted
inserted
replaced
65:a62227112f5b | 66:3b98e3fecd9b |
---|---|
280 first = i - 1; | 280 first = i - 1; |
281 break; | 281 break; |
282 } | 282 } |
283 } | 283 } |
284 } | 284 } |
285 | |
285 if (first == m_history.count() - 1) | 286 if (first == m_history.count() - 1) |
286 saveAll = true; | 287 saveAll = true; |
287 | 288 |
288 QString directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation); | 289 QString directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation); |
289 if (directory.isEmpty()) | 290 if (directory.isEmpty()) |
480 | 481 |
481 this(HistoryManager history, QObject parent = null) | 482 this(HistoryManager history, QObject parent = null) |
482 { | 483 { |
483 super(parent); | 484 super(parent); |
484 m_history = history; | 485 m_history = history; |
485 | |
486 assert(m_history); | 486 assert(m_history); |
487 | 487 |
488 m_history.historyReset.connect(&this.historyReset); | 488 m_history.historyReset.connect(&this.historyReset); |
489 m_history.entryRemoved.connect(&this.historyReset); | 489 m_history.entryRemoved.connect(&this.historyReset); |
490 m_history.entryAdded.connect(&this.entryAdded); | 490 m_history.entryAdded.connect(&this.entryAdded); |
571 | 571 |
572 private: | 572 private: |
573 HistoryManager m_history; | 573 HistoryManager m_history; |
574 } | 574 } |
575 | 575 |
576 | |
576 const uint MOVEDROWS = 15; | 577 const uint MOVEDROWS = 15; |
578 | |
577 | 579 |
578 /*! | 580 /*! |
579 Proxy model that will remove any duplicate entries. | 581 Proxy model that will remove any duplicate entries. |
580 Both m_sourceRow and m_historyHash store their offsets not from | 582 Both m_sourceRow and m_historyHash store their offsets not from |
581 the front of the list, but as offsets from the back. | 583 the front of the list, but as offsets from the back. |
929 | 931 |
930 this(QWidget parent = null) | 932 this(QWidget parent = null) |
931 { | 933 { |
932 super(parent); | 934 super(parent); |
933 m_history = 0; | 935 m_history = 0; |
934 connect(this, SIGNAL(activated(QModelIndex )), | 936 activated.connect(&this.activated); |
935 this, SLOT(activated(QModelIndex ))); | |
936 setHoverRole(HistoryModel.UrlStringRole); | 937 setHoverRole(HistoryModel.UrlStringRole); |
937 } | 938 } |
938 | 939 |
939 void setInitialActions(QList<QAction> actions) | 940 void setInitialActions(QList<QAction> actions) |
940 { | 941 { |
941 m_initialActions = actions; | 942 m_initialActions = actions; |
942 for (int i = 0; i < m_initialActions.count(); ++i) | 943 for (int i = 0; i < m_initialActions.count(); ++i) |
943 addAction(m_initialActions.at(i)); | 944 addAction(m_initialActions.at(i)); |
944 } | 945 } |
945 | 946 |
946 protected: | 947 protected: |
947 | 948 |
948 bool prePopulated() | 949 bool prePopulated() |
949 { | 950 { |
994 | 995 |
995 HistoryManager m_history; | 996 HistoryManager m_history; |
996 HistoryMenuModel m_historyMenuModel; | 997 HistoryMenuModel m_historyMenuModel; |
997 QList<QAction> m_initialActions; | 998 QList<QAction> m_initialActions; |
998 } | 999 } |
1000 | |
999 | 1001 |
1000 // proxy model for the history model that | 1002 // proxy model for the history model that |
1001 // exposes each url http://www.foo.com and it url starting at the host www.foo.com | 1003 // exposes each url http://www.foo.com and it url starting at the host www.foo.com |
1002 class HistoryCompletionModel : public QAbstractProxyModel | 1004 class HistoryCompletionModel : public QAbstractProxyModel |
1003 { | 1005 { |
1136 int columnCount(QModelIndex parent); | 1138 int columnCount(QModelIndex parent); |
1137 { | 1139 { |
1138 return sourceModel().columnCount(mapToSource(parent)); | 1140 return sourceModel().columnCount(mapToSource(parent)); |
1139 } | 1141 } |
1140 | 1142 |
1141 | |
1142 int rowCount(QModelIndex parent = QModelIndex()) | 1143 int rowCount(QModelIndex parent = QModelIndex()) |
1143 { | 1144 { |
1144 if ( parent.internalId() != 0 || parent.column() > 0 || !sourceModel()) | 1145 if ( parent.internalId() != 0 || parent.column() > 0 || !sourceModel()) |
1145 return 0; | 1146 return 0; |
1146 | 1147 |
1175 { | 1176 { |
1176 if (!sourceIndex.isValid()) | 1177 if (!sourceIndex.isValid()) |
1177 return QModelIndex(); | 1178 return QModelIndex(); |
1178 | 1179 |
1179 if (m_sourceRowCache.isEmpty()) | 1180 if (m_sourceRowCache.isEmpty()) |
1180 rowCount(QModelIndex()); | 1181 rowCount(QModelIndex()); |
1181 | 1182 |
1182 QList<int>.iterator it; | 1183 QList<int>.iterator it; |
1183 it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), sourceIndex.row()); | 1184 it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), sourceIndex.row()); |
1184 if (*it != sourceIndex.row()) | 1185 if (*it != sourceIndex.row()) |
1185 --it; | 1186 --it; |
1186 int dateRow = qMax(0, it - m_sourceRowCache.begin()); | 1187 int dateRow = qMax(0, it - m_sourceRowCache.begin()); |
1187 int row = sourceIndex.row() - m_sourceRowCache.at(dateRow); | 1188 int row = sourceIndex.row() - m_sourceRowCache.at(dateRow); |
1188 return createIndex(row, sourceIndex.column(), dateRow + 1); | 1189 return createIndex(row, sourceIndex.column(), dateRow + 1); |
1189 } | 1190 } |
1190 | 1191 |