-rw-r--r-- | noncore/apps/tableviewer/tableviewer.cpp | 8 | ||||
-rw-r--r-- | noncore/apps/tableviewer/ui/commonwidgets.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tableviewer/ui/tvbrowseview.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/tableviewer/ui/tvfilterview.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tableviewer/ui/tvlistview.cpp | 4 |
5 files changed, 10 insertions, 10 deletions
diff --git a/noncore/apps/tableviewer/tableviewer.cpp b/noncore/apps/tableviewer/tableviewer.cpp index f35dfcd..4c6d809 100644 --- a/noncore/apps/tableviewer/tableviewer.cpp +++ b/noncore/apps/tableviewer/tableviewer.cpp @@ -1,357 +1,357 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ /* local includes */ #include "tableviewer.h" #include "ui/tvbrowseview.h" #include "ui/tvfilterview.h" #include "ui/tvlistview.h" #include "ui/tveditview.h" #include "ui/tvkeyedit.h" #include "db/datacache.h" /* QPE includes */ #include <qpe/fileselector.h> #include <qpe/resource.h> #include <qpe/qpetoolbar.h> /* QTE includes */ #include <qmenubar.h> #include <qpopupmenu.h> #include <qapplication.h> #include <qwidgetstack.h> #include <qlayout.h> #include <qbuffer.h> /*! \class TableViewerWindow \brief The main window widget of the application This is the main widget of the table viewer application. It is the co-ordination point. */ /*! Constructs a new TableViewerWindow */ TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { setCaption(tr("Table Viewer")); /* Build data */ ds = new DBStore(); doc.setType("text/x-xml-tableviewer"); doc.setName("table"); dirty = FALSE; ts.current_column = 0; ts.kRep = ds->getKeys(); /* build menus */ menu = new QMenuBar(this, 0); QPopupMenu *file_menu = new QPopupMenu; file_menu->insertItem("New", this, SLOT(newDocument())); file_menu->insertItem("Open", this, SLOT(selectDocument())); file_menu->insertSeparator(); file_menu->insertItem("Properties"); /* later will want to set this up to clean up first via this, SLOT(quit) */ menu->insertItem("Document", file_menu); QPopupMenu *edit_menu = new QPopupMenu; edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot())); edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot())); edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot())); menu->insertItem("Edit", edit_menu); QPopupMenu *view_menu = new QPopupMenu; view_menu->insertItem("Browse View", this, SLOT(browseViewSlot())); view_menu->insertItem("List View", this, SLOT(listViewSlot())); menu->insertItem("View", view_menu); QVBoxLayout *main_layout = new QVBoxLayout; /* Build tool bar */ navigation = new QToolBar(this, "navigation"); QToolButton *newItemButton = new QToolButton( QIconSet(Resource::loadPixmap("new")), "New Item", QString::null, this, SLOT(newItemSlot()), navigation, "New Item"); QToolButton *editItemButton = new QToolButton( QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null, this, SLOT(editItemSlot()), navigation, "Edit Item"); QToolButton *deleteItemButton = new QToolButton( QIconSet(Resource::loadPixmap("trash")), "Delete Item", QString::null, this, SLOT(deleteItemSlot()), navigation, "Delete Item"); navigation->addSeparator(); QToolButton *firstItemButton = new QToolButton( QIconSet(Resource::loadPixmap("fastback")), "First Item", QString::null, this, SLOT(firstItem()), navigation, "First Item"); QToolButton *previousItemButton = new QToolButton( QIconSet(Resource::loadPixmap("back")), "Previous Item", QString::null, this, SLOT(previousItem()), navigation, "Previous Item"); QToolButton *nextItemButton = new QToolButton( QIconSet(Resource::loadPixmap("forward")), "Next Item", QString::null, this, SLOT(nextItem()), navigation, "Next Item"); QToolButton *lastItemButton = new QToolButton( QIconSet(Resource::loadPixmap("fastforward")), "Last Item", QString::null, this, SLOT(lastItem()), navigation, "Last Item"); navigation->addSeparator(); QToolButton *browseButton = new QToolButton( QIconSet(Resource::loadPixmap("day")), "View Single Item", QString::null, this, SLOT(browseViewSlot()), navigation, "View Single Item"); QToolButton *listButton = new QToolButton( QIconSet(Resource::loadPixmap("month")), "View Multiple Items", QString::null, this, SLOT(listViewSlot()), navigation, "View Multiple Items"); setToolBarsMovable(FALSE); setToolBarsMovable(FALSE); setToolBarsMovable(FALSE); /* Build widgets */ browseView = new TVBrowseView(&ts, this, 0); listView = new TVListView(&ts, this, 0); filterView = new TVFilterView(&ts, this, 0); fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer", this, "fileselector"); fileSelector->setNewVisible(FALSE); fileSelector->setCloseVisible(FALSE); cw = new QWidgetStack(this, 0); cw->addWidget(listView, ListState); cw->addWidget(browseView, BrowseState); cw->addWidget(filterView, FilterState); cw->addWidget(fileSelector, FileState); current_view = FileState; cw->raiseWidget(current_view); fileSelector->reread(); - connect(browseView, SIGNAL(searchOnKey(int, TVVariant)), - this, SLOT(searchOnKey(int, TVVariant))); + connect(browseView, SIGNAL(searchOnKey(int,TVVariant)), + this, SLOT(searchOnKey(int,TVVariant))); connect(browseView, SIGNAL(sortChanged(int)), this, SLOT(setPrimaryKey(int))); connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot())); - connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), - this, SLOT(openDocument(const DocLnk &))); + connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)), + this, SLOT(openDocument(const DocLnk&))); main_layout->addWidget(menu); main_layout->addWidget(cw); setCentralWidget(cw); } /*! Destroys the TableViewerWindow */ TableViewerWindow::~TableViewerWindow() { if(dirty) saveDocument(); } /*! Opens a file dialog and loads the file specified by the dialog */ void TableViewerWindow::selectDocument() { if(dirty) saveDocument(); current_view = FileState; cw->raiseWidget(current_view); fileSelector->reread(); } void TableViewerWindow::saveDocument() { if(!dirty) return; FileManager fm; QIODevice *dev = fm.saveFile(doc); if(!ds->saveSource(dev, doc.type())){ qWarning("Save unsuccessful"); return; } dev->close(); dirty = FALSE; } void TableViewerWindow::newDocument() { DocLnk nf; nf.setType("text/x-xml-tableviewer"); nf.setName("table"); delete ds; ds = new DBStore(); ts.current_column = 0; ts.kRep = ds->getKeys(); browseView->reset(); listView->reset(); filterView->reset(); doc = nf; dirty = FALSE; current_view = BrowseState; cw->raiseWidget(current_view); /* now set up for editing the keys */ ts.kRep->addKey("key", TVVariant::String); editKeysSlot(); } void TableViewerWindow::setDocument(const QString &f) { openDocument(DocLnk(f, TRUE)); } void TableViewerWindow::openDocument(const DocLnk &f) { if (!f.isValid()) return; FileManager fm; QIODevice *dev = fm.openFile(f); doc = f; if(ds->openSource(dev, doc.type())) { DataElem *d; browseView->reset(); listView->reset(); filterView->reset(); current_view = BrowseState; cw->raiseWidget(current_view); /* set up new table state and ensure sub widgets have a reference */ ts.current_column = 0; ts.kRep = ds->getKeys(); browseView->rebuildKeys(); listView->rebuildKeys(); filterView->rebuildKeys(); ds->first(); /* set up the list view */ listView->clearItems(); do { d = ds->getCurrentData(); if(d) listView->addItem(d); } while(ds->next()); /* Set up browse view, Will be based of structure of listView */ listView->first(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); listView->rebuildData(); QString scratch = "Table Viewer";/* later take from constant */ scratch += " - "; scratch += ds->getName(); setCaption(tr(scratch)); dirty = FALSE; } else { qWarning(tr("could not load Document")); } dev->close(); } /*! Moves to the first item of the current table */ void TableViewerWindow::firstItem() { listView->first(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Moves to the lat item of the current table */ void TableViewerWindow::lastItem() { listView->last(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Moves to the next item of the current table */ void TableViewerWindow::nextItem() { listView->next(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Moves to the previous item of the current table */ void TableViewerWindow::previousItem() { listView->previous(); ts.current_elem = listView->getCurrentData(); browseView->rebuildData(); } /*! Raises the List View. This is a mode change for the application. */ void TableViewerWindow::listViewSlot() { if(current_view == FilterState) applyFilter(); current_view = ListState; cw->raiseWidget(current_view); } void TableViewerWindow::applyFilter() { DataElem *d; listView->clearItems(); ds->first(); do { d = ds->getCurrentData(); if(d) if(filterView->passesFilter(d)) listView->addItem(d); diff --git a/noncore/apps/tableviewer/ui/commonwidgets.cpp b/noncore/apps/tableviewer/ui/commonwidgets.cpp index 4c47951..e82018c 100644 --- a/noncore/apps/tableviewer/ui/commonwidgets.cpp +++ b/noncore/apps/tableviewer/ui/commonwidgets.cpp @@ -1,210 +1,210 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qlineedit.h> #include <qlayout.h> #include <qlabel.h> #include <qcombobox.h> #include <qpe/datebookmonth.h> #include <qpopupmenu.h> #include <qspinbox.h> #include "commonwidgets.h" DateEdit::DateEdit( QWidget *parent, const char *name, WFlags f ) : QToolButton(parent, name) { QPopupMenu *m1 = new QPopupMenu(this); dateSelector = new DateBookMonth(m1, 0, TRUE); m1->insertItem(dateSelector); setPopup(m1); setPopupDelay(0); - connect(dateSelector, SIGNAL(dateClicked(int, int, int)), + connect(dateSelector, SIGNAL(dateClicked(int,int,int)), this, SLOT(subValueChanged())); setText(dateSelector->selectedDate().toString()); } DateEdit::~DateEdit() {} QDate DateEdit::date() const { return dateSelector->selectedDate(); } void DateEdit::setDate(QDate d) { dateSelector->setDate(d.year(), d.month(), d.day()); setText(d.toString()); } QSizePolicy DateEdit::sizePolicy() const { QSizePolicy sp; sp.setHorData(QToolButton::sizePolicy().horData()); sp.setVerData(QSizePolicy::Fixed); return sp; } void DateEdit::clear() { QDate today = QDate::currentDate(); dateSelector->setDate(today.year(), today.month(), today.day()); setText(today.toString()); } void DateEdit::subValueChanged() { QDate current = dateSelector->selectedDate(); setText(current.toString()); emit valueChanged(current); } TimeEdit::TimeEdit( QWidget *parent, const char *name, WFlags f ) : QWidget(parent, name, f) { QHBoxLayout *layout = new QHBoxLayout(this, 0); layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this)); hourKey->setWrapping(true); hourKey->setMinimumWidth(30); hourKey->setMaximumWidth(35); layout->addWidget(new QLabel(" : ", this)); layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this)); minuteKey->setWrapping(true); minuteKey->setMinimumWidth(30); minuteKey->setMaximumWidth(35); layout->addWidget(new QLabel(" : ", this)); layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0)); secondKey->setWrapping(true); secondKey->setMinimumWidth(30); secondKey->setMaximumWidth(35); layout->addWidget(ampm = new QComboBox(this)); ampm->insertItem("AM"); ampm->insertItem("PM"); layout->addStretch(-1); clear(); connect(secondKey, SIGNAL(valueChanged(const QString&)), this, SLOT(subValueChanged())); connect(minuteKey, SIGNAL(valueChanged(const QString&)), this, SLOT(subValueChanged())); connect(hourKey, SIGNAL(valueChanged(const QString&)), this, SLOT(subValueChanged())); connect(ampm, SIGNAL(activated(int)), this, SLOT(subValueChanged())); } TimeEdit::~TimeEdit() {} QTime TimeEdit::time() const { int s,m,h; s = secondKey->text().toInt(); m = minuteKey->text().toInt(); h = hourKey->text().toInt(); if(ampm->currentItem() == 1) { /* pm */ h = h + 12; } /* hour now ranges 1->24 */ if (h == 12) h = 0; if (h == 24) h = 12; if(QTime::isValid(h, m, s)) return QTime(h, m, s); return QTime(0, 0, 0); } void TimeEdit::setTime(QTime t) { int h = t.hour(); secondKey->setValue(t.second()); minuteKey->setValue(t.minute()); /* h 0..23 */ if (h > 11) { h -= 12; ampm->setCurrentItem(1); } else { ampm->setCurrentItem(0); } if (h == 0) h = 12; hourKey->setValue(h); } QSizePolicy TimeEdit::sizePolicy() const { QSizePolicy sp; sp.setHorData(QSizePolicy::Preferred); sp.setVerData(QSizePolicy::Fixed); return sp; } void TimeEdit::clear() { secondKey->setValue(0); minuteKey->setValue(0); hourKey->setValue(12); ampm->setCurrentItem(0); } void TimeEdit::subValueChanged() { emit valueChanged(time()); } IntEdit::IntEdit( QWidget *parent, const char *name, WFlags f ) : QSpinBox(INT_MIN, INT_MAX, 1, parent, name) { setValue(0); } IntEdit::~IntEdit() {} int IntEdit::value() { return cleanText().toInt(); } void IntEdit::clear() { setValue(0); } diff --git a/noncore/apps/tableviewer/ui/tvbrowseview.cpp b/noncore/apps/tableviewer/ui/tvbrowseview.cpp index 22bac55..8a65ed1 100644 --- a/noncore/apps/tableviewer/ui/tvbrowseview.cpp +++ b/noncore/apps/tableviewer/ui/tvbrowseview.cpp @@ -1,123 +1,123 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "tvbrowseview.h" #include "browsekeyentry.h" #include <qtoolbutton.h> #include <qtextview.h> #include <qtextbrowser.h> #include <qlayout.h> #include "../xmlencodeattr.h" /*! \class TVBrowseView \brief The widget describing how to draw the browse view user interface This widget allows for the user to browse through the table, one element at a time, or search on a single key. Its main goal is to show a single element in a readable format and make it easy for the user to rapidly find specific elements in the table. */ /*! Constructs a new TVBrowseView widget */ TVBrowseView::TVBrowseView(TableState *t, QWidget* parent, const char *name, WFlags fl ) { if (!name) setName("BrowseView"); // setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 0, 0, sizePolicy().hasHeightForWidth() ) ); QVBoxLayout *vlayout = new QVBoxLayout(this); textViewDisplay = new QTextBrowser(this, "textViewDisplay"); vlayout->addWidget( textViewDisplay ); keyEntry = new TVBrowseKeyEntry(this, "keyEntry"); vlayout->addWidget( keyEntry ); /* connect the signals down */ - connect(keyEntry, SIGNAL(searchOnKey(int, TVVariant)), - this, SIGNAL(searchOnKey(int, TVVariant))); + connect(keyEntry, SIGNAL(searchOnKey(int,TVVariant)), + this, SIGNAL(searchOnKey(int,TVVariant))); connect(keyEntry, SIGNAL(sortChanged(int)), this, SIGNAL(sortChanged(int))); ts = t; keyEntry->setTableState(t); } /*! Destroys the TVBrowseView widget */ TVBrowseView::~TVBrowseView() { } void TVBrowseView::rebuildData() { if(!ts) return; if(!ts->current_elem) { /* also disable buttons */ textViewDisplay->setText(""); return; } setDisplayText(ts->current_elem); } /* Reset to initial state */ void TVBrowseView::reset() { textViewDisplay->setText(""); keyEntry->reset(); } /*! sets the data element to be displayed to element */ void TVBrowseView::setDisplayText(const DataElem *element) { QString rep = ""; KeyListIterator it(*ts->kRep); while (it.current()) { if (element->hasValidValue(it.currentKey())) { if(it.currentKey() == ts->current_column) { rep += "<A name=\"ckey\"></A><B><FONT COLOR=#FF0000>" + encodeAttr(it.current()->name()) + ":</FONT></B> "; } else { rep += "<B>" + encodeAttr(it.current()->name()) + ":</B> "; } rep += encodeAttr(element->toQString(it.currentKey())) + "<BR>"; } ++it; } textViewDisplay->setText(rep); textViewDisplay->scrollToAnchor("ckey"); } void TVBrowseView::rebuildKeys() { keyEntry->rebuildKeys(); } diff --git a/noncore/apps/tableviewer/ui/tvfilterview.cpp b/noncore/apps/tableviewer/ui/tvfilterview.cpp index b03e846..22f1fb7 100644 --- a/noncore/apps/tableviewer/ui/tvfilterview.cpp +++ b/noncore/apps/tableviewer/ui/tvfilterview.cpp @@ -1,284 +1,284 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "tvfilterview.h" #include <qtoolbutton.h> #include <qcombobox.h> #include <qlistview.h> #include <qlayout.h> #include <qheader.h> #include <qpushbutton.h> #include <qlabel.h> #include <qpe/qpeapplication.h> TVFilterView::TVFilterView(TableState *t, QWidget* parent, const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl) { if ( !name ) setName( "Filter View" ); QVBoxLayout *vlayout = new QVBoxLayout(this); display = new QListView(this, "display"); display->addColumn("Key"); display->addColumn("Constraint"); display->addColumn("Value"); display->header()->setClickEnabled(FALSE); display->header()->setResizeEnabled(FALSE); vlayout->addWidget(display); QHBoxLayout *hlayout = new QHBoxLayout; hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); newFilterButton = new QPushButton(this, "new Filter"); newFilterButton->setMaximumSize(QSize(50, 32767)); newFilterButton->setText("New"); hlayout->addWidget(newFilterButton); deleteFilterButton = new QPushButton(this, "delete Filter"); deleteFilterButton->setMaximumSize(QSize(50, 32767)); deleteFilterButton->setText("Delete"); hlayout->addWidget(deleteFilterButton); clearFilterButton = new QPushButton(this, "delete Filter"); clearFilterButton->setMaximumSize(QSize(60, 32767)); clearFilterButton->setText("Clear All"); hlayout->addWidget(clearFilterButton); vlayout->addLayout(hlayout); QHBoxLayout *hlayout2 = new QHBoxLayout; keyNameCombo = new QComboBox(FALSE, this, "key name"); keyNameCombo->setEnabled(FALSE); hlayout2->addWidget(keyNameCombo); QLabel *label = new QLabel(this); label->setText("has value"); hlayout2->addWidget(label); keyEntry = new TVFilterKeyEntry(this, "key entry"); keyEntry->setEnabled(FALSE); vlayout->addLayout(hlayout2); vlayout->addWidget(keyEntry); connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() )); connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm())); connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms())); connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() )); connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() )); connect(display, SIGNAL(selectionChanged(QListViewItem*)), this, - SLOT(setTerm(QListViewItem *))); + SLOT(setTerm(QListViewItem*))); ts = t; current = 0; terms.setAutoDelete(true); do_filter = false; #ifdef Q_WS_QWS QPEApplication::showDialog( this ); #endif } /*! Destroys the TVFilterView widget */ TVFilterView::~TVFilterView() { } void TVFilterView::rebuildData() { } void TVFilterView::reset() { keyNameCombo->clear(); keyIds.clear(); } void TVFilterView::rebuildKeys() { int i; if (!ts) return; if(!ts->kRep) return; keyEntry->setTableState(ts); /* set up the list of keys that can be compared on */ keyNameCombo->clear(); KeyListIterator it(*ts->kRep); i = 0; while(it.current()) { if(ts->kRep->validIndex(it.currentKey())) { keyNameCombo->insertItem(it.current()->name()); keyIds.insert(i, it.currentKey()); ++i; } ++it; } } bool TVFilterView::passesFilter(DataElem *d) { if (!filterActive()) return true; FilterTerm *t; for (t = terms.first(); t != 0; t = terms.next() ) { /* check against filter */ switch(t->ct) { case ct_less: if (!d->lessThan(t->keyIndex, t->value)) return false; break; case ct_more: if (!d->moreThan(t->keyIndex, t->value)) return false; break; case ct_equal: if (!d->equalTo(t->keyIndex, t->value)) return false; break; case ct_contains: if (!d->contains(t->keyIndex, t->value)) return false; break; case ct_startswith: if (!d->startsWith(t->keyIndex, t->value)) return false; break; case ct_endswith: if (!d->endsWith(t->keyIndex, t->value)) return false; break; default: qWarning("TVFilterView::passesFilter() " "unrecognized filter type"); return false; } } return true; } bool TVFilterView::filterActive() const { /* when button operated, also check the do_filter value return do_filter; */ if (terms.isEmpty()) return false; return true; } /* SLOTS */ void TVFilterView::newTerm() { if (!ts) return; FilterTerm *term = new FilterTerm; current = term; term->view = 0; updateTerm(); display->setSelected(term->view, true); terms.append(term); keyEntry->setEnabled(true); keyNameCombo->setEnabled(true); } void TVFilterView::updateTerm() { FilterTerm *term; /* Read the widget values (keyname, compare type, value) * and build the lists */ if (!ts) return; if (!current) return; QString keyString; QString cmpString; QString vString; term = current; /* create new list item, set initial values, enable widgets */ term->keyIndex = keyIds[keyNameCombo->currentItem()]; keyEntry->setKey(term->keyIndex); /* so the next two items make sense */ term->ct = keyEntry->getCompareType(), term->value = keyEntry->getCompareValue(); keyString = keyNameCombo->currentText(); switch(term->ct) { case ct_less: cmpString = " less than "; break; case ct_more: cmpString = " more than "; break; case ct_equal: cmpString = " equal to "; break; case ct_contains: cmpString = " containing "; break; case ct_startswith: cmpString = " starting with "; break; case ct_endswith: cmpString = " ending with "; break; default: cmpString = " ERROR "; } vString = term->value.toString(); /* remove old view */ if (term->view) delete(term->view); term->view = new QListViewItem(display, 0, keyString, cmpString, vString); display->setSelected(term->view, true); } /* deletes current term */ void TVFilterView::deleteTerm() { if(!current) return; if (current->view) delete(current->view); terms.removeRef(current); current = terms.first(); if(terms.isEmpty()) { keyEntry->setEnabled(false); keyNameCombo->setEnabled(false); } } diff --git a/noncore/apps/tableviewer/ui/tvlistview.cpp b/noncore/apps/tableviewer/ui/tvlistview.cpp index b25e813..b10ff1d 100644 --- a/noncore/apps/tableviewer/ui/tvlistview.cpp +++ b/noncore/apps/tableviewer/ui/tvlistview.cpp @@ -1,300 +1,300 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "tvlistview.h" #include "../db/common.h" #include <qtoolbutton.h> #include <qlistview.h> #include <qlayout.h> void TVListViewPrivate::setColumnWidth(int column, int width) { if(width > 70) width = 70; QListView::setColumnWidth(column, width); } void TVListViewPrivate::setSorting(int column, bool increasing) { emit sortChanged(column); QListView::setSorting(column, increasing); } TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name, WFlags fl) : QListView(parent, name, fl) { ; } class TVListViewItem : public QListViewItem { public: TVListViewItem(QListView *parent, DataElem *d); ~TVListViewItem(); QString text(int i) const { return data_reference->toQString(i); } /* Do nothing... all data for this item should be generated */ void setText(int i, const QString &) { ; } QString key(int i, bool a) const { return data_reference->toSortableQString(i); } void setDataElem(DataElem *d) { data_reference = d; } DataElem *getDataElem() { return data_reference; } private: DataElem *data_reference; }; TVListViewItem::TVListViewItem(QListView *parent, DataElem *d) : QListViewItem(parent) { data_reference = d; } TVListViewItem::~TVListViewItem() { data_reference = 0; } TVListView::TVListView(TableState *t, QWidget* parent, const char *name, WFlags fl ) : QWidget(parent, name, fl) { if (!name) setName("TVListView"); // the next two lines need to be rationalized. resize(318,457); setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth())); setCaption(tr("List View")); QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(0); layout->setMargin(0); listViewDisplay = new TVListViewPrivate(this, "listViewDisplay"); layout->addWidget(listViewDisplay); - connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this, - SLOT(setCurrent(QListViewItem *))); + connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem*)), this, + SLOT(setCurrent(QListViewItem*))); connect(listViewDisplay, SIGNAL(sortChanged(int)), this, SLOT(setSorting(int))); listViewDisplay->setShowSortIndicator(true); it = new QListViewItemIterator(listViewDisplay); ts = t; } TVListView::~TVListView() { } void TVListView::addItem(DataElem *d) { TVListViewItem *i = new TVListViewItem(listViewDisplay, d); delete it; it = new QListViewItemIterator(i); } /* remove current (it) item */ void TVListView::removeItem() { QListViewItemIterator other(*it); QListViewItemIterator tmp = *it; (*it)++; if (!it->current()) { *it = tmp; (*it)--; if (!it->current()) { delete it; it = 0; } } delete other.current(); } void TVListView::clearItems() { /* This is ok since the destructor for TVListItem does not know about the data_reference pointer.. and hence will leave it alone */ listViewDisplay->clear(); delete it; it = new QListViewItemIterator(listViewDisplay); } void TVListView::first() { delete it; it = new QListViewItemIterator(listViewDisplay); } void TVListView::last() { qWarning("TVListView::last not yet implemented"); } void TVListView::next() { QListViewItemIterator tmp = *it; (*it)++; if (!it->current()) { *it = tmp; } } void TVListView::previous() { QListViewItemIterator tmp = *it; (*it)--; if (!it->current()) { *it = tmp; } } DataElem *TVListView::getCurrentData() { if (it->current()) { return ((TVListViewItem *)it->current())->getDataElem(); } return NULL; } /*! Now to implement the closest match function */ void TVListView::findItem(int keyId, TVVariant value) { QListViewItem *i; TVListViewItem *best_so_far = NULL; /* start at the beginning... go through till find the closest elem */ i = listViewDisplay->firstChild(); while (i) { /* search stuff */ if(best_so_far) { if (DataElem::closer( ((TVListViewItem *)i)->getDataElem(), best_so_far->getDataElem(), value, keyId)) best_so_far = (TVListViewItem *)i; } else { if (DataElem::closer( ((TVListViewItem *)i)->getDataElem(), NULL, value, keyId)) best_so_far = (TVListViewItem *)i; } i = i->itemBelow(); } if (best_so_far) { /* set best_so_far to current element */ delete it; it = new QListViewItemIterator(best_so_far); } } void TVListView::rebuildKeys() { int i; if(!ts) return; if(!ts->kRep) return; i = listViewDisplay->columns(); while(i > 0) listViewDisplay->removeColumn(--i); KeyListIterator kit(*ts->kRep); i = 0; while(kit.current()) { if(!kit.current()->delFlag()) { listViewDisplay->addColumn(kit.current()->name()); keyIds.insert(i, kit.currentKey()); ++i; } ++kit; } } void TVListView::setSorting(int column) { /* Without table state can't do anything */ if (ts == 0) return; if (keyIds[column] != ts->current_column) { ts->current_column = keyIds[column]; } } void TVListView::rebuildData() { int i; QMap<int, int>::Iterator kit; /* Need to set sort order */ if(!ts) return; /* revers lookup the column */ i = -1; for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) { if (kit.data() == ts->current_column) { i = kit.key(); break; } } if (i == -1) return; listViewDisplay->setSorting(i); listViewDisplay->sort(); /* reset current element */ listViewDisplay->setCurrentItem(it->current()); listViewDisplay->setSelected(it->current(), true); listViewDisplay->ensureItemVisible(it->current()); } void TVListView::reset() { int i; listViewDisplay->clear(); i = listViewDisplay->columns(); while (i > 0) listViewDisplay->removeColumn(--i); keyIds.clear(); } void TVListView::setCurrent(QListViewItem *i) { /* cast */ TVListViewItem *t = (TVListViewItem *)i; |