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"
79  << "Ver"
80  << "Event"
81  ;
82  twHistory_->setHeaderLabels(headerLabels);
83  for (int i=0; i<history_->size(); i++)
84  {
85  SgVlbiHistoryRecord* rec = history_->at(i);
86 
88 
89  item->setText(0, rec->getEpoch().toLocal().toString(SgMJD::F_YYYYMMDDHHMMSSSS));
90  item->setData(0, Qt::TextAlignmentRole, Qt::AlignRight);
91  item->setData(0, Qt::UserRole, i); // == idx
92  item->setText(1, str.sprintf("%3d", rec->getVersion()));
93  item->setData(1, Qt::TextAlignmentRole, Qt::AlignRight);
94  item->setText(2, rec->getText());
95  item->setData(2, Qt::TextAlignmentRole, Qt::AlignLeft);
96  if (reUserComment.indexIn(rec->getText()) != -1)
97  {
98  QFont fnt=item->font(2);
99  fnt.setBold(true);
100  item->setFont(2, fnt);
101  item->setForeground(2, userRecordBrushF);
102  }
103  else if (reOperatorComment.indexIn(rec->getText()) != -1)
104  {
105  QFont fnt=item->font(2);
106  fnt.setBold(true);
107  item->setFont(2, fnt);
108  item->setForeground(2, operatorRecordBrushF);
109  };
110  };
111 
112  twHistory_->header()->resizeSections(QHeaderView::ResizeToContents);
113 #if QT_VERSION >= 0x050000
114  twHistory_->header()->setSectionResizeMode(QHeaderView::Interactive);
115 #else
116  twHistory_->header()->setResizeMode(QHeaderView::Interactive);
117 #endif
118  twHistory_->header()->setStretchLastSection(true);
119 
120  //twHistory_->setSortingEnabled(true);
121  //twHistory_->setUniformRowHeights(true);
122  twHistory_->setFocus();
123  twHistory_->setItemsExpandable(false);
124  twHistory_->setAllColumnsShowFocus(true);
125 
126  layout->addWidget(twHistory_);
127 
128  QBoxLayout *hLayout = new QHBoxLayout();
129  layout->addLayout(hLayout);
130 
131  historyLine_ = new QLineEdit(this);
132  QLabel *label = new QLabel("&Add a record:", this);
133  label->setBuddy(historyLine_);
134  label->setMinimumSize(label->sizeHint());
135  historyLine_->setMinimumHeight(historyLine_->sizeHint().height());
136  historyLine_->setMinimumWidth(10*historyLine_->fontMetrics().width("WWW") + 10);
137 
138  hLayout->addWidget(label);
139  hLayout->addWidget(historyLine_, 10);
140 
141  QPushButton *button = new QPushButton("Submit", this);
142  button->setMinimumSize(button->sizeHint());
143  button->setDefault(true);
144  hLayout->addWidget(button);
145  connect (button, SIGNAL(clicked()), SLOT(addHistoryLine()));
146  connect (historyLine_, SIGNAL(returnPressed()), SLOT(addHistoryLine()));
147 
148  QShortcut *shCut=new QShortcut(QKeySequence(QKeySequence::Delete), this);
149  connect(shCut, SIGNAL(activated()), this, SLOT(delHistoryLine()));
150 };
151 
152 
153 
154 //
156 {
157  QBrush newRecordBrush(Qt::blue);
158  QString str;
159  QString text = historyLine_->text();
160  if (text.simplified() != "")
161  {
162  int version=history_->last()->getVersion();
163  int idx=history_->size();
164  SgVlbiHistoryRecord *rec=new SgVlbiHistoryRecord(SgMJD::currentMJD(), version, text, true);
166  history_->append(rec);
167  //
168  if (0<idx && !history_->at(idx-1)->getIsEditable())
170 // item->setText(0, rec->getEpoch().toLocal().toString(SgMJD::F_YYYYMMDDHHMMSSSS));
171  item->setText(0, rec->getEpoch().toString(SgMJD::F_YYYYMMDDHHMMSSSS));
172  item->setData(0, Qt::TextAlignmentRole, Qt::AlignRight);
173  item->setData(0, Qt::ForegroundRole, newRecordBrush);
174  item->setData(0, Qt::UserRole, idx);
175 
176  item->setText(1, str.sprintf("%3d", rec->getVersion()));
177  item->setData(1, Qt::TextAlignmentRole, Qt::AlignRight);
178  item->setData(1, Qt::ForegroundRole, newRecordBrush);
179  item->setText(2, rec->getText());
180  item->setData(2, Qt::TextAlignmentRole, Qt::AlignLeft);
181  item->setData(2, Qt::ForegroundRole, newRecordBrush);
182 
183  historyLine_->setText("");
184  emit modified(true);
185  };
186 };
187 
188 
189 
190 //
192 {
193  QTreeWidgetItem *item=twHistory_->currentItem();
194  if (item)
195  {
196  bool isOk;
197  int idx=item->data(0, Qt::UserRole).toInt(&isOk);
198  if (isOk)
199  {
200  SgVlbiHistoryRecord *rec=history_->at(idx);
201  if (rec->getIsEditable())
202  {
203  if (QMessageBox::warning(this, "Warning",
204  "Are you sure to delete the history record?\nThe record was issued on " +
205  rec->getEpoch().toString() + ". It says:\n" + rec->getText(),
206  QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
207  {
209  ": delHistoryLine(): the history record \"" + rec->getText() + "\" sunk into oblivion");
210  //
211  // update first user's record (if necessary)
212  if (idx==0) // lonely record
214  else if (!history_->at(idx-1)->getIsEditable()) // this one was the first user's record
215  {
216  if (idx<history_->size()-1)
217  history_->setFirstRecordFromUser(history_->at(idx+1)->getText());
218  else
220  };
221  //
222  // remove from the list:
223  history_->removeAt(idx);
224  //
225  // adjust indices:
226  QTreeWidgetItem *it=twHistory_->itemBelow(item);
227  while (it)
228  {
229  it->setData(0, Qt::UserRole, idx++);
230  it = twHistory_->itemBelow(it);
231  };
232  delete rec;
233  delete item;
234  emit modified(true);
235  };
236  };
237  };
238  };
239 };
240 /*=====================================================================================================*/
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:1008
static SgMJD currentMJD()
Definition: SgMJD.cpp:119
SgMJD toLocal() const
Definition: SgMJD.cpp:1247
int getVersion() const
bool getIsEditable() const
const SgMJD & getEpoch() const
const QString & getText() const
void setFirstRecordFromUser(const QString &)