/rekall-2.4.6/libs/kbase/kb_tree.cpp
C++ | 490 lines | 313 code | 82 blank | 95 comment | 31 complexity | e0dca1bfaa855e46c14a7211b3dfa633 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, LGPL-2.1
- /***************************************************************************
- file : kb_tree.cpp
- copyright : (C) 1999,2000,2001,2002,2003,2004,2005
- by Mike Richardson
- (C) 2001,2002,2003,2004,2005
- by John Dean
- license : This file is released under the terms of
- the GNU General Public License, version 2. The
- copyright holders retain the right to release
- this code under diffenent non-exclusive licences.
- email : mike@quaking.demon.co.uk
- ***************************************************************************/
- #if __KB_AUTOMOC
- #include "kb_tree.moc"
- #else
- #include "kb_tree.h"
- #endif
- #include "kb_qttree.h"
- #include "kb_nodereg.h"
- #include "kb_popupmenu.h"
- #include "kb_qrytable.h"
- #include "kb_qryquery.h"
- #include "kb_qrysql.h"
- #include "kb_formblock.h"
- /* KBTree */
- /* KBTree : Constructor for tree control */
- /* parent : KBNode * : Parent node */
- /* aList : const QDict<QString> & */
- /* : List of attributes */
- /* ok : bool * : Success */
- /* (returns) : KBNode : */
- KBTree::KBTree
- ( KBNode *parent,
- const QDict<QString> &aList,
- bool *ok
- )
- :
- KBLinkTree (parent, aList, "KBTree"),
- m_group (this, "group", aList, KAF_REQD|KAF_GRPDATA),
- m_clickOpen (this, "clickopen", aList, KAF_GRPFORMAT),
- m_setClose (this, "setclose", aList, KAF_GRPFORMAT),
- m_treeType (this, "treetype", aList, KAF_GRPFORMAT)
- {
- #if ! __KB_RUNTIME
- if (ok != 0)
- {
- QString *lt = aList.find ("linktype") ;
- if (lt != 0)
- if (*lt == "query") m_query = new KBQryQuery (this) ;
- else if (*lt == "sql" ) m_query = new KBQrySQL (this) ;
- if (m_query == 0)
- m_query = new KBQryTable (this) ;
- if (!m_query->propertyDlg ())
- { delete this ;
- *ok = false ;
- return ;
- }
- if (!::treePropDlg (this, "Tree", m_attribs))
- { delete this ;
- *ok = false ;
- return ;
- }
- *ok = true ;
- }
- #endif
- m_groupCount = 0 ;
- }
- /* KBTree */
- /* KBTree : Constructor for tree control */
- /* parent : KBNode * : Parent node */
- /* link : KBTree * : Extant link */
- /* (returns) : KBNode : */
- KBTree::KBTree
- ( KBNode *parent,
- KBTree *tree
- )
- :
- KBLinkTree (parent, tree),
- m_group (this, "group", tree, KAF_REQD|KAF_GRPDATA),
- m_clickOpen (this, "clickopen", tree, KAF_GRPFORMAT),
- m_setClose (this, "setclose", tree, KAF_GRPFORMAT),
- m_treeType (this, "treetype", tree, KAF_GRPFORMAT)
- {
- m_groupCount = 0 ;
- }
- /* KBTree */
- /* ~KBTree : Destructor for tree control */
- /* (returns) : : */
- KBTree::~KBTree ()
- {
- }
- void KBTree::loadControl
- ( uint drow,
- const QStringList &keyset,
- const KBLTValueSet &valset
- )
- {
- if (m_ctrls.at(drow) != 0)
- ((KBCtrlTree *)m_ctrls.at(drow))->loadControl (keyset, valset) ;
- }
- /* KBTree */
- /* addDummyItems: Add dummy items for query */
- /* (returns) : uint : Number of items added excluding key */
- uint KBTree::addDummyItems ()
- {
- uint added = KBLinkTree::addDummyItems () ;
- m_groupCount = addExprItems (m_group.getValue()) ;
- return added + m_groupCount ;
- }
- /* KBTree */
- /* makeCtrl : Make a link control */
- /* drow : uint : Display row number */
- /* (returns) : KBControl * : Associated control */
- KBControl
- *KBTree::makeCtrl
- ( uint drow
- )
- {
- return new KBCtrlTree (getDisplay(), this, drow) ;
- }
- /* KBTree */
- /* replicate : Replicate this link */
- /* parent : KBNode * : Parent of replicant */
- /* (returns) : KBNode * : New link node */
- KBNode *KBTree::replicate
- ( KBNode *parent
- )
- {
- KBTree *nTree = new KBTree (parent, this) ;
- CITER
- ( QryBase,
- q,
- nTree->m_query = q->replicate(nTree)->isQryBase() ;
- break ;
- ) ;
- return nTree ;
- }
- /* KBTree */
- /* setUserFilter */
- /* : Set user filter for link query */
- /* qrow : uint : Applicable query row */
- /* filter : const QString & : Filter expression */
- /* (returns) : void : */
- void KBTree::setUserFilter
- ( uint qrow,
- const QString &filter
- )
- {
- KBControl *ctrl = ctrlAtQRow (qrow) ;
- if (ctrl != 0) ((KBCtrlTree *)ctrl)->setUserFilter (filter ) ;
- }
- /* KBTree */
- /* setUserSorting */
- /* : Set user sorting for link query */
- /* qrow : uint : Applicable query row */
- /* sorting : const QString & : Sorting expression */
- /* (returns) : void : */
- void KBTree::setUserSorting
- ( uint qrow,
- const QString &sorting
- )
- {
- KBControl *ctrl = ctrlAtQRow (qrow) ;
- if (ctrl != 0) ((KBCtrlTree *)ctrl)->setUserSorting(sorting) ;
- }
- /* KBTree */
- /* reload : Reload values list */
- /* qrow : uint : Applicable query row */
- /* (returns) : void : */
- void KBTree::reload
- ( uint qrow
- )
- {
- KBControl *ctrl = ctrlAtQRow (qrow) ;
- if (ctrl != 0) ((KBCtrlTree *)ctrl)->reload() ;
- }
- /* KBTree */
- /* getExtra : Get extra value */
- /* qrow : uint : Query row */
- /* which : bool : Specifies extra or display */
- /* index : uint : Extra index */
- /* (returns) : KBValue : Extra value */
- KBValue KBTree::getExtra
- ( uint qrow,
- bool which,
- uint index
- )
- {
- KBControl *ctrl = ctrlAtQRow (qrow) ;
- return ctrl == 0 ? KBValue() : ((KBCtrlTree *)ctrl)->getExtra (which, index) ;
- }
- /* KBTree */
- /* getNumValues: Get number of values showing at row */
- /* qrow : uint : Query row number */
- /* (returns) : uint : Number of values */
- uint KBTree::getNumValues
- ( uint qrow
- )
- {
- KBControl *ctrl = ctrlAtQRow (qrow) ;
- uint nv = 0 ;
- if (ctrl != 0)
- if (((KBCtrlTree *)ctrl)->getNumValues (nv))
- return nv ;
- return m_valset.count() ;
- }
- /* KBTree */
- /* getDisplayList */
- /* : Get list of displayed text values at row */
- /* qrow : uint : Query row number */
- /* (returns) : QStringList : List of text values */
- QStringList
- KBTree::getDisplayList
- ( uint qrow
- )
- {
- QStringList results ;
- if (getRoot()->isForm() != 0)
- {
- KBControl *ctrl = ctrlAtQRow (qrow) ;
- if (ctrl != 0)
- if (((KBCtrlTree *)ctrl)->getDisplayList (results))
- return results ;
- }
- for (uint idx = 0 ; idx < m_valset.count() ; idx += 1)
- results.append (m_valset[idx][0]) ;
- return results ;
- }
- /* KBTree */
- /* groupCount : Get count of grouping columns */
- /* (returns) : uint : Group column count */
- uint KBTree::groupCount ()
- {
- return m_groupCount ;
- }
- /* KBTree */
- /* clickOpen : Return click-opens setting */
- /* (returns) : bool : True if click-opens set */
- bool KBTree::clickOpen ()
- {
- return m_clickOpen.getBoolValue() ;
- }
- /* KBTree */
- /* setClose : Get close-on-set setting */
- /* (returns) : bool : True if close-on-set set */
- bool KBTree::setClose ()
- {
- return m_setClose .getBoolValue() ;
- }
- /* KBTree */
- /* treeType : Get selected tree type */
- /* (returns) : KBTree::TreeType : Selected tree type */
- KBTree::TreeType
- KBTree::treeType ()
- {
- return (KBTree::TreeType)m_treeType .getIntValue () ;
- }
- #if ! __KB_RUNTIME
- /* KBTree */
- /* propertyDlg : Show property dialog */
- /* iniAttr : cchar * : Initial attribute */
- /* (returns) : bool : Success */
- bool KBTree::propertyDlg
- ( cchar *iniAttr
- )
- {
- if (::treePropDlg (this, "Tree", m_attribs, iniAttr))
- {
- setupProperties () ;
- addDummyItems () ;
- return true ;
- }
- return false ;
- }
- #endif
- static KBNode *newTreeTable
- ( KBNode *parent,
- const QDict<QString> &aDict,
- bool *ok
- )
- {
- QDict<QString> d2 (aDict ) ;
- QString lt ("table") ;
- d2.insert ("linktype", <) ;
- return new KBTree (parent, d2, ok) ;
- }
- static KBNode *newTreeQuery
- ( KBNode *parent,
- const QDict<QString> &aDict,
- bool *ok
- )
- {
- QDict<QString> d2 (aDict ) ;
- QString lt ("query") ;
- d2.insert ("linktype", <) ;
- return new KBTree (parent, d2, ok) ;
- }
- static KBNode *newTreeSQL
- ( KBNode *parent,
- const QDict<QString> &aDict,
- bool *ok
- )
- {
- QDict<QString> d2 (aDict ) ;
- QString lt ("sql" ) ;
- d2.insert ("linktype", <) ;
- return new KBTree (parent, d2, ok) ;
- }
- /* ------------------------------------------------------------------ */
- /* The following code is used to generate the "New Tree" popup menu, */
- /* which allows the insertion of trees based on Queries (both Rekall */
- /* and SQL) as well as tables. */
- static KBNode *makeTableTreeFromWizard
- ( KBNode *parent,
- KBQryBase *query,
- KBAttrDict &aDict,
- bool &cancel
- )
- {
- #if ! __KB_RUNTIME
- extern KBNode *makeCtrlFromWizard
- ( KBNode *parent,
- KBQryBase *query,
- cchar *wizName,
- KBAttrDict &aDict,
- bool &cancel
- ) ;
- return makeCtrlFromWizard
- ( parent,
- query,
- "KBTreeTable",
- aDict,
- cancel
- ) ;
- #else
- return 0 ;
- #endif
- }
- static NodeSpec nodeSpecTable =
- {
- 0,
- QString::null,
- 0,
- newTreeTable,
- makeTableTreeFromWizard,
- KNF_FORM|KNF_BLOCK|KNF_DATA,
- -1
- } ;
- static NodeSpec nodeSpecQuery =
- {
- 0,
- QString::null,
- 0,
- newTreeQuery,
- 0,
- KNF_FORM|KNF_BLOCK|KNF_DATA,
- -1
- } ;
- static NodeSpec nodeSpecSQL =
- {
- 0,
- QString::null,
- 0,
- newTreeSQL,
- 0,
- KNF_FORM|KNF_BLOCK|KNF_DATA,
- -1
- } ;
- /* makeTreePopup: Make new tree popup menu */
- /* parent : QWidget * : Parent widget */
- /* receiver : QObject * : Reciever for menu signals */
- /* bState : Qt::ButtonState & : Return button state */
- /* dflt : NodeSpec ** : Return default case */
- /* (returns) : KBPopupMenu * : New popup menu */
- KBPopupMenu
- *KBTree::makeTreePopup
- ( QWidget *parent,
- QObject *receiver,
- Qt::ButtonState *bState,
- NodeSpec **dflt
- )
- {
- KBPopupMenu *tp = new KBPopupMenu (parent, bState) ;
- tp->insertItem
- ( TR("Table tree"),
- receiver,
- SLOT(newNode(int)),
- QKeySequence(),
- nodeSpecToId(&nodeSpecTable)
- ) ;
- tp->insertItem
- ( TR("Query tree"),
- receiver,
- SLOT(newNode(int)),
- QKeySequence(),
- nodeSpecToId(&nodeSpecQuery)
- ) ;
- tp->insertItem
- ( TR("SQL tree" ),
- receiver,
- SLOT(newNode(int)),
- QKeySequence(),
- nodeSpecToId(&nodeSpecSQL)
- ) ;
- *dflt = &nodeSpecTable ;
- return tp ;
- }
- NEWNODE(Tree, __TR("New &Tree"), makeTreePopup, KNF_FORM|KNF_BLOCK|KNF_DATA)