~vbursian/research-assistant/intervers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
////////////////////////////////////////////////////////////////////////////////
/*! @file Plot.cpp   Виджет для показа графиков с легендой.
- Part of RAGUI - Research Assistant Graphical User Interface.
- Uses  QtGui v.4.6  -  http://qt.nokia.com/
- Uses  RANet - Research Assistant Net Library (based on ANSI C++).
- Copyright(C) 2010, Viktor E. Bursian, St.Petersburg, Russia.
                     Viktor.Bursian@mail.ioffe.ru
*///////////////////////////////////////////////////////////////////////////////
#include "Plot.h"
#include "BasicNodes.h"
#include "NetOps.h"
#include <QMenuBar>
namespace RA {
//------------------------------------------------------------------------------

sPlot::~sPlot()
{
  if( Legend ){ delete Legend;  Legend=NULL; };
  if( Chart ){ delete Chart;  Chart=NULL; };
  if( Evolution ){ delete Evolution;  Evolution=NULL; };
};


sPlot::sPlot (sNodePtr       Config
             ,sString        DefaultTitle)
    :sRASubwidget(Config,DefaultTitle)
{
  Layout = new QHBoxLayout(this);
  Layout->setMargin(0);
  Splitter = new QSplitter(this);
  Splitter->setOrientation(Qt::Vertical);

  sCluster::sPtr              root(WidgetConfig->GetAttr("Content"));
  ASSERT(root.IsCorrect());
  sAttribute          RootAttr (Title()
                               ,root
                               ,sCluster::Type()   );
  Evolution = new sNet2TreeEvolution(RootAttr);
  Chart = new sChart(Evolution ,this);
  Legend = new sNavigator(Evolution ,this);

  Splitter->addWidget(Chart);
  Splitter->addWidget(Legend);
  Layout->addWidget(Splitter);

//  Legend->setMinimumSize(80,80);

  connect(Chart ,SIGNAL(CursorPositionChanged(sPhysPair,sPhysPair
                                             ,sString,sString))
         ,this  ,SIGNAL(CursorPositionChanged(sPhysPair,sPhysPair
                                             ,sString,sString)));
  //! @todo{elegancy} не логичнее ли перенести это связывание в главное окно?
  connect(this  ,SIGNAL(CursorPositionChanged(sPhysPair,sPhysPair
                                             ,sString,sString))
         ,MainWindow ,SLOT(ShowCursorInfo(sPhysPair,sPhysPair
                                             ,sString,sString)));

  connect(Evolution,SIGNAL(Changed()),Legend,SLOT(OnNetChange()));
  connect(Evolution,SIGNAL(Changed()),Chart,SLOT(OnNetChange()));
  Evolution->Initiate();
  UpdatingTimer = new QTimer(this);
  connect(UpdatingTimer, SIGNAL(timeout()), Evolution, SLOT(Update()));
  UpdatingTimer->start(sNavigator::UpdatingPeriod);

  Chart->AllowCurveDrops();

  QActionGroup *              AG = new QActionGroup(this);
  ActionLegentBottom = new QAction(QIcon(":RAGUI/LegendBottom")
                                  ,"Legend at the bottom",AG);
  ActionLegentBottom->setCheckable(true);
  ActionLegentBottom->setChecked(true);
  connect(ActionLegentBottom,SIGNAL(toggled(bool))
         ,this,SLOT(PutLegendAtTheBottom(bool)));
  addAction(ActionLegentBottom);
  ActionLegentRight = new QAction(QIcon(":RAGUI/LegendRight")
                                 ,"Legend on the right",AG);
  ActionLegentRight->setCheckable(true);
  addAction(ActionLegentRight);

//  MenuExtension = new QMenu("PLOT",this);
//  MenuExtension->addActions(Chart->actions());
//  QMenu * ML = MenuExtension->addMenu("Legend");
//  ML->addActions(AG->actions());
};


const QIcon &  sPlot::Icon ()
{
  static QIcon *  MyIcon = new QIcon(":/RAGUI/plot_icon");
  return *MyIcon;
};


void  sPlot::RestoreState ()
{
  sRASubwidget::RestoreState();
  if( ! WidgetConfig.IsNULL() ){
    sIntegerNode::sPtr        I;
    sIntegerNode::sPtr        I1;
    sIntegerNode::sPtr        I2;

    I=WidgetConfig->GetAttr("Splitter.Orientation");
    if( I.IsCorrect() ){
      Splitter->setOrientation(Qt::Orientation( (int)(*I) ));
      ActionLegentBottom->setChecked(Splitter->orientation() == Qt::Vertical);
      ActionLegentRight->setChecked(Splitter->orientation() == Qt::Horizontal);
    };
    I1=WidgetConfig->GetAttr("Splitter.Part1");
    I2=WidgetConfig->GetAttr("Splitter.Part2");
    if( I1.IsCorrect() && I2.IsCorrect() ){
      QList<int>    List;
      List.append( (int)(*I1) );
      List.append( (int)(*I2) );
      Splitter->setSizes(List);
    };

    Chart->RestoreScales(WidgetConfig);
  };
};


void  sPlot::StoreState ()
{
  sRASubwidget::StoreState();
  if( ! WidgetConfig.IsNULL() ){
    WidgetConfig << attr("Splitter.Orientation",Splitter->orientation());
    WidgetConfig << attr("Splitter.Part1",Splitter->sizes().at(0));
    WidgetConfig << attr("Splitter.Part2",Splitter->sizes().at(1));
    Chart->StoreScales(WidgetConfig);
  };
};


bool  sPlot::CanClose ()
{
  return true;
};


void  sPlot::focusInEvent (QFocusEvent *  event)
{
  /* во-первых, место занимает;
     во-вторых, тулбары можно показать/спрятать через
     автоматическое контекстное меню (на тулбарах, доках, меню)
  if( MainWindow->ToolBarPlot ){
    MainWindow->ToolBarPlot->clear();
    MainWindow->ToolBarPlot->addActions(actions());
    MainWindow->ToolBarPlot->addSeparator();
    MainWindow->ToolBarPlot->addActions(Chart->actions());
    MainWindow->ToolBarPlot->setVisible(true);
  };
  */
  /*
  PA = MainWindow->menuBar()->addMenu(MenuExtension);
  */
  sRASubwidget::focusInEvent(event);
};


void  sPlot::focusOutEvent (QFocusEvent *  event)
{
  /*
  if( MainWindow->ToolBarPlot ){
    MainWindow->ToolBarPlot->setVisible(false);
  };
  */
  /*
  MainWindow->menuBar()->removeAction(PA);
  */
  sRASubwidget::focusOutEvent(event);
};


void  sPlot::contextMenuEvent (QContextMenuEvent *  event)
{
  QMenu                       PopupMenu/*(this)*/;
  PopupMenu.addActions(actions());
  PopupMenu.exec(event->globalPos());
};


void  sPlot::PutLegendAtTheBottom (bool  AtTheBottom)
{
  if( AtTheBottom ){
    Splitter->setOrientation(Qt::Vertical);
  }else{
    Splitter->setOrientation(Qt::Horizontal);
  };
};

//------------------------------------------------------------------------------
}; //namespace RA