0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the Qt Designer of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
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 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "treewidgeteditor.h"
|
|
43 |
#include <formwindowbase_p.h>
|
|
44 |
#include <iconloader_p.h>
|
|
45 |
#include <qdesigner_command_p.h>
|
|
46 |
#include <qdesigner_utils_p.h>
|
|
47 |
#include <abstractformbuilder.h>
|
|
48 |
#include <designerpropertymanager.h>
|
|
49 |
#include <qttreepropertybrowser.h>
|
|
50 |
|
|
51 |
#include <QtDesigner/QDesignerFormWindowInterface>
|
|
52 |
#include <QtDesigner/QDesignerFormEditorInterface>
|
|
53 |
#include <QtDesigner/QDesignerIconCacheInterface>
|
|
54 |
#include <QtCore/QDir>
|
|
55 |
#include <QtCore/QQueue>
|
|
56 |
#include <QtGui/QHeaderView>
|
|
57 |
#include <QtGui/QTreeWidgetItemIterator>
|
|
58 |
|
|
59 |
QT_BEGIN_NAMESPACE
|
|
60 |
|
|
61 |
namespace qdesigner_internal {
|
|
62 |
|
|
63 |
TreeWidgetEditor::TreeWidgetEditor(QDesignerFormWindowInterface *form, QWidget *parent)
|
|
64 |
: AbstractItemEditor(form, parent), m_updatingBrowser(false)
|
|
65 |
{
|
|
66 |
m_columnEditor = new ItemListEditor(form, this);
|
|
67 |
m_columnEditor->setObjectName(QLatin1String("columnEditor"));
|
|
68 |
m_columnEditor->setNewItemText(tr("New Column"));
|
|
69 |
ui.setupUi(this);
|
|
70 |
|
|
71 |
injectPropertyBrowser(ui.itemsTab, ui.widget);
|
|
72 |
connect(ui.showPropertiesButton, SIGNAL(clicked()),
|
|
73 |
this, SLOT(togglePropertyBrowser()));
|
|
74 |
togglePropertyBrowser();
|
|
75 |
|
|
76 |
ui.tabWidget->insertTab(0, m_columnEditor, tr("&Columns"));
|
|
77 |
ui.tabWidget->setCurrentIndex(0);
|
|
78 |
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
79 |
|
|
80 |
ui.newItemButton->setIcon(createIconSet(QString::fromUtf8("plus.png")));
|
|
81 |
ui.newSubItemButton->setIcon(createIconSet(QString::fromUtf8("downplus.png")));
|
|
82 |
ui.deleteItemButton->setIcon(createIconSet(QString::fromUtf8("minus.png")));
|
|
83 |
ui.moveItemUpButton->setIcon(createIconSet(QString::fromUtf8("up.png")));
|
|
84 |
ui.moveItemDownButton->setIcon(createIconSet(QString::fromUtf8("down.png")));
|
|
85 |
ui.moveItemRightButton->setIcon(createIconSet(QString::fromUtf8("leveldown.png")));
|
|
86 |
ui.moveItemLeftButton->setIcon(createIconSet(QString::fromUtf8("levelup.png")));
|
|
87 |
|
|
88 |
ui.treeWidget->header()->setMovable(false);
|
|
89 |
|
|
90 |
connect(iconCache(), SIGNAL(reloaded()), this, SLOT(cacheReloaded()));
|
|
91 |
}
|
|
92 |
|
|
93 |
static AbstractItemEditor::PropertyDefinition treeHeaderPropList[] = {
|
|
94 |
{ Qt::DisplayPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "text" },
|
|
95 |
{ Qt::DecorationPropertyRole, 0, DesignerPropertyManager::designerIconTypeId, "icon" },
|
|
96 |
{ Qt::ToolTipPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "toolTip" },
|
|
97 |
{ Qt::StatusTipPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "statusTip" },
|
|
98 |
{ Qt::WhatsThisPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "whatsThis" },
|
|
99 |
{ Qt::FontRole, QVariant::Font, 0, "font" },
|
|
100 |
{ Qt::TextAlignmentRole, 0, DesignerPropertyManager::designerAlignmentTypeId, "textAlignment" },
|
|
101 |
{ Qt::BackgroundRole, QVariant::Color, 0, "background" },
|
|
102 |
{ Qt::ForegroundRole, QVariant::Brush, 0, "foreground" },
|
|
103 |
{ 0, 0, 0, 0 }
|
|
104 |
};
|
|
105 |
|
|
106 |
static AbstractItemEditor::PropertyDefinition treeItemColumnPropList[] = {
|
|
107 |
{ Qt::DisplayPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "text" },
|
|
108 |
{ Qt::DecorationPropertyRole, 0, DesignerPropertyManager::designerIconTypeId, "icon" },
|
|
109 |
{ Qt::ToolTipPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "toolTip" },
|
|
110 |
{ Qt::StatusTipPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "statusTip" },
|
|
111 |
{ Qt::WhatsThisPropertyRole, 0, DesignerPropertyManager::designerStringTypeId, "whatsThis" },
|
|
112 |
{ Qt::FontRole, QVariant::Font, 0, "font" },
|
|
113 |
{ Qt::TextAlignmentRole, 0, DesignerPropertyManager::designerAlignmentTypeId, "textAlignment" },
|
|
114 |
{ Qt::BackgroundRole, QVariant::Brush, 0, "background" },
|
|
115 |
{ Qt::ForegroundRole, QVariant::Brush, 0, "foreground" },
|
|
116 |
{ Qt::CheckStateRole, 0, QtVariantPropertyManager::enumTypeId, "checkState" },
|
|
117 |
{ 0, 0, 0, 0 }
|
|
118 |
};
|
|
119 |
|
|
120 |
static AbstractItemEditor::PropertyDefinition treeItemCommonPropList[] = {
|
|
121 |
{ ItemFlagsShadowRole, 0, QtVariantPropertyManager::flagTypeId, "flags" },
|
|
122 |
{ 0, 0, 0, 0 }
|
|
123 |
};
|
|
124 |
|
|
125 |
QtVariantProperty *TreeWidgetEditor::setupPropertyGroup(const QString &title, PropertyDefinition *propDefs)
|
|
126 |
{
|
|
127 |
setupProperties(propDefs);
|
|
128 |
QtVariantProperty *groupProp = m_propertyManager->addProperty(QtVariantPropertyManager::groupTypeId(), title);
|
|
129 |
foreach (QtVariantProperty *prop, m_rootProperties)
|
|
130 |
groupProp->addSubProperty(prop);
|
|
131 |
m_rootProperties.clear();
|
|
132 |
return groupProp;
|
|
133 |
}
|
|
134 |
|
|
135 |
TreeWidgetContents TreeWidgetEditor::fillContentsFromTreeWidget(QTreeWidget *treeWidget)
|
|
136 |
{
|
|
137 |
TreeWidgetContents treeCont;
|
|
138 |
treeCont.fromTreeWidget(treeWidget, false);
|
|
139 |
treeCont.applyToTreeWidget(ui.treeWidget, iconCache(), true);
|
|
140 |
|
|
141 |
treeCont.m_headerItem.applyToListWidget(m_columnEditor->listWidget(), iconCache(), true);
|
|
142 |
m_columnEditor->setupEditor(treeWidget, treeHeaderPropList);
|
|
143 |
|
|
144 |
QList<QtVariantProperty*> rootProperties;
|
|
145 |
rootProperties.append(setupPropertyGroup(tr("Per column properties"), treeItemColumnPropList));
|
|
146 |
rootProperties.append(setupPropertyGroup(tr("Common properties"), treeItemCommonPropList));
|
|
147 |
m_rootProperties = rootProperties;
|
|
148 |
m_propertyBrowser->setPropertiesWithoutValueMarked(true);
|
|
149 |
m_propertyBrowser->setRootIsDecorated(false);
|
|
150 |
setupObject(treeWidget);
|
|
151 |
|
|
152 |
if (ui.treeWidget->topLevelItemCount() > 0)
|
|
153 |
ui.treeWidget->setCurrentItem(ui.treeWidget->topLevelItem(0));
|
|
154 |
|
|
155 |
updateEditor();
|
|
156 |
|
|
157 |
return treeCont;
|
|
158 |
}
|
|
159 |
|
|
160 |
TreeWidgetContents TreeWidgetEditor::contents() const
|
|
161 |
{
|
|
162 |
TreeWidgetContents retVal;
|
|
163 |
retVal.fromTreeWidget(ui.treeWidget, true);
|
|
164 |
return retVal;
|
|
165 |
}
|
|
166 |
|
|
167 |
void TreeWidgetEditor::setItemData(int role, const QVariant &v)
|
|
168 |
{
|
|
169 |
const int col = (role == ItemFlagsShadowRole) ? 0 : ui.treeWidget->currentColumn();
|
|
170 |
QVariant newValue = v;
|
|
171 |
BoolBlocker block(m_updatingBrowser);
|
|
172 |
if (role == Qt::FontRole && newValue.type() == QVariant::Font) {
|
|
173 |
QFont oldFont = ui.treeWidget->font();
|
|
174 |
QFont newFont = qVariantValue<QFont>(newValue).resolve(oldFont);
|
|
175 |
newValue = qVariantFromValue(newFont);
|
|
176 |
ui.treeWidget->currentItem()->setData(col, role, QVariant()); // force the right font with the current resolve mask is set (item view bug)
|
|
177 |
}
|
|
178 |
ui.treeWidget->currentItem()->setData(col, role, newValue);
|
|
179 |
}
|
|
180 |
|
|
181 |
QVariant TreeWidgetEditor::getItemData(int role) const
|
|
182 |
{
|
|
183 |
const int col = (role == ItemFlagsShadowRole) ? 0 : ui.treeWidget->currentColumn();
|
|
184 |
return ui.treeWidget->currentItem()->data(col, role);
|
|
185 |
}
|
|
186 |
|
|
187 |
void TreeWidgetEditor::on_newItemButton_clicked()
|
|
188 |
{
|
|
189 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
190 |
QTreeWidgetItem *newItem = 0;
|
|
191 |
ui.treeWidget->blockSignals(true);
|
|
192 |
if (curItem) {
|
|
193 |
if (curItem->parent())
|
|
194 |
newItem = new QTreeWidgetItem(curItem->parent(), curItem);
|
|
195 |
else
|
|
196 |
newItem = new QTreeWidgetItem(ui.treeWidget, curItem);
|
|
197 |
} else
|
|
198 |
newItem = new QTreeWidgetItem(ui.treeWidget);
|
|
199 |
const QString newItemText = tr("New Item");
|
|
200 |
newItem->setText(0, newItemText);
|
|
201 |
newItem->setData(0, Qt::DisplayPropertyRole, qVariantFromValue(PropertySheetStringValue(newItemText)));
|
|
202 |
newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
|
|
203 |
ui.treeWidget->blockSignals(false);
|
|
204 |
|
|
205 |
ui.treeWidget->setCurrentItem(newItem, qMax(ui.treeWidget->currentColumn(), 0));
|
|
206 |
updateEditor();
|
|
207 |
ui.treeWidget->editItem(newItem, ui.treeWidget->currentColumn());
|
|
208 |
}
|
|
209 |
|
|
210 |
void TreeWidgetEditor::on_newSubItemButton_clicked()
|
|
211 |
{
|
|
212 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
213 |
if (!curItem)
|
|
214 |
return;
|
|
215 |
|
|
216 |
ui.treeWidget->blockSignals(true);
|
|
217 |
QTreeWidgetItem *newItem = new QTreeWidgetItem(curItem);
|
|
218 |
const QString newItemText = tr("New Subitem");
|
|
219 |
newItem->setText(0, newItemText);
|
|
220 |
newItem->setData(0, Qt::DisplayPropertyRole, qVariantFromValue(PropertySheetStringValue(newItemText)));
|
|
221 |
newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
|
|
222 |
ui.treeWidget->blockSignals(false);
|
|
223 |
|
|
224 |
ui.treeWidget->setCurrentItem(newItem, ui.treeWidget->currentColumn());
|
|
225 |
updateEditor();
|
|
226 |
ui.treeWidget->editItem(newItem, ui.treeWidget->currentColumn());
|
|
227 |
}
|
|
228 |
|
|
229 |
void TreeWidgetEditor::on_deleteItemButton_clicked()
|
|
230 |
{
|
|
231 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
232 |
if (!curItem)
|
|
233 |
return;
|
|
234 |
|
|
235 |
QTreeWidgetItem *nextCurrent = 0;
|
|
236 |
if (curItem->parent()) {
|
|
237 |
int idx = curItem->parent()->indexOfChild(curItem);
|
|
238 |
if (idx == curItem->parent()->childCount() - 1)
|
|
239 |
idx--;
|
|
240 |
else
|
|
241 |
idx++;
|
|
242 |
if (idx < 0)
|
|
243 |
nextCurrent = curItem->parent();
|
|
244 |
else
|
|
245 |
nextCurrent = curItem->parent()->child(idx);
|
|
246 |
} else {
|
|
247 |
int idx = ui.treeWidget->indexOfTopLevelItem(curItem);
|
|
248 |
if (idx == ui.treeWidget->topLevelItemCount() - 1)
|
|
249 |
idx--;
|
|
250 |
else
|
|
251 |
idx++;
|
|
252 |
if (idx >= 0)
|
|
253 |
nextCurrent = ui.treeWidget->topLevelItem(idx);
|
|
254 |
}
|
|
255 |
closeEditors();
|
|
256 |
ui.treeWidget->blockSignals(true);
|
|
257 |
delete curItem;
|
|
258 |
ui.treeWidget->blockSignals(false);
|
|
259 |
|
|
260 |
if (nextCurrent)
|
|
261 |
ui.treeWidget->setCurrentItem(nextCurrent, ui.treeWidget->currentColumn());
|
|
262 |
updateEditor();
|
|
263 |
}
|
|
264 |
|
|
265 |
void TreeWidgetEditor::on_moveItemUpButton_clicked()
|
|
266 |
{
|
|
267 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
268 |
if (!curItem)
|
|
269 |
return;
|
|
270 |
|
|
271 |
int idx;
|
|
272 |
if (curItem->parent())
|
|
273 |
idx = curItem->parent()->indexOfChild(curItem);
|
|
274 |
else
|
|
275 |
idx = ui.treeWidget->indexOfTopLevelItem(curItem);
|
|
276 |
if (idx == 0)
|
|
277 |
return;
|
|
278 |
|
|
279 |
QTreeWidgetItem *takenItem;
|
|
280 |
ui.treeWidget->blockSignals(true);
|
|
281 |
if (curItem->parent()) {
|
|
282 |
QTreeWidgetItem *parentItem = curItem->parent();
|
|
283 |
takenItem = parentItem->takeChild(idx);
|
|
284 |
parentItem->insertChild(idx - 1, takenItem);
|
|
285 |
} else {
|
|
286 |
takenItem = ui.treeWidget->takeTopLevelItem(idx);
|
|
287 |
ui.treeWidget->insertTopLevelItem(idx - 1, takenItem);
|
|
288 |
}
|
|
289 |
ui.treeWidget->blockSignals(false);
|
|
290 |
|
|
291 |
ui.treeWidget->setCurrentItem(takenItem, ui.treeWidget->currentColumn());
|
|
292 |
updateEditor();
|
|
293 |
}
|
|
294 |
|
|
295 |
void TreeWidgetEditor::on_moveItemDownButton_clicked()
|
|
296 |
{
|
|
297 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
298 |
if (!curItem)
|
|
299 |
return;
|
|
300 |
|
|
301 |
int idx, idxCount;
|
|
302 |
if (curItem->parent()) {
|
|
303 |
idx = curItem->parent()->indexOfChild(curItem);
|
|
304 |
idxCount = curItem->parent()->childCount();
|
|
305 |
} else {
|
|
306 |
idx = ui.treeWidget->indexOfTopLevelItem(curItem);
|
|
307 |
idxCount = ui.treeWidget->topLevelItemCount();
|
|
308 |
}
|
|
309 |
if (idx == idxCount - 1)
|
|
310 |
return;
|
|
311 |
|
|
312 |
QTreeWidgetItem *takenItem;
|
|
313 |
ui.treeWidget->blockSignals(true);
|
|
314 |
if (curItem->parent()) {
|
|
315 |
QTreeWidgetItem *parentItem = curItem->parent();
|
|
316 |
takenItem = parentItem->takeChild(idx);
|
|
317 |
parentItem->insertChild(idx + 1, takenItem);
|
|
318 |
} else {
|
|
319 |
takenItem = ui.treeWidget->takeTopLevelItem(idx);
|
|
320 |
ui.treeWidget->insertTopLevelItem(idx + 1, takenItem);
|
|
321 |
}
|
|
322 |
ui.treeWidget->blockSignals(false);
|
|
323 |
|
|
324 |
ui.treeWidget->setCurrentItem(takenItem, ui.treeWidget->currentColumn());
|
|
325 |
updateEditor();
|
|
326 |
}
|
|
327 |
|
|
328 |
void TreeWidgetEditor::on_moveItemLeftButton_clicked()
|
|
329 |
{
|
|
330 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
331 |
if (!curItem)
|
|
332 |
return;
|
|
333 |
|
|
334 |
QTreeWidgetItem *parentItem = curItem->parent();
|
|
335 |
if (!parentItem)
|
|
336 |
return;
|
|
337 |
|
|
338 |
ui.treeWidget->blockSignals(true);
|
|
339 |
QTreeWidgetItem *takenItem = parentItem->takeChild(parentItem->indexOfChild(curItem));
|
|
340 |
if (parentItem->parent()) {
|
|
341 |
int idx = parentItem->parent()->indexOfChild(parentItem);
|
|
342 |
parentItem->parent()->insertChild(idx, takenItem);
|
|
343 |
} else {
|
|
344 |
int idx = ui.treeWidget->indexOfTopLevelItem(parentItem);
|
|
345 |
ui.treeWidget->insertTopLevelItem(idx, takenItem);
|
|
346 |
}
|
|
347 |
ui.treeWidget->blockSignals(false);
|
|
348 |
|
|
349 |
ui.treeWidget->setCurrentItem(takenItem, ui.treeWidget->currentColumn());
|
|
350 |
updateEditor();
|
|
351 |
}
|
|
352 |
|
|
353 |
void TreeWidgetEditor::on_moveItemRightButton_clicked()
|
|
354 |
{
|
|
355 |
QTreeWidgetItem *curItem = ui.treeWidget->currentItem();
|
|
356 |
if (!curItem)
|
|
357 |
return;
|
|
358 |
|
|
359 |
int idx, idxCount;
|
|
360 |
if (curItem->parent()) {
|
|
361 |
idx = curItem->parent()->indexOfChild(curItem);
|
|
362 |
idxCount = curItem->parent()->childCount();
|
|
363 |
} else {
|
|
364 |
idx = ui.treeWidget->indexOfTopLevelItem(curItem);
|
|
365 |
idxCount = ui.treeWidget->topLevelItemCount();
|
|
366 |
}
|
|
367 |
if (idx == idxCount - 1)
|
|
368 |
return;
|
|
369 |
|
|
370 |
QTreeWidgetItem *takenItem;
|
|
371 |
ui.treeWidget->blockSignals(true);
|
|
372 |
if (curItem->parent()) {
|
|
373 |
QTreeWidgetItem *parentItem = curItem->parent()->child(idx + 1);
|
|
374 |
takenItem = curItem->parent()->takeChild(idx);
|
|
375 |
parentItem->insertChild(0, takenItem);
|
|
376 |
} else {
|
|
377 |
QTreeWidgetItem *parentItem = ui.treeWidget->topLevelItem(idx + 1);
|
|
378 |
takenItem = ui.treeWidget->takeTopLevelItem(idx);
|
|
379 |
parentItem->insertChild(0, takenItem);
|
|
380 |
}
|
|
381 |
ui.treeWidget->blockSignals(false);
|
|
382 |
|
|
383 |
ui.treeWidget->setCurrentItem(takenItem, ui.treeWidget->currentColumn());
|
|
384 |
updateEditor();
|
|
385 |
}
|
|
386 |
|
|
387 |
void TreeWidgetEditor::togglePropertyBrowser()
|
|
388 |
{
|
|
389 |
// Always hide in case parent widget is not visible -> on startup
|
|
390 |
const bool isVisible =
|
|
391 |
!this->isVisible() ? true : m_propertyBrowser->isVisible();
|
|
392 |
if (isVisible)
|
|
393 |
ui.showPropertiesButton->setText(tr("Properties &<<"));
|
|
394 |
else
|
|
395 |
ui.showPropertiesButton->setText(tr("Properties &>>"));
|
|
396 |
|
|
397 |
m_propertyBrowser->setVisible(!isVisible);
|
|
398 |
}
|
|
399 |
|
|
400 |
void TreeWidgetEditor::on_treeWidget_currentItemChanged()
|
|
401 |
{
|
|
402 |
m_columnEditor->setCurrentIndex(ui.treeWidget->currentColumn());
|
|
403 |
updateEditor();
|
|
404 |
}
|
|
405 |
|
|
406 |
void TreeWidgetEditor::on_treeWidget_itemChanged(QTreeWidgetItem *item, int column)
|
|
407 |
{
|
|
408 |
if (m_updatingBrowser)
|
|
409 |
return;
|
|
410 |
|
|
411 |
PropertySheetStringValue val = qVariantValue<PropertySheetStringValue>(item->data(column, Qt::DisplayPropertyRole));
|
|
412 |
val.setValue(item->text(column));
|
|
413 |
BoolBlocker block(m_updatingBrowser);
|
|
414 |
item->setData(column, Qt::DisplayPropertyRole, qVariantFromValue(val));
|
|
415 |
|
|
416 |
updateBrowser();
|
|
417 |
}
|
|
418 |
|
|
419 |
void TreeWidgetEditor::on_columnEditor_indexChanged(int idx)
|
|
420 |
{
|
|
421 |
if (QTreeWidgetItem *item = ui.treeWidget->currentItem())
|
|
422 |
ui.treeWidget->setCurrentItem(item, idx);
|
|
423 |
}
|
|
424 |
|
|
425 |
void TreeWidgetEditor::on_columnEditor_itemChanged(int idx, int role, const QVariant &v)
|
|
426 |
{
|
|
427 |
if (role == Qt::DisplayPropertyRole)
|
|
428 |
ui.treeWidget->headerItem()->setData(idx, Qt::EditRole, qVariantValue<PropertySheetStringValue>(v).value());
|
|
429 |
ui.treeWidget->headerItem()->setData(idx, role, v);
|
|
430 |
}
|
|
431 |
|
|
432 |
void TreeWidgetEditor::updateEditor()
|
|
433 |
{
|
|
434 |
QTreeWidgetItem *current = ui.treeWidget->currentItem();
|
|
435 |
|
|
436 |
bool itemsEnabled = false;
|
|
437 |
bool currentItemEnabled = false;
|
|
438 |
bool moveItemUpEnabled = false;
|
|
439 |
bool moveItemDownEnabled = false;
|
|
440 |
bool moveItemRightEnabled = false;
|
|
441 |
bool moveItemLeftEnabled = false;
|
|
442 |
|
|
443 |
if (ui.treeWidget->columnCount() > 0) {
|
|
444 |
itemsEnabled = true;
|
|
445 |
if (current) {
|
|
446 |
int idx;
|
|
447 |
int idxCount;
|
|
448 |
currentItemEnabled = true;
|
|
449 |
if (current->parent()) {
|
|
450 |
moveItemLeftEnabled = true;
|
|
451 |
idx = current->parent()->indexOfChild(current);
|
|
452 |
idxCount = current->parent()->childCount();
|
|
453 |
} else {
|
|
454 |
idx = ui.treeWidget->indexOfTopLevelItem(current);
|
|
455 |
idxCount = ui.treeWidget->topLevelItemCount();
|
|
456 |
}
|
|
457 |
if (idx > 0)
|
|
458 |
moveItemUpEnabled = true;
|
|
459 |
if (idx < idxCount - 1) {
|
|
460 |
moveItemDownEnabled = true;
|
|
461 |
moveItemRightEnabled = true;
|
|
462 |
}
|
|
463 |
}
|
|
464 |
}
|
|
465 |
ui.tabWidget->setTabEnabled(1, itemsEnabled);
|
|
466 |
ui.newSubItemButton->setEnabled(currentItemEnabled);
|
|
467 |
ui.deleteItemButton->setEnabled(currentItemEnabled);
|
|
468 |
|
|
469 |
ui.moveItemUpButton->setEnabled(moveItemUpEnabled);
|
|
470 |
ui.moveItemDownButton->setEnabled(moveItemDownEnabled);
|
|
471 |
ui.moveItemRightButton->setEnabled(moveItemRightEnabled);
|
|
472 |
ui.moveItemLeftButton->setEnabled(moveItemLeftEnabled);
|
|
473 |
|
|
474 |
if (current)
|
|
475 |
updateBrowser();
|
|
476 |
else
|
|
477 |
m_propertyBrowser->clear();
|
|
478 |
}
|
|
479 |
|
|
480 |
void TreeWidgetEditor::moveColumnItems(const PropertyDefinition *propList,
|
|
481 |
QTreeWidgetItem *item, int fromColumn, int toColumn, int step)
|
|
482 |
{
|
|
483 |
BoolBlocker block(m_updatingBrowser);
|
|
484 |
|
|
485 |
QList<QVariant> saveCol;
|
|
486 |
for (int j = 0; propList[j].name; j++)
|
|
487 |
saveCol.append(item->data(toColumn, propList[j].role));
|
|
488 |
QVariant editVariant = item->data(toColumn, Qt::EditRole);
|
|
489 |
QVariant toolTipVariant = item->data(toColumn, Qt::ToolTipRole);
|
|
490 |
QVariant statusTipVariant = item->data(toColumn, Qt::StatusTipRole);
|
|
491 |
QVariant whatsThisVariant = item->data(toColumn, Qt::WhatsThisRole);
|
|
492 |
QVariant decorationVariant = item->data(toColumn, Qt::DecorationRole);
|
|
493 |
for (int i = toColumn; i != fromColumn; i += step) {
|
|
494 |
for (int j = 0; propList[j].name; j++)
|
|
495 |
item->setData(i, propList[j].role, item->data(i + step, propList[j].role));
|
|
496 |
item->setData(i, Qt::EditRole, item->data(i + step, Qt::EditRole));
|
|
497 |
item->setData(i, Qt::ToolTipRole, item->data(i + step, Qt::ToolTipRole));
|
|
498 |
item->setData(i, Qt::StatusTipRole, item->data(i + step, Qt::StatusTipRole));
|
|
499 |
item->setData(i, Qt::WhatsThisRole, item->data(i + step, Qt::WhatsThisRole));
|
|
500 |
item->setData(i, Qt::DecorationRole, item->data(i + step, Qt::DecorationRole));
|
|
501 |
}
|
|
502 |
for (int j = 0; propList[j].name; j++)
|
|
503 |
item->setData(fromColumn, propList[j].role, saveCol[j]);
|
|
504 |
item->setData(fromColumn, Qt::EditRole, editVariant);
|
|
505 |
item->setData(fromColumn, Qt::ToolTipRole, toolTipVariant);
|
|
506 |
item->setData(fromColumn, Qt::StatusTipRole, statusTipVariant);
|
|
507 |
item->setData(fromColumn, Qt::WhatsThisRole, whatsThisVariant);
|
|
508 |
item->setData(fromColumn, Qt::DecorationRole, decorationVariant);
|
|
509 |
}
|
|
510 |
|
|
511 |
void TreeWidgetEditor::moveColumns(int fromColumn, int toColumn, int step)
|
|
512 |
{
|
|
513 |
ui.treeWidget->blockSignals(true);
|
|
514 |
|
|
515 |
moveColumnItems(treeHeaderPropList, ui.treeWidget->headerItem(), fromColumn, toColumn, step);
|
|
516 |
|
|
517 |
QQueue<QTreeWidgetItem *> pendingQueue;
|
|
518 |
for (int i = 0; i < ui.treeWidget->topLevelItemCount(); i++)
|
|
519 |
pendingQueue.enqueue(ui.treeWidget->topLevelItem(i));
|
|
520 |
|
|
521 |
while (!pendingQueue.isEmpty()) {
|
|
522 |
QTreeWidgetItem *item = pendingQueue.dequeue();
|
|
523 |
for (int i = 0; i < item->childCount(); i++)
|
|
524 |
pendingQueue.enqueue(item->child(i));
|
|
525 |
|
|
526 |
moveColumnItems(treeItemColumnPropList, item, fromColumn, toColumn, step);
|
|
527 |
}
|
|
528 |
|
|
529 |
ui.treeWidget->blockSignals(false);
|
|
530 |
}
|
|
531 |
|
|
532 |
void TreeWidgetEditor::moveColumnsLeft(int fromColumn, int toColumn)
|
|
533 |
{
|
|
534 |
if (fromColumn >= toColumn)
|
|
535 |
return;
|
|
536 |
|
|
537 |
moveColumns(fromColumn, toColumn, -1);
|
|
538 |
}
|
|
539 |
|
|
540 |
void TreeWidgetEditor::moveColumnsRight(int fromColumn, int toColumn)
|
|
541 |
{
|
|
542 |
if (fromColumn >= toColumn)
|
|
543 |
return;
|
|
544 |
|
|
545 |
moveColumns(toColumn, fromColumn, 1);
|
|
546 |
}
|
|
547 |
|
|
548 |
void TreeWidgetEditor::on_columnEditor_itemInserted(int idx)
|
|
549 |
{
|
|
550 |
int columnCount = ui.treeWidget->columnCount();
|
|
551 |
ui.treeWidget->setColumnCount(columnCount + 1);
|
|
552 |
ui.treeWidget->headerItem()->setText(columnCount, m_columnEditor->newItemText());
|
|
553 |
moveColumnsLeft(idx, columnCount);
|
|
554 |
|
|
555 |
updateEditor();
|
|
556 |
}
|
|
557 |
|
|
558 |
void TreeWidgetEditor::on_columnEditor_itemDeleted(int idx)
|
|
559 |
{
|
|
560 |
closeEditors();
|
|
561 |
|
|
562 |
int columnCount = ui.treeWidget->columnCount() - 1;
|
|
563 |
if (!columnCount)
|
|
564 |
ui.treeWidget->clear();
|
|
565 |
else
|
|
566 |
moveColumnsRight(idx, columnCount);
|
|
567 |
ui.treeWidget->setColumnCount(columnCount);
|
|
568 |
|
|
569 |
updateEditor();
|
|
570 |
}
|
|
571 |
|
|
572 |
void TreeWidgetEditor::on_columnEditor_itemMovedUp(int idx)
|
|
573 |
{
|
|
574 |
moveColumnsRight(idx - 1, idx);
|
|
575 |
|
|
576 |
ui.treeWidget->setCurrentItem(ui.treeWidget->currentItem(), idx - 1);
|
|
577 |
updateEditor();
|
|
578 |
}
|
|
579 |
|
|
580 |
void TreeWidgetEditor::on_columnEditor_itemMovedDown(int idx)
|
|
581 |
{
|
|
582 |
moveColumnsLeft(idx, idx + 1);
|
|
583 |
|
|
584 |
ui.treeWidget->setCurrentItem(ui.treeWidget->currentItem(), idx + 1);
|
|
585 |
updateEditor();
|
|
586 |
}
|
|
587 |
|
|
588 |
void TreeWidgetEditor::closeEditors()
|
|
589 |
{
|
|
590 |
if (QTreeWidgetItem *cur = ui.treeWidget->currentItem() ) {
|
|
591 |
const int numCols = cur->columnCount ();
|
|
592 |
for (int i = 0; i < numCols; i++)
|
|
593 |
ui.treeWidget->closePersistentEditor (cur, i);
|
|
594 |
}
|
|
595 |
}
|
|
596 |
|
|
597 |
void TreeWidgetEditor::cacheReloaded()
|
|
598 |
{
|
|
599 |
reloadIconResources(iconCache(), ui.treeWidget);
|
|
600 |
}
|
|
601 |
|
|
602 |
}
|
|
603 |
QT_END_NAMESPACE
|