1
/***************************************************************************
2
kstviewmanger_i.cpp - Part of KST
5
copyright : (C) 2003 The University of British Columbia
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
19
// include files for Qt
20
#include <qptrstack.h>
22
// include files for KDE
24
#include <klistview.h>
25
#include <kmessagebox.h>
26
#include <kstandarddirs.h>
28
// application specific includes
29
#include "kstdatacollection.h"
30
#include "kstobject.h"
31
#include "kstviewmanager_i.h"
33
#include "kstviewwindow.h"
36
#define RTTI_OBJ_WINDOW 4301
37
#define RTTI_OBJ_2D_PLOT 4302
38
#define RTTI_OBJ_PLOT_GROUP 4303
39
#define RTTI_OBJ_VIEW_OBJECT 4304
42
KstViewObjectItem::KstViewObjectItem(QListView *parent, KstTopLevelViewPtr x, KstViewManagerI *vm, int localUseCount)
43
: QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_WINDOW), _name(x->tagName()), _vm(vm) {
46
setText(0, x->name());
47
setText(1, x->type());
48
update(KstViewObjectPtr(x), true, localUseCount);
52
KstViewObjectItem::KstViewObjectItem(QListViewItem *parent, KstViewObjectPtr x, KstViewManagerI *vm, int localUseCount)
53
: QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_VIEW_OBJECT), _name(x->tagName()), _vm(vm) {
56
setText(0, x->tagName());
57
setText(1, x->type());
58
update(KstViewObjectPtr(x), true, localUseCount);
61
KstViewObjectItem::~KstViewObjectItem() {
64
void KstViewObjectItem::update(KstViewObjectPtr x, bool recursive, int localUseCount) {
65
QPtrStack<QListViewItem> trash;
67
// garbage collect first
68
for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
70
KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
71
if (i->rtti() == RTTI_OBJ_VIEW_OBJECT) {
72
for (KstViewObjectList::ConstIterator obj = x->children().begin(); obj != x->children().end(); ++obj) {
73
if (x->tagName() == oi->tagName()) {
84
trash.setAutoDelete(true);
85
_vm->blockSignals(true);
87
_vm->blockSignals(false);
89
for (KstViewObjectList::ConstIterator obj = x->children().begin(); obj != x->children().end(); ++obj) {
91
for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
92
KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
93
if (oi->tagName() == (*obj)->tagName()) {
100
KstViewObjectItem *i = new KstViewObjectItem(this, *obj, _vm);
106
void KstViewObjectItem::updateButtons() {
107
_vm->Edit->setEnabled(_rtti != RTTI_OBJ_WINDOW);
108
_vm->Delete->setEnabled(true);
112
KstViewManagerI::KstViewManagerI(KstDoc *in_doc, QWidget* parent, const char* name, bool modal, WFlags fl)
113
: KstViewManager(parent, name, modal, fl) {
116
connect(Close, SIGNAL(clicked()), this, SLOT(reject()));
117
connect(Edit, SIGNAL(clicked()), this, SLOT(edit_I()));
118
connect(Delete, SIGNAL(clicked()), this, SLOT(delete_I()));
119
connect(ViewView, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(edit_I()));
120
connect(ViewView, SIGNAL(currentChanged(QListViewItem *)), this, SLOT(currentChanged(QListViewItem *)));
121
connect(ViewView, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(currentChanged(QListViewItem *)));
122
connect(ViewView, SIGNAL(contextMenuRequested(QListViewItem*, const QPoint&, int)), this, SLOT(contextMenu(QListViewItem*, const QPoint&, int)));
126
KstViewManagerI::~KstViewManagerI() {
130
void KstViewManagerI::show_I() {
137
void KstViewManagerI::updateContents() {
142
void KstViewManagerI::update() {
143
KstApp *app = KstApp::inst();
149
QListViewItem *currentItem = ViewView->selectedItem();
150
QPtrStack<QListViewItem> trash;
151
KMdiIterator<KMdiChildView*> *it = app->createIterator();
153
// garbage collect first
154
for (QListViewItem *i = ViewView->firstChild(); i; i = i->nextSibling()) {
156
KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
158
if (i->rtti() == RTTI_OBJ_WINDOW) {
159
while (it->currentItem()) {
160
KstViewWindow *win = dynamic_cast<KstViewWindow*>(it->currentItem());
162
KstTopLevelViewPtr view = win->view();
164
if (view->tagName() == oi->tagName()) {
177
trash.setAutoDelete(true);
178
ViewView->blockSignals(true);
180
ViewView->blockSignals(false);
183
while (it->currentItem()) {
184
KstViewWindow *win = dynamic_cast<KstViewWindow*>(it->currentItem());
186
KstTopLevelViewPtr view = win->view();
190
for (QListViewItem *i = ViewView->firstChild(); i; i = i->nextSibling()) {
191
KstViewObjectItem *oi = static_cast<KstViewObjectItem*>(i);
192
if (oi->rtti() == RTTI_OBJ_WINDOW && oi->tagName() == view->tagName()) {
193
oi->update(KstViewObjectPtr(view));
199
KstViewObjectItem *i = new KstViewObjectItem(ViewView, view, this);
206
for (QListViewItem *i = ViewView->firstChild(); i; i = i->nextSibling()) {
207
if (i == currentItem) {
208
ViewView->setCurrentItem(i);
209
ViewView->setSelected(i, true);
214
if (ViewView->selectedItem()) {
215
static_cast<KstViewObjectItem*>(ViewView->currentItem())->updateButtons();
217
Edit->setEnabled(false);
218
Delete->setEnabled(false);
221
app->deleteIterator(it);
225
void KstViewManagerI::edit_I() {
228
if (ViewView->selectedItems().count() > 0) {
229
qi = ViewView->selectedItems().at(0);
231
KMessageBox::sorry(this, i18n("An item must be selected to edit."));
237
void KstViewManagerI::delete_I() {
238
QListViewItem *qi = ViewView->selectedItems().at(0);
239
KstViewObjectItem *koi = static_cast<KstViewObjectItem*>(qi);
241
if (koi->removable()) {
249
// 100->499 reserved for plots
250
// 500->999 reserved for filters
252
void KstViewManagerI::contextMenu(QListViewItem *i, const QPoint& p, int col) {
259
KstViewObjectItem *koi = static_cast<KstViewObjectItem*>(i);
260
KPopupMenu *m = new KPopupMenu(this);
262
m->insertTitle(koi->text(0));
268
void KstViewManagerI::doUpdates() {
273
void KstViewManagerI::currentChanged(QListViewItem *i) {
275
KstViewObjectItem *koi = static_cast<KstViewObjectItem*>(i);
276
koi->updateButtons();
280
#include "kstviewmanager_i.moc"