General Purpose Geodetic Library
SgGuiVlbiHistory.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include <QtCore/QRegExp>
24 
25 
26 #include <SgGuiVlbiHistory.h>
27 #include <SgLogger.h>
28 #include <SgVlbiHistory.h>
29 
30 
31 #if QT_VERSION >= 0x050000
32 # include <QtWidgets/QAction>
33 # include <QtWidgets/QBoxLayout>
34 # include <QtWidgets/QLabel>
35 # include <QtWidgets/QMenu>
36 # include <QtWidgets/QMessageBox>
37 # include <QtWidgets/QPushButton>
38 # include <QtWidgets/QShortcut>
39 #else
40 # include <QtGui/QAction>
41 # include <QtGui/QBoxLayout>
42 # include <QtGui/QLabel>
43 # include <QtGui/QMenu>
44 # include <QtGui/QMessageBox>
45 # include <QtGui/QPushButton>
46 # include <QtGui/QShortcut>
47 #endif
48 
49 
50 
51 
52 /*=======================================================================================================
53 *
54 * METHODS:
55 *
56 *======================================================================================================*/
57 SgGuiVlbiHistory::SgGuiVlbiHistory(SgVlbiHistory *history, QWidget* parent, Qt::WindowFlags f)
58  : QWidget(parent, f)
59 {
60  history_ = history;
61  QString str;
62  QBoxLayout *layout = new QVBoxLayout(this);
63 
64  twHistory_ = new QTreeWidget(this);
65  twHistory_->setColumnCount(3);
66 
67 //QBrush userRecordBrushF(QBrush(QColor(0, 140, 0)));
68  QBrush userRecordBrushF(QBrush(QColor(30, 90, 255)));
69  QBrush operatorRecordBrushF(QBrush(QColor(214, 61, 210)));
70 
71  QRegExp reUserComment("^\\w{2}>(.+)", Qt::CaseInsensitive);
72  QRegExp reOperatorComment("readLogFile: station ([\\w\\s-+_]{1,8}): "
73  "\\d{4}/\\d{2}/\\d{2}\\s+(.+)", Qt::CaseInsensitive);
74 
75 
76  QStringList headerLabels;
77  headerLabels
78 // << "Date (UTC)"
79  << "Date"
80  << "Ver"
81  << "Event"
82  ;
83  twHistory_->setHeaderLabels(headerLabels);
84  for (int i=0; i<history_->size(); i++)
85  {
86  SgVlbiHistoryRecord* rec = history_->at(i);
87 
89 
90  item->setText(0, rec->getEpoch().toLocal().toString(SgMJD::F_YYYYMMDDHHMMSSSS));
91  item->setData(0, Qt::TextAlignmentRole, Qt::AlignRight);
92  item->setData(0, Qt::UserRole, i); // == idx
93  item->setText(1, str.sprintf("%3d", rec->getVersion()));
94  item->setData(1, Qt::TextAlignmentRole, Qt::AlignRight);
95  item->setText(2, rec->getText());
96  item->setData(2, Qt::TextAlignmentRole, Qt::AlignLeft);
97  if (reUserComment.indexIn(rec->getText()) != -1)
98  {
99  QFont fnt=item->font(2);
100  fnt.setBold(true);
101  item->setFont(2, fnt);
102  item->setForeground(2, userRecordBrushF);
103  }
104  else if (reOperatorComment.indexIn(rec->getText()) != -1)
105  {
106  QFont fnt=item->font(2);
107  fnt.setBold(true);
108  item->setFont(2, fnt);
109  item->setForeground(2, operatorRecordBrushF);
110  };
111  };
112 
113  twHistory_->header()->resizeSections(QHeaderView::ResizeToContents);
114 #if QT_VERSION >= 0x050000
115  twHistory_->header()->setSectionResizeMode(QHeaderView::Interactive);
116 #else
117  twHistory_->header()->setResizeMode(QHeaderView::Interactive);
118 #endif
119  twHistory_->header()->setStretchLastSection(true);
120 
121  //twHistory_->setSortingEnabled(true);
122  //twHistory_->setUniformRowHeights(true);
123  twHistory_->setFocus();
124  twHistory_->setItemsExpandable(false);
125  twHistory_->setAllColumnsShowFocus(true);
126 
127  layout->addWidget(twHistory_);
128 
129  QBoxLayout *hLayout = new QHBoxLayout();
130  layout->addLayout(hLayout);
131 
132  historyLine_ = new QLineEdit(this);
133  QLabel *label = new QLabel("&Add a record:", this);
134  label->setBuddy(historyLine_);
135  label->setMinimumSize(label->sizeHint());
136  historyLine_->setMinimumHeight(historyLine_->sizeHint().height());
137  historyLine_->setMinimumWidth(10*historyLine_->fontMetrics().width("WWW") + 10);
138 
139  hLayout->addWidget(label);
140  hLayout->addWidget(historyLine_, 10);
141 
142  QPushButton *button = new QPushButton("Submit", this);
143  button->setMinimumSize(button->sizeHint());
144  button->setDefault(true);
145  hLayout->addWidget(button);
146  connect (button, SIGNAL(clicked()), SLOT(addHistoryLine()));
147  connect (historyLine_, SIGNAL(returnPressed()), SLOT(addHistoryLine()));
148 
149  QShortcut *shCut=new QShortcut(QKeySequence(QKeySequence::Delete), this);
150  connect(shCut, SIGNAL(activated()), this, SLOT(delHistoryLine()));
151 };
152 
153 
154 
155 //
157 {
158  QBrush newRecordBrush(Qt::blue);
159  QString str;
160  QString text = historyLine_->text();
161  if (text.simplified() != "")
162  {
163  int version=history_->last()->getVersion();
164  int idx=history_->size();
165  SgVlbiHistoryRecord *rec=new SgVlbiHistoryRecord(SgMJD::currentMJD(), version, text, true);
167  history_->append(rec);
168  //
169  if (0<idx && !history_->at(idx-1)->getIsEditable())
171 // item->setText(0, rec->getEpoch().toLocal().toString(SgMJD::F_YYYYMMDDHHMMSSSS));
172  item->setText(0, rec->getEpoch().toString(SgMJD::F_YYYYMMDDHHMMSSSS));
173  item->setData(0, Qt::TextAlignmentRole, Qt::AlignRight);
174  item->setData(0, Qt::ForegroundRole, newRecordBrush);
175  item->setData(0, Qt::UserRole, idx);
176 
177  item->setText(1, str.sprintf("%3d", rec->getVersion()));
178  item->setData(1, Qt::TextAlignmentRole, Qt::AlignRight);
179  item->setData(1, Qt::ForegroundRole, newRecordBrush);
180  item->setText(2, rec->getText());
181  item->setData(2, Qt::TextAlignmentRole, Qt::AlignLeft);
182  item->setData(2, Qt::ForegroundRole, newRecordBrush);
183 
184  historyLine_->setText("");
185  emit modified(true);
186  };
187 };
188 
189 
190 
191 //
193 {
194  QTreeWidgetItem *item=twHistory_->currentItem();
195  if (item)
196  {
197  bool isOk;
198  int idx=item->data(0, Qt::UserRole).toInt(&isOk);
199  if (isOk)
200  {
201  SgVlbiHistoryRecord *rec=history_->at(idx);
202  if (rec->getIsEditable())
203  {
204  if (QMessageBox::warning(this, "Warning",
205  "Are you sure to delete the history record?\nThe record was issued on " +
206  rec->getEpoch().toString() + ". It says:\n" + rec->getText(),
207  QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
208  {
210  ": delHistoryLine(): the history record \"" + rec->getText() + "\" sunk into oblivion");
211  //
212  // update first user's record (if necessary)
213  if (idx==0) // lonely record
215  else if (!history_->at(idx-1)->getIsEditable()) // this one was the first user's record
216  {
217  if (idx<history_->size()-1)
218  history_->setFirstRecordFromUser(history_->at(idx+1)->getText());
219  else
221  };
222  //
223  // remove from the list:
224  history_->removeAt(idx);
225  //
226  // adjust indices:
227  QTreeWidgetItem *it=twHistory_->itemBelow(item);
228  while (it)
229  {
230  it->setData(0, Qt::UserRole, idx++);
231  it = twHistory_->itemBelow(it);
232  };
233  delete rec;
234  delete item;
235  emit modified(true);
236  };
237  };
238  };
239  };
240 };
241 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
QLineEdit * historyLine_
virtual QString className() const
QTreeWidget * twHistory_
SgVlbiHistory * history_
SgGuiVlbiHistory(SgVlbiHistory *, QWidget *=0, Qt::WindowFlags=0)
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ SESSION
Definition: SgLogger.h:77
@ F_YYYYMMDDHHMMSSSS
Long verbose: Fri, the 2nd of Apr, 2010; 17hr 02min 43.6400sec.
Definition: SgMJD.h:67
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1007
static SgMJD currentMJD()
Definition: SgMJD.cpp:118
SgMJD toLocal() const
Definition: SgMJD.cpp:1246
int getVersion() const
bool getIsEditable() const
const SgMJD & getEpoch() const
const QString & getText() const
void setFirstRecordFromUser(const QString &)