PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. /***************************************************************************
  2. file : kb_tree.cpp
  3. copyright : (C) 1999,2000,2001,2002,2003,2004,2005
  4. by Mike Richardson
  5. (C) 2001,2002,2003,2004,2005
  6. by John Dean
  7. license : This file is released under the terms of
  8. the GNU General Public License, version 2. The
  9. copyright holders retain the right to release
  10. this code under diffenent non-exclusive licences.
  11. email : mike@quaking.demon.co.uk
  12. ***************************************************************************/
  13. #if __KB_AUTOMOC
  14. #include "kb_tree.moc"
  15. #else
  16. #include "kb_tree.h"
  17. #endif
  18. #include "kb_qttree.h"
  19. #include "kb_nodereg.h"
  20. #include "kb_popupmenu.h"
  21. #include "kb_qrytable.h"
  22. #include "kb_qryquery.h"
  23. #include "kb_qrysql.h"
  24. #include "kb_formblock.h"
  25. /* KBTree */
  26. /* KBTree : Constructor for tree control */
  27. /* parent : KBNode * : Parent node */
  28. /* aList : const QDict<QString> & */
  29. /* : List of attributes */
  30. /* ok : bool * : Success */
  31. /* (returns) : KBNode : */
  32. KBTree::KBTree
  33. ( KBNode *parent,
  34. const QDict<QString> &aList,
  35. bool *ok
  36. )
  37. :
  38. KBLinkTree (parent, aList, "KBTree"),
  39. m_group (this, "group", aList, KAF_REQD|KAF_GRPDATA),
  40. m_clickOpen (this, "clickopen", aList, KAF_GRPFORMAT),
  41. m_setClose (this, "setclose", aList, KAF_GRPFORMAT),
  42. m_treeType (this, "treetype", aList, KAF_GRPFORMAT)
  43. {
  44. #if ! __KB_RUNTIME
  45. if (ok != 0)
  46. {
  47. QString *lt = aList.find ("linktype") ;
  48. if (lt != 0)
  49. if (*lt == "query") m_query = new KBQryQuery (this) ;
  50. else if (*lt == "sql" ) m_query = new KBQrySQL (this) ;
  51. if (m_query == 0)
  52. m_query = new KBQryTable (this) ;
  53. if (!m_query->propertyDlg ())
  54. { delete this ;
  55. *ok = false ;
  56. return ;
  57. }
  58. if (!::treePropDlg (this, "Tree", m_attribs))
  59. { delete this ;
  60. *ok = false ;
  61. return ;
  62. }
  63. *ok = true ;
  64. }
  65. #endif
  66. m_groupCount = 0 ;
  67. }
  68. /* KBTree */
  69. /* KBTree : Constructor for tree control */
  70. /* parent : KBNode * : Parent node */
  71. /* link : KBTree * : Extant link */
  72. /* (returns) : KBNode : */
  73. KBTree::KBTree
  74. ( KBNode *parent,
  75. KBTree *tree
  76. )
  77. :
  78. KBLinkTree (parent, tree),
  79. m_group (this, "group", tree, KAF_REQD|KAF_GRPDATA),
  80. m_clickOpen (this, "clickopen", tree, KAF_GRPFORMAT),
  81. m_setClose (this, "setclose", tree, KAF_GRPFORMAT),
  82. m_treeType (this, "treetype", tree, KAF_GRPFORMAT)
  83. {
  84. m_groupCount = 0 ;
  85. }
  86. /* KBTree */
  87. /* ~KBTree : Destructor for tree control */
  88. /* (returns) : : */
  89. KBTree::~KBTree ()
  90. {
  91. }
  92. void KBTree::loadControl
  93. ( uint drow,
  94. const QStringList &keyset,
  95. const KBLTValueSet &valset
  96. )
  97. {
  98. if (m_ctrls.at(drow) != 0)
  99. ((KBCtrlTree *)m_ctrls.at(drow))->loadControl (keyset, valset) ;
  100. }
  101. /* KBTree */
  102. /* addDummyItems: Add dummy items for query */
  103. /* (returns) : uint : Number of items added excluding key */
  104. uint KBTree::addDummyItems ()
  105. {
  106. uint added = KBLinkTree::addDummyItems () ;
  107. m_groupCount = addExprItems (m_group.getValue()) ;
  108. return added + m_groupCount ;
  109. }
  110. /* KBTree */
  111. /* makeCtrl : Make a link control */
  112. /* drow : uint : Display row number */
  113. /* (returns) : KBControl * : Associated control */
  114. KBControl
  115. *KBTree::makeCtrl
  116. ( uint drow
  117. )
  118. {
  119. return new KBCtrlTree (getDisplay(), this, drow) ;
  120. }
  121. /* KBTree */
  122. /* replicate : Replicate this link */
  123. /* parent : KBNode * : Parent of replicant */
  124. /* (returns) : KBNode * : New link node */
  125. KBNode *KBTree::replicate
  126. ( KBNode *parent
  127. )
  128. {
  129. KBTree *nTree = new KBTree (parent, this) ;
  130. CITER
  131. ( QryBase,
  132. q,
  133. nTree->m_query = q->replicate(nTree)->isQryBase() ;
  134. break ;
  135. ) ;
  136. return nTree ;
  137. }
  138. /* KBTree */
  139. /* setUserFilter */
  140. /* : Set user filter for link query */
  141. /* qrow : uint : Applicable query row */
  142. /* filter : const QString & : Filter expression */
  143. /* (returns) : void : */
  144. void KBTree::setUserFilter
  145. ( uint qrow,
  146. const QString &filter
  147. )
  148. {
  149. KBControl *ctrl = ctrlAtQRow (qrow) ;
  150. if (ctrl != 0) ((KBCtrlTree *)ctrl)->setUserFilter (filter ) ;
  151. }
  152. /* KBTree */
  153. /* setUserSorting */
  154. /* : Set user sorting for link query */
  155. /* qrow : uint : Applicable query row */
  156. /* sorting : const QString & : Sorting expression */
  157. /* (returns) : void : */
  158. void KBTree::setUserSorting
  159. ( uint qrow,
  160. const QString &sorting
  161. )
  162. {
  163. KBControl *ctrl = ctrlAtQRow (qrow) ;
  164. if (ctrl != 0) ((KBCtrlTree *)ctrl)->setUserSorting(sorting) ;
  165. }
  166. /* KBTree */
  167. /* reload : Reload values list */
  168. /* qrow : uint : Applicable query row */
  169. /* (returns) : void : */
  170. void KBTree::reload
  171. ( uint qrow
  172. )
  173. {
  174. KBControl *ctrl = ctrlAtQRow (qrow) ;
  175. if (ctrl != 0) ((KBCtrlTree *)ctrl)->reload() ;
  176. }
  177. /* KBTree */
  178. /* getExtra : Get extra value */
  179. /* qrow : uint : Query row */
  180. /* which : bool : Specifies extra or display */
  181. /* index : uint : Extra index */
  182. /* (returns) : KBValue : Extra value */
  183. KBValue KBTree::getExtra
  184. ( uint qrow,
  185. bool which,
  186. uint index
  187. )
  188. {
  189. KBControl *ctrl = ctrlAtQRow (qrow) ;
  190. return ctrl == 0 ? KBValue() : ((KBCtrlTree *)ctrl)->getExtra (which, index) ;
  191. }
  192. /* KBTree */
  193. /* getNumValues: Get number of values showing at row */
  194. /* qrow : uint : Query row number */
  195. /* (returns) : uint : Number of values */
  196. uint KBTree::getNumValues
  197. ( uint qrow
  198. )
  199. {
  200. KBControl *ctrl = ctrlAtQRow (qrow) ;
  201. uint nv = 0 ;
  202. if (ctrl != 0)
  203. if (((KBCtrlTree *)ctrl)->getNumValues (nv))
  204. return nv ;
  205. return m_valset.count() ;
  206. }
  207. /* KBTree */
  208. /* getDisplayList */
  209. /* : Get list of displayed text values at row */
  210. /* qrow : uint : Query row number */
  211. /* (returns) : QStringList : List of text values */
  212. QStringList
  213. KBTree::getDisplayList
  214. ( uint qrow
  215. )
  216. {
  217. QStringList results ;
  218. if (getRoot()->isForm() != 0)
  219. {
  220. KBControl *ctrl = ctrlAtQRow (qrow) ;
  221. if (ctrl != 0)
  222. if (((KBCtrlTree *)ctrl)->getDisplayList (results))
  223. return results ;
  224. }
  225. for (uint idx = 0 ; idx < m_valset.count() ; idx += 1)
  226. results.append (m_valset[idx][0]) ;
  227. return results ;
  228. }
  229. /* KBTree */
  230. /* groupCount : Get count of grouping columns */
  231. /* (returns) : uint : Group column count */
  232. uint KBTree::groupCount ()
  233. {
  234. return m_groupCount ;
  235. }
  236. /* KBTree */
  237. /* clickOpen : Return click-opens setting */
  238. /* (returns) : bool : True if click-opens set */
  239. bool KBTree::clickOpen ()
  240. {
  241. return m_clickOpen.getBoolValue() ;
  242. }
  243. /* KBTree */
  244. /* setClose : Get close-on-set setting */
  245. /* (returns) : bool : True if close-on-set set */
  246. bool KBTree::setClose ()
  247. {
  248. return m_setClose .getBoolValue() ;
  249. }
  250. /* KBTree */
  251. /* treeType : Get selected tree type */
  252. /* (returns) : KBTree::TreeType : Selected tree type */
  253. KBTree::TreeType
  254. KBTree::treeType ()
  255. {
  256. return (KBTree::TreeType)m_treeType .getIntValue () ;
  257. }
  258. #if ! __KB_RUNTIME
  259. /* KBTree */
  260. /* propertyDlg : Show property dialog */
  261. /* iniAttr : cchar * : Initial attribute */
  262. /* (returns) : bool : Success */
  263. bool KBTree::propertyDlg
  264. ( cchar *iniAttr
  265. )
  266. {
  267. if (::treePropDlg (this, "Tree", m_attribs, iniAttr))
  268. {
  269. setupProperties () ;
  270. addDummyItems () ;
  271. return true ;
  272. }
  273. return false ;
  274. }
  275. #endif
  276. static KBNode *newTreeTable
  277. ( KBNode *parent,
  278. const QDict<QString> &aDict,
  279. bool *ok
  280. )
  281. {
  282. QDict<QString> d2 (aDict ) ;
  283. QString lt ("table") ;
  284. d2.insert ("linktype", &lt) ;
  285. return new KBTree (parent, d2, ok) ;
  286. }
  287. static KBNode *newTreeQuery
  288. ( KBNode *parent,
  289. const QDict<QString> &aDict,
  290. bool *ok
  291. )
  292. {
  293. QDict<QString> d2 (aDict ) ;
  294. QString lt ("query") ;
  295. d2.insert ("linktype", &lt) ;
  296. return new KBTree (parent, d2, ok) ;
  297. }
  298. static KBNode *newTreeSQL
  299. ( KBNode *parent,
  300. const QDict<QString> &aDict,
  301. bool *ok
  302. )
  303. {
  304. QDict<QString> d2 (aDict ) ;
  305. QString lt ("sql" ) ;
  306. d2.insert ("linktype", &lt) ;
  307. return new KBTree (parent, d2, ok) ;
  308. }
  309. /* ------------------------------------------------------------------ */
  310. /* The following code is used to generate the "New Tree" popup menu, */
  311. /* which allows the insertion of trees based on Queries (both Rekall */
  312. /* and SQL) as well as tables. */
  313. static KBNode *makeTableTreeFromWizard
  314. ( KBNode *parent,
  315. KBQryBase *query,
  316. KBAttrDict &aDict,
  317. bool &cancel
  318. )
  319. {
  320. #if ! __KB_RUNTIME
  321. extern KBNode *makeCtrlFromWizard
  322. ( KBNode *parent,
  323. KBQryBase *query,
  324. cchar *wizName,
  325. KBAttrDict &aDict,
  326. bool &cancel
  327. ) ;
  328. return makeCtrlFromWizard
  329. ( parent,
  330. query,
  331. "KBTreeTable",
  332. aDict,
  333. cancel
  334. ) ;
  335. #else
  336. return 0 ;
  337. #endif
  338. }
  339. static NodeSpec nodeSpecTable =
  340. {
  341. 0,
  342. QString::null,
  343. 0,
  344. newTreeTable,
  345. makeTableTreeFromWizard,
  346. KNF_FORM|KNF_BLOCK|KNF_DATA,
  347. -1
  348. } ;
  349. static NodeSpec nodeSpecQuery =
  350. {
  351. 0,
  352. QString::null,
  353. 0,
  354. newTreeQuery,
  355. 0,
  356. KNF_FORM|KNF_BLOCK|KNF_DATA,
  357. -1
  358. } ;
  359. static NodeSpec nodeSpecSQL =
  360. {
  361. 0,
  362. QString::null,
  363. 0,
  364. newTreeSQL,
  365. 0,
  366. KNF_FORM|KNF_BLOCK|KNF_DATA,
  367. -1
  368. } ;
  369. /* makeTreePopup: Make new tree popup menu */
  370. /* parent : QWidget * : Parent widget */
  371. /* receiver : QObject * : Reciever for menu signals */
  372. /* bState : Qt::ButtonState & : Return button state */
  373. /* dflt : NodeSpec ** : Return default case */
  374. /* (returns) : KBPopupMenu * : New popup menu */
  375. KBPopupMenu
  376. *KBTree::makeTreePopup
  377. ( QWidget *parent,
  378. QObject *receiver,
  379. Qt::ButtonState *bState,
  380. NodeSpec **dflt
  381. )
  382. {
  383. KBPopupMenu *tp = new KBPopupMenu (parent, bState) ;
  384. tp->insertItem
  385. ( TR("Table tree"),
  386. receiver,
  387. SLOT(newNode(int)),
  388. QKeySequence(),
  389. nodeSpecToId(&nodeSpecTable)
  390. ) ;
  391. tp->insertItem
  392. ( TR("Query tree"),
  393. receiver,
  394. SLOT(newNode(int)),
  395. QKeySequence(),
  396. nodeSpecToId(&nodeSpecQuery)
  397. ) ;
  398. tp->insertItem
  399. ( TR("SQL tree" ),
  400. receiver,
  401. SLOT(newNode(int)),
  402. QKeySequence(),
  403. nodeSpecToId(&nodeSpecSQL)
  404. ) ;
  405. *dflt = &nodeSpecTable ;
  406. return tp ;
  407. }
  408. NEWNODE(Tree, __TR("New &Tree"), makeTreePopup, KNF_FORM|KNF_BLOCK|KNF_DATA)