qwt_picker_machine.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_picker_machine.h"
11 #include "qwt_event_pattern.h"
12 #include <qevent.h>
13 
16  d_selectionType( type ),
17  d_state( 0 )
18 {
19 }
20 
23 {
24 }
25 
28 {
29  return d_selectionType;
30 }
31 
34 {
35  return d_state;
36 }
37 
40 {
41  d_state = state;
42 }
43 
46 {
47  setState( 0 );
48 }
49 
53 {
54 }
55 
57 QList<QwtPickerMachine::Command> QwtPickerTrackerMachine::transition(
58  const QwtEventPattern &, const QEvent *e )
59 {
60  QList<QwtPickerMachine::Command> cmdList;
61 
62  switch ( e->type() )
63  {
64  case QEvent::Enter:
65  case QEvent::MouseMove:
66  {
67  if ( state() == 0 )
68  {
69  cmdList += Begin;
70  cmdList += Append;
71  setState( 1 );
72  }
73  else
74  {
75  cmdList += Move;
76  }
77  break;
78  }
79  case QEvent::Leave:
80  {
81  cmdList += Remove;
82  cmdList += End;
83  setState( 0 );
84  }
85  default:
86  break;
87  }
88 
89  return cmdList;
90 }
91 
95 {
96 }
97 
99 QList<QwtPickerMachine::Command> QwtPickerClickPointMachine::transition(
100  const QwtEventPattern &eventPattern, const QEvent *event )
101 {
102  QList<QwtPickerMachine::Command> cmdList;
103 
104  switch ( event->type() )
105  {
106  case QEvent::MouseButtonPress:
107  {
108  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
109  static_cast<const QMouseEvent *>( event ) ) )
110  {
111  cmdList += Begin;
112  cmdList += Append;
113  cmdList += End;
114  }
115  break;
116  }
117  case QEvent::KeyPress:
118  {
119  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
120  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
121  {
122  if ( !keyEvent->isAutoRepeat() )
123  {
124  cmdList += Begin;
125  cmdList += Append;
126  cmdList += End;
127  }
128  }
129  break;
130  }
131  default:
132  break;
133  }
134 
135  return cmdList;
136 }
137 
141 {
142 }
143 
145 QList<QwtPickerMachine::Command> QwtPickerDragPointMachine::transition(
146  const QwtEventPattern &eventPattern, const QEvent *event )
147 {
148  QList<QwtPickerMachine::Command> cmdList;
149 
150  switch ( event->type() )
151  {
152  case QEvent::MouseButtonPress:
153  {
154  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
155  static_cast<const QMouseEvent *>( event ) ) )
156  {
157  if ( state() == 0 )
158  {
159  cmdList += Begin;
160  cmdList += Append;
161  setState( 1 );
162  }
163  }
164  break;
165  }
166  case QEvent::MouseMove:
167  case QEvent::Wheel:
168  {
169  if ( state() != 0 )
170  cmdList += Move;
171  break;
172  }
173  case QEvent::MouseButtonRelease:
174  {
175  if ( state() != 0 )
176  {
177  cmdList += End;
178  setState( 0 );
179  }
180  break;
181  }
182  case QEvent::KeyPress:
183  {
184  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
185  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
186  {
187  if ( !keyEvent->isAutoRepeat() )
188  {
189  if ( state() == 0 )
190  {
191  cmdList += Begin;
192  cmdList += Append;
193  setState( 1 );
194  }
195  else
196  {
197  cmdList += End;
198  setState( 0 );
199  }
200  }
201  }
202  break;
203  }
204  default:
205  break;
206  }
207 
208  return cmdList;
209 }
210 
214 {
215 }
216 
218 QList<QwtPickerMachine::Command> QwtPickerClickRectMachine::transition(
219  const QwtEventPattern &eventPattern, const QEvent *event )
220 {
221  QList<QwtPickerMachine::Command> cmdList;
222 
223  switch ( event->type() )
224  {
225  case QEvent::MouseButtonPress:
226  {
227  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
228  static_cast<const QMouseEvent *>( event ) ) )
229  {
230  switch ( state() )
231  {
232  case 0:
233  {
234  cmdList += Begin;
235  cmdList += Append;
236  setState( 1 );
237  break;
238  }
239  case 1:
240  {
241  // Uh, strange we missed the MouseButtonRelease
242  break;
243  }
244  default:
245  {
246  cmdList += End;
247  setState( 0 );
248  }
249  }
250  }
251  break;
252  }
253  case QEvent::MouseMove:
254  case QEvent::Wheel:
255  {
256  if ( state() != 0 )
257  cmdList += Move;
258  break;
259  }
260  case QEvent::MouseButtonRelease:
261  {
262  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
263  static_cast<const QMouseEvent *>( event ) ) )
264  {
265  if ( state() == 1 )
266  {
267  cmdList += Append;
268  setState( 2 );
269  }
270  }
271  break;
272  }
273  case QEvent::KeyPress:
274  {
275  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
276  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
277  {
278  if ( !keyEvent->isAutoRepeat() )
279  {
280  if ( state() == 0 )
281  {
282  cmdList += Begin;
283  cmdList += Append;
284  setState( 1 );
285  }
286  else
287  {
288  if ( state() == 1 )
289  {
290  cmdList += Append;
291  setState( 2 );
292  }
293  else if ( state() == 2 )
294  {
295  cmdList += End;
296  setState( 0 );
297  }
298  }
299  }
300  }
301  break;
302  }
303  default:
304  break;
305  }
306 
307  return cmdList;
308 }
309 
313 {
314 }
315 
317 QList<QwtPickerMachine::Command> QwtPickerDragRectMachine::transition(
318  const QwtEventPattern &eventPattern, const QEvent *event )
319 {
320  QList<QwtPickerMachine::Command> cmdList;
321 
322  switch ( event->type() )
323  {
324  case QEvent::MouseButtonPress:
325  {
326  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
327  static_cast<const QMouseEvent *>( event ) ) )
328  {
329  if ( state() == 0 )
330  {
331  cmdList += Begin;
332  cmdList += Append;
333  cmdList += Append;
334  setState( 2 );
335  }
336  }
337  break;
338  }
339  case QEvent::MouseMove:
340  case QEvent::Wheel:
341  {
342  if ( state() != 0 )
343  cmdList += Move;
344  break;
345  }
346  case QEvent::MouseButtonRelease:
347  {
348  if ( state() == 2 )
349  {
350  cmdList += End;
351  setState( 0 );
352  }
353  break;
354  }
355  case QEvent::KeyPress:
356  {
357  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
358  static_cast<const QKeyEvent *> ( event ) ) )
359  {
360  if ( state() == 0 )
361  {
362  cmdList += Begin;
363  cmdList += Append;
364  cmdList += Append;
365  setState( 2 );
366  }
367  else
368  {
369  cmdList += End;
370  setState( 0 );
371  }
372  }
373  break;
374  }
375  default:
376  break;
377  }
378 
379  return cmdList;
380 }
381 
385 {
386 }
387 
389 QList<QwtPickerMachine::Command> QwtPickerPolygonMachine::transition(
390  const QwtEventPattern &eventPattern, const QEvent *event )
391 {
392  QList<QwtPickerMachine::Command> cmdList;
393 
394  switch ( event->type() )
395  {
396  case QEvent::MouseButtonPress:
397  {
398  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
399  static_cast<const QMouseEvent *>( event ) ) )
400  {
401  if ( state() == 0 )
402  {
403  cmdList += Begin;
404  cmdList += Append;
405  cmdList += Append;
406  setState( 1 );
407  }
408  else
409  {
410  cmdList += Append;
411  }
412  }
413  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect2,
414  static_cast<const QMouseEvent *>( event ) ) )
415  {
416  if ( state() == 1 )
417  {
418  cmdList += End;
419  setState( 0 );
420  }
421  }
422  break;
423  }
424  case QEvent::MouseMove:
425  case QEvent::Wheel:
426  {
427  if ( state() != 0 )
428  cmdList += Move;
429  break;
430  }
431  case QEvent::KeyPress:
432  {
433  const QKeyEvent *keyEvent = static_cast<const QKeyEvent *> ( event );
434  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1, keyEvent ) )
435  {
436  if ( !keyEvent->isAutoRepeat() )
437  {
438  if ( state() == 0 )
439  {
440  cmdList += Begin;
441  cmdList += Append;
442  cmdList += Append;
443  setState( 1 );
444  }
445  else
446  {
447  cmdList += Append;
448  }
449  }
450  }
451  else if ( eventPattern.keyMatch( QwtEventPattern::KeySelect2, keyEvent ) )
452  {
453  if ( !keyEvent->isAutoRepeat() )
454  {
455  if ( state() == 1 )
456  {
457  cmdList += End;
458  setState( 0 );
459  }
460  }
461  }
462  break;
463  }
464  default:
465  break;
466  }
467 
468  return cmdList;
469 }
470 
474 {
475 }
476 
478 QList<QwtPickerMachine::Command> QwtPickerDragLineMachine::transition(
479  const QwtEventPattern &eventPattern, const QEvent *event )
480 {
481  QList<QwtPickerMachine::Command> cmdList;
482 
483  switch( event->type() )
484  {
485  case QEvent::MouseButtonPress:
486  {
487  if ( eventPattern.mouseMatch( QwtEventPattern::MouseSelect1,
488  static_cast<const QMouseEvent *>( event ) ) )
489  {
490  if ( state() == 0 )
491  {
492  cmdList += Begin;
493  cmdList += Append;
494  cmdList += Append;
495  setState( 1 );
496  }
497  }
498  break;
499  }
500  case QEvent::KeyPress:
501  {
502  if ( eventPattern.keyMatch( QwtEventPattern::KeySelect1,
503  static_cast<const QKeyEvent *> ( event ) ) )
504  {
505  if ( state() == 0 )
506  {
507  cmdList += Begin;
508  cmdList += Append;
509  cmdList += Append;
510  setState( 1 );
511  }
512  else
513  {
514  cmdList += End;
515  setState( 0 );
516  }
517  }
518  break;
519  }
520  case QEvent::MouseMove:
521  case QEvent::Wheel:
522  {
523  if ( state() != 0 )
524  cmdList += Move;
525 
526  break;
527  }
528  case QEvent::MouseButtonRelease:
529  {
530  if ( state() != 0 )
531  {
532  cmdList += End;
533  setState( 0 );
534  }
535  }
536  default:
537  break;
538  }
539 
540  return cmdList;
541 }
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
QwtPickerDragLineMachine()
Constructor.
QwtPickerClickRectMachine()
Constructor.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
The state machine not usable for any type of selection.
QwtPickerMachine(SelectionType)
Constructor.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
void reset()
Set the current state to 0.
void setState(int)
Change the current state.
The state machine is for selecting a polygon (many points).
The state machine is for selecting a single point.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
A state machine for QwtPicker selections.
virtual ~QwtPickerMachine()
Destructor.
bool mouseMatch(MousePatternCode, const QMouseEvent *) const
Compare a mouse event with an event pattern.
QwtPickerDragPointMachine()
Constructor.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
A collection of event patterns.
bool keyMatch(KeyPatternCode, const QKeyEvent *) const
Compare a key event with an event pattern.
SelectionType selectionType() const
Return the selection type.
const SelectionType d_selectionType
QwtPickerClickPointMachine()
Constructor.
QwtPickerTrackerMachine()
Constructor.
int state() const
Return the current state.
virtual QList< Command > transition(const QwtEventPattern &, const QEvent *)
Transition.
QwtPickerDragRectMachine()
Constructor.
QwtPickerPolygonMachine()
Constructor.
The state machine is for selecting a rectangle (2 points).


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17