source: s10k/CommonLibs/CustomTreeWidget/customtreewidget.cpp@ 1077

Last change on this file since 1077 was 1073, checked in by s10k, 7 years ago

added XML Tools latest version (2.0d) and s10k's common libs

File size: 2.3 KB
Line 
1/**
2 * Copyright (C) 2017
3 *
4 * This library is distributed under the MIT License. See notice at the end
5 * of this file.
6 *
7 * All code credit go to "Igor" from stackoverflow:
8 * http://stackoverflow.com/a/21285323
9 */
10
11#include "customtreewidget.h"
12
13CustomTreeWidget::CustomTreeWidget(QWidget *parent)
14 : QTreeWidget(parent)
15{
16 setSelectionMode(QAbstractItemView::SingleSelection);
17 setDragEnabled(true);
18 viewport()->setAcceptDrops(true);
19 setDropIndicatorShown(true);
20 setDragDropMode(QAbstractItemView::InternalMove);
21}
22
23void CustomTreeWidget::dropEvent(QDropEvent * event)
24{
25 QModelIndex droppedIndex = indexAt( event->pos() );
26
27 if( !droppedIndex.isValid() )
28 return;
29
30 QTreeWidget::dropEvent(event);
31
32 QTreeWidgetItem *itemMoved = itemAt(event->pos());
33
34 // If the item was dropped in top level item (project), it is moved to the bottom
35 if(itemMoved == this->topLevelItem(0)){
36 itemMoved = this->topLevelItem(0)->child(this->topLevelItem(0)->childCount()-1);
37 }
38
39 // Set the item moved as currentItem
40 setCurrentItem(itemMoved);
41
42 // Signal that the item has changed
43 itemChanged(itemAt(event->pos()),0);
44}
45
46/**
47 * Copyright (c) 2017
48 *
49 * Permission is hereby granted, free of charge, to any person
50 * obtaining a copy of this software and associated documentation
51 * files (the "Software"), to deal in the Software without
52 * restriction, including without limitation the rights to use,
53 * copy, modify, merge, publish, distribute, sublicense, and/or sell
54 * copies of the Software, and to permit persons to whom the
55 * Software is furnished to do so, subject to the following
56 * conditions:
57 *
58 * The above copyright notice and this permission notice shall be
59 * included in all copies or substantial portions of the Software.
60 *
61 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
62 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
63 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
64 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
65 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
66 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
67 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
68 * OTHER DEALINGS IN THE SOFTWARE.
69 */
Note: See TracBrowser for help on using the repository browser.