source-tree refactoring
This commit is contained in:
60
src/widgets/treewidget_p.h
Normal file
60
src/widgets/treewidget_p.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
QGL SceneTree
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TREEWIDGET_H
|
||||
#define TREEWIDGET_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDropEvent>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTimer>
|
||||
#include <QTreeWidget>
|
||||
|
||||
class InternalMoveTreeWidget: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {}
|
||||
|
||||
protected:
|
||||
virtual void dropEvent(QDropEvent * e) {
|
||||
QList<QTreeWidgetItem *> sil = selectedItems();
|
||||
if (sil.isEmpty()) return;
|
||||
QTreeWidget::dropEvent(e);
|
||||
foreach(QTreeWidgetItem * ti, sil) {
|
||||
QTreeWidgetItem * ti_p = ti->parent();
|
||||
if (!ti_p) ti_p = invisibleRootItem();
|
||||
int ti_ppos = ti_p->indexOfChild(ti);
|
||||
emit itemMoved(ti, ti_p, ti_ppos);
|
||||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index);
|
||||
};
|
||||
|
||||
|
||||
class NoEditDelegate: public QStyledItemDelegate {
|
||||
public:
|
||||
NoEditDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
|
||||
virtual QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TREEWIDGET_H
|
||||
Reference in New Issue
Block a user