Changeset View
Changeset View
Standalone View
Standalone View
sidebar/tree_module/tree_module.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 52 | { | |||
---|---|---|---|---|---|
57 | treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | 57 | treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | ||
58 | 58 | | |||
59 | model = new KDirModel(this); | 59 | model = new KDirModel(this); | ||
60 | sorted_model = new KDirSortFilterProxyModel(this); | 60 | sorted_model = new KDirSortFilterProxyModel(this); | ||
61 | sorted_model->setSortFoldersFirst(true); | 61 | sorted_model->setSortFoldersFirst(true); | ||
62 | sorted_model->setSourceModel(model); | 62 | sorted_model->setSourceModel(model); | ||
63 | model->dirLister()->setDirOnlyMode(true); | 63 | model->dirLister()->setDirOnlyMode(true); | ||
64 | 64 | | |||
65 | #if KDIRMODEL_HAS_ROOT_NODE | | |||
66 | if (m_initURL.isLocalFile()) { // .scheme() == "file" | | |||
67 | model->openUrl(m_initURL, KDirModel::ShowRoot); | 65 | model->openUrl(m_initURL, KDirModel::ShowRoot); | ||
68 | } else { | | |||
69 | model->dirLister()->openUrl(m_initURL, KDirLister::Keep); | | |||
70 | } | | |||
71 | #else | | |||
72 | model->dirLister()->openUrl(m_initURL, KDirLister::Keep); | | |||
73 | #endif | | |||
74 | 66 | | |||
75 | treeView->setModel(sorted_model); | 67 | treeView->setModel(sorted_model); | ||
76 | 68 | | |||
77 | treeView->setColumnHidden(1, true); | 69 | for (int i = 1; i <= 6; i++) { | ||
78 | treeView->setColumnHidden(2, true); | 70 | treeView->setColumnHidden(i, true); | ||
79 | treeView->setColumnHidden(3, true); | 71 | } | ||
80 | treeView->setColumnHidden(4, true); | | |||
81 | treeView->setColumnHidden(5, true); | | |||
82 | treeView->setColumnHidden(6, true); | | |||
83 | 72 | | |||
84 | model->expandToUrl(m_initURL); // KDir is async, we'll just have to wait for slotKDirCompleted() | 73 | model->expandToUrl(m_initURL); // KDir is async, we'll just have to wait for slotKDirCompleted() | ||
85 | connect(model, &KDirModel::expand, | 74 | connect(model, &KDirModel::expand, | ||
86 | this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex); | 75 | this, &KonqSideBarTreeModule::slotKDirExpand_setRootIndex); | ||
87 | 76 | | |||
88 | QItemSelectionModel *selectionModel = treeView->selectionModel(); | 77 | QItemSelectionModel *selectionModel = treeView->selectionModel(); | ||
89 | connect(selectionModel, &QItemSelectionModel::selectionChanged, | 78 | connect(selectionModel, &QItemSelectionModel::selectionChanged, | ||
90 | this, &KonqSideBarTreeModule::slotSelectionChanged); | 79 | this, &KonqSideBarTreeModule::slotSelectionChanged); | ||
Show All 18 Lines | |||||
109 | { | 98 | { | ||
110 | if (!dirtyURL.isValid()) { | 99 | if (!dirtyURL.isValid()) { | ||
111 | return dirtyURL; | 100 | return dirtyURL; | ||
112 | } | 101 | } | ||
113 | QUrl url = dirtyURL; | 102 | QUrl url = dirtyURL; | ||
114 | if (url.isRelative()) { | 103 | if (url.isRelative()) { | ||
115 | url.setScheme("file"); | 104 | url.setScheme("file"); | ||
116 | if (url.path() == "~") { | 105 | if (url.path() == "~") { | ||
117 | QString homePath = QDir::homePath(); | 106 | const QString homePath = QDir::homePath(); | ||
118 | if (!homePath.endsWith("/")) { | 107 | if (!homePath.endsWith("/")) { | ||
119 | url.setPath(homePath.append("/")); | 108 | url.setPath(homePath + "/"); | ||
120 | } else { | 109 | } else { | ||
121 | url.setPath(homePath); | 110 | url.setPath(homePath); | ||
122 | } | 111 | } | ||
123 | } | 112 | } | ||
124 | } | 113 | } | ||
125 | return url; | 114 | return url; | ||
126 | } | 115 | } | ||
127 | 116 | | |||
Show All 21 Lines | |||||
149 | } | 138 | } | ||
150 | 139 | | |||
151 | void KonqSideBarTreeModule::setSelection(const QUrl &target_url, bool do_openURLreq) // do_openURLreq=true) | 140 | void KonqSideBarTreeModule::setSelection(const QUrl &target_url, bool do_openURLreq) // do_openURLreq=true) | ||
152 | { | 141 | { | ||
153 | QModelIndex index = sorted_model->mapFromSource(model->indexForUrl(target_url)); | 142 | QModelIndex index = sorted_model->mapFromSource(model->indexForUrl(target_url)); | ||
154 | 143 | | |||
155 | m_lastURL = target_url; | 144 | m_lastURL = target_url; | ||
156 | 145 | | |||
157 | #if KDIRMODEL_HAS_ROOT_NODE | | |||
158 | if (!index.isValid() && target_url.scheme() == m_initURL.scheme()) { | 146 | if (!index.isValid() && target_url.scheme() == m_initURL.scheme()) { | ||
159 | #else | | |||
160 | if (!index.isValid() && target_url.scheme() == m_initURL.scheme() && target_url != QUrl::fromLocalFile("/")) { | | |||
161 | #endif | | |||
162 | if (do_openURLreq) { | 147 | if (do_openURLreq) { | ||
163 | connect(model, &KDirModel::expand, | 148 | connect(model, &KDirModel::expand, | ||
164 | this, &KonqSideBarTreeModule::slotKDirExpand_setSelection ); | 149 | this, &KonqSideBarTreeModule::slotKDirExpand_setSelection ); | ||
165 | model->expandToUrl(target_url); // KDirModel is async, we'll just have to wait for slotKDirExpand_setSelection() | 150 | model->expandToUrl(target_url); // KDirModel is async, we'll just have to wait for slotKDirExpand_setSelection() | ||
166 | } | 151 | } | ||
167 | } | 152 | } | ||
168 | 153 | | |||
169 | setSelectionIndex(index); | 154 | setSelectionIndex(index); | ||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |