GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
QGo4CommandsHistory.cpp
Go to the documentation of this file.
1 // $Id: QGo4CommandsHistory.cpp 2819 2020-05-13 12:22:20Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "QGo4CommandsHistory.h"
15 
16 #include <QKeyEvent>
17 
18 #define GO4_COMHIS_MAX 50
19 
20 
21 QGo4CommandsHistory::QGo4CommandsHistory(QWidget* w, const char* name) :
22  QComboBox(w)
23 {
24  setObjectName(name ? name : "Go4CommandsHistory");
25  setMaxCount(GO4_COMHIS_MAX);
26  setInsertPolicy(InsertAtTop);
27  setDuplicatesEnabled(false);
28  setEditable(true);
29  // setAutoCompletion(true); // not needed, by default is auto-completion is enabled, this is deprecated method
30 }
31 
33 {
34 }
35 
37 {
38  if ( (e->key()==Qt::Key_Return) || (e->key()==Qt::Key_Enter) ){
39  if(count()>=GO4_COMHIS_MAX) setInsertPolicy(InsertAtCurrent); // overwrite last command
40  emit enterPressedSingal();
41  }
42 
43  QComboBox::keyPressEvent(e);
44 }
45 
46 QStringList QGo4CommandsHistory::getHistory(int max)
47 {
48  QStringList lst;
49  if (max>count()) max = count();
50 
51  for(int i=0; i<max; i++)
52  lst.append(itemText(i));
53 
54  return lst;
55 }
QStringList getHistory(int max=50)
QGo4CommandsHistory(QWidget *w, const char *name=0)
virtual void keyPressEvent(QKeyEvent *e)
#define GO4_COMHIS_MAX