7#include "captureprocessoverlay.h"
11CaptureProcessOverlay::CaptureProcessOverlay(
QWidget *parent) :
QWidget(parent)
15 setStyleSheet(
"color: rgb(255, 255, 255);");
18 captureHistory().updateTargetStatistics();
22 displayTargetStatistics();
26void CaptureProcessOverlay::refresh()
30 displayTargetStatistics();
33bool CaptureProcessOverlay::addFrameData(FrameData data,
const QString &devicename)
35 if (m_captureHistory[devicename].addFrame(data) ==
false)
42void CaptureProcessOverlay::updateFrameData()
45 if (hasFrames() ==
false)
47 frameDataWidget->setVisible(
false);
50 frameDataWidget->setVisible(
true);
51 const FrameData currentFrame = captureHistory().
currentFrame();
52 frameTypeLabel->setText(
QString(
"%1 %2").arg(CCDFrameTypeNames[currentFrame.frameType]).
arg(currentFrame.filterName));
53 exposureValue->setText(
QString(
"%1 sec").arg(currentFrame.exptime, 0,
'f',
54 currentFrame.exptime < 1 ? 2 : currentFrame.exptime < 5 ? 1 : 0));
55 binningValue->setText(
QString(
"%1x%2").arg(currentFrame.binning.x()).
arg(currentFrame.binning.y()));
56 filenameValue->setText(currentFrame.filename);
57 geometryValue->setText(
QString(
"%1px x %2px").arg(currentFrame.width).
arg(currentFrame.height));
59 bool visible = (currentFrame.gain >= 0);
62 gainValue->setText(
QString(
"%1").arg(currentFrame.gain, 0,
'f', 1));
64 visible = (currentFrame.offset >= 0);
65 offsetLabel->setVisible(
visible);
66 offsetValue->setVisible(
visible);
67 offsetValue->setText(
QString(
"%1").arg(currentFrame.offset, 0,
'f', 1));
69 visible = (currentFrame.iso !=
"");
71 isoValue->setText(
QString(
"ISO %1").arg(currentFrame.iso));
73 visible = (currentFrame.targetdrift >= 0);
74 targetDriftLabel->setVisible(
visible);
75 targetDriftValue->setVisible(
visible);
76 targetDriftValue->setText(
QString(
"%L1\"").arg(currentFrame.targetdrift, 0,
'f', 1));
79 QFileInfo fileinfo(currentFrame.filename);
80 const QDateTime lastmodified = fileinfo.lastModified();
81 captureDate->setText(lastmodified.
toString(
"dd.MM.yyyy hh:mm:ss"));
84 if (captureHistory().
size() > 0)
85 historyCountsLabel->setText(
QString(
"(%1/%2)").arg(captureHistory().position() + 1).arg(captureHistory().
size()));
87 historyCountsLabel->setText(
"");
90 historyBackwardButton->setEnabled(captureHistory().
size() > 0 && captureHistory().position() > 0);
91 historyForwardButton->setEnabled(captureHistory().
size() > 0 && captureHistory().
size() - captureHistory().position() > 1);
94void CaptureProcessOverlay::updateTargetDistance(
double targetDiff)
97 FrameData lastFrame = captureHistory().
getFrame(captureHistory().
size() - 1);
98 lastFrame.targetdrift = targetDiff;
100 captureHistory().
addFrame(lastFrame);
104bool CaptureProcessOverlay::hasFrames()
106 if (m_captureHistory.contains(m_currentTrainName))
107 return m_captureHistory[m_currentTrainName].size() > 0;
112void CaptureProcessOverlay::displayTargetStatistics()
119 display.
append(
QString(
"<p><b><u>%1</u></b><table border=0>").arg(*target_it ==
"" ?
"<it>" +
i18n(
"No target") +
"</it>" :
124 for (
QList<QPair<CCDFrameType, QString>>::iterator key_it = keys.
begin(); key_it != keys.
end(); key_it++)
127 QString frame_type = CCDFrameTypeNames[key_it->first];
132 for (
QList<QPair<int, int>*>::iterator it = counts.
begin(); it != counts.
end(); it++)
134 double exptime = (*it)->first / 1000.0;
135 QTime total(0, 0, 0, 0);
136 total = total.addMSecs(
int((*it)->first * (*it)->second));
137 display.
append(
QString(
"<tr><td><b>%1 %2</b> (%3 x %4 sec):</td><td style=\"text-align: right\">%5</td></tr>")
138 .arg(frame_type).arg(filter)
140 .
arg(exptime, 0,
'f', exptime < 10 ? 2 : 0)
141 .
arg(total.toString(
"hh:mm:ss")));
144 display.
append(
"</table></p>");
147 captureStatisticsLabel->setText(display);
150bool CaptureProcessOverlay::showNextFrame()
152 if (captureHistory().
forward())
160bool CaptureProcessOverlay::showPreviousFrame()
162 if (captureHistory().backward())
170bool CaptureProcessOverlay::deleteFrame(
int pos)
172 if (captureHistory().deleteFrame(
pos) ==
true)
176 displayTargetStatistics();
182void CaptureProcessOverlay::setCurrentTrainName(
const QString &trainname)
184 m_currentTrainName = trainname;
192 if (it->filename == data.filename)
197 m_position = m_history.
size() - 1;
198 countNewFrame(data.target, data.frameType, data.filterName, data.exptime);
204 if (m_history.size() != 0 &&
pos < m_history.size())
206 m_history.removeAt(
pos);
208 if (m_position >=
pos)
211 if (m_position < 0 && m_history.size() > 0)
213 else if (m_position >= m_history.size())
214 m_position = m_history.size() - 1;
216 updateTargetStatistics();
231 if (m_position < m_history.size() - 1)
261 countNewFrame(list_it->target, list_it->frameType, list_it->filterName, list_it->exptime);
262 new_history.
append(*list_it);
267 m_history = new_history;
270 if (m_position >= m_history.size())
271 m_position = m_history.
size() - 1;
274void CaptureProcessOverlay::CaptureHistory::countNewFrame(
QString target, CCDFrameType frameType,
QString filter,
278 QPair<CCDFrameType, QString> key(frameType, filter);
280 int exptime_r = int(exptime * 1000);
282 if (statistics.contains(target) ==
false)
285 if (statistics[target].contains(key) ==
false)
286 statistics[target].insert(key,
QList<QPair<int, int>*>());
288 QPair<int, int>* count =
nullptr;
290 for (
QList<QPair<int, int>*>::iterator it = counts->
begin(); it != counts->
end(); it++)
293 if ((*it)->first == exptime_r)
300 if (count ==
nullptr)
302 count =
new QPair<int, int>(exptime_r, 0);
306 count->second = count->second + 1;
bool deleteFrame(int pos)
Delete the current frame and (if possible) the corresponding file.
bool forward()
Move one step forward in the history.
bool addFrame(FrameData data)
Add a newly captured frame to the history.
void reset()
Reset the history.
bool backward()
Move one step backwards in the history.
const FrameData currentFrame()
the currently pointed capture frame
const FrameData getFrame(int pos)
Obtain the frame from the given position in the history.
void updateTargetStatistics()
Iterate over the current target history and add all those where the corresponding file exists.
QString i18n(const char *text, const TYPE &arg...)
KGuiItem forward(BidiMode useBidi=IgnoreRTL)
QString toString(QStringView format, QCalendar cal) const const
bool exists(const QString &fileName)
void append(QList< T > &&value)
qsizetype size() const const
QList< Key > keys() const const
T value(const Key &key, const T &defaultValue) const const
QString & append(QChar ch)
QString arg(Args &&... args) const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)