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 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
//---------------------------------------------------------------------------
#include <QShortcutEvent>
#include <QCompleter>
#include <QFileSystemModel>
#include <QFileDialog>
#include "rtklib.h"
#include "serioptdlg.h"
#include "cmdoptdlg.h"
#include "fileoptdlg.h"
#include "tcpoptdlg.h"
#include "outstrdlg.h"
#include "keydlg.h"
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
OutputStrDialog::OutputStrDialog(QWidget* parent)
: QDialog(parent)
{
setupUi(this);
keyDialog = new KeyDialog(this);
serialOptDialog = new SerialOptDialog(this);
tcpOptDialog = new TcpOptDialog(this);
QCompleter *fileCompleter=new QCompleter(this);
QFileSystemModel *fileModel=new QFileSystemModel(fileCompleter);
fileModel->setRootPath("");
fileCompleter->setModel(fileModel);
FilePath1->setCompleter(fileCompleter);
FilePath2->setCompleter(fileCompleter);
connect(BtnCancel,SIGNAL(clicked(bool)),this,SLOT(reject()));
connect(BtnFile1,SIGNAL(clicked(bool)),this,SLOT(BtnFile1Click()));
connect(BtnFile2,SIGNAL(clicked(bool)),this,SLOT(BtnFile2Click()));
connect(BtnKey,SIGNAL(clicked(bool)),this,SLOT(BtnKeyClick()));
connect(BtnOk,SIGNAL(clicked(bool)),this,SLOT(BtnOkClick()));
connect(BtnStr1,SIGNAL(clicked(bool)),this,SLOT(BtnStr1Click()));
connect(BtnStr2,SIGNAL(clicked(bool)),this,SLOT(BtnStr2Click()));
connect(Stream1,SIGNAL(currentIndexChanged(int)),this,SLOT(Stream1Change(int)));
connect(Stream2,SIGNAL(currentIndexChanged(int)),this,SLOT(Stream2Change(int)));
connect(Stream1C,SIGNAL(clicked(bool)),this,SLOT(Stream1CClick()));
connect(Stream2C,SIGNAL(clicked(bool)),this,SLOT(Stream2CClick()));
SwapIntv->setValidator(new QDoubleValidator());
}
//---------------------------------------------------------------------------
void OutputStrDialog::showEvent(QShowEvent *event)
{
if (event->spontaneous()) return;
Stream1C ->setChecked(StreamC[0]);
Stream2C ->setChecked(StreamC[1]);
Stream1 ->setCurrentIndex(Stream[0]);
Stream2 ->setCurrentIndex(Stream[1]);
Format1 ->setCurrentIndex(Format[0]);
Format2 ->setCurrentIndex(Format[1]);
FilePath1->setText(GetFilePath(Paths[0][2]));
FilePath2->setText(GetFilePath(Paths[1][2]));
SwapIntv->insertItem(0,SwapInterval);SwapIntv->setCurrentIndex(0);
TimeTagC ->setChecked(OutTimeTag);
UpdateEnable();
}
//---------------------------------------------------------------------------
void OutputStrDialog::BtnOkClick()
{
StreamC[0] =Stream1C->isChecked();
StreamC[1] =Stream2C->isChecked();
Stream[0] =Stream1->currentIndex();
Stream[1] =Stream2->currentIndex();
Format[0] =Format1->currentIndex();
Format[1] =Format2->currentIndex();
Paths [0][2]=SetFilePath(FilePath1->text());
Paths [1][2]=SetFilePath(FilePath2->text());
SwapInterval=SwapIntv->currentText();
OutTimeTag =TimeTagC->isChecked();
accept();
}
//---------------------------------------------------------------------------
void OutputStrDialog::BtnFile1Click()
{
FilePath1->setText(QDir::toNativeSeparators(QFileDialog::getSaveFileName(this,tr("Load..."),FilePath1->text())));
}
//---------------------------------------------------------------------------
void OutputStrDialog::BtnFile2Click()
{
FilePath2->setText(QDir::toNativeSeparators(QFileDialog::getSaveFileName(this,tr("Load..."),FilePath2->text())));
}
//---------------------------------------------------------------------------
void OutputStrDialog::Stream1Change(int)
{
UpdateEnable();
}
//---------------------------------------------------------------------------
void OutputStrDialog::Stream2Change(int)
{
UpdateEnable();
}
//---------------------------------------------------------------------------
void OutputStrDialog::Stream1CClick()
{
UpdateEnable();
}
//---------------------------------------------------------------------------
void OutputStrDialog::Stream2CClick()
{
UpdateEnable();
}
//---------------------------------------------------------------------------
void OutputStrDialog::BtnKeyClick()
{
keyDialog->exec();
}
//---------------------------------------------------------------------------
void OutputStrDialog::BtnStr1Click()
{
switch (Stream1->currentIndex()) {
case 0: SerialOpt(0,0); break;
case 1: TcpOpt(0,1); break;
case 2: TcpOpt(0,0); break;
case 3: TcpOpt(0,2); break;
}
}
//---------------------------------------------------------------------------
void OutputStrDialog::BtnStr2Click()
{
switch (Stream2->currentIndex()) {
case 0: SerialOpt(1,0); break;
case 1: TcpOpt(1,1); break;
case 2: TcpOpt(1,0); break;
case 3: TcpOpt(1,2); break;
}
}
//---------------------------------------------------------------------------
QString OutputStrDialog::GetFilePath(const QString path)
{
QString file;
file=path.mid(0,path.indexOf("::"));
return file;
}
//---------------------------------------------------------------------------
QString OutputStrDialog::SetFilePath(const QString p)
{
QString path=p;
QString str;
bool okay;
if (TimeTagC->isChecked()) path+="::T";
str=SwapIntv->currentText();
str.toDouble(&okay);
if (okay) {
path+="::S="+str;
}
return path;
}
//---------------------------------------------------------------------------
void OutputStrDialog::SerialOpt(int index, int opt)
{
serialOptDialog->Path=Paths[index][0];
serialOptDialog->Opt=opt;
serialOptDialog->exec();
if (serialOptDialog->result()!=QDialog::Accepted) return;
Paths[index][0]=serialOptDialog->Path;
}
//---------------------------------------------------------------------------
void OutputStrDialog::TcpOpt(int index, int opt)
{
tcpOptDialog->Path=Paths[index][1];
tcpOptDialog->Opt=opt;
for (int i=0;i<10;i++) {
tcpOptDialog->History[i]=History[i];
tcpOptDialog->MntpHist[i]=MntpHist[i];
}
tcpOptDialog->exec();
if (tcpOptDialog->exec()!=QDialog::Accepted) return;
Paths[index][1]=tcpOptDialog->Path;
for (int i=0;i<10;i++) {
History[i]=tcpOptDialog->History[i];
MntpHist[i]=tcpOptDialog->MntpHist[i];
}
}
//---------------------------------------------------------------------------
void OutputStrDialog::UpdateEnable(void)
{
int ena=(Stream1C->isChecked()&&(Stream1->currentIndex()==4))||
(Stream2C->isChecked()&&(Stream2->currentIndex()==4));
Stream1 ->setEnabled(Stream1C->isChecked());
Stream2 ->setEnabled(Stream2C->isChecked());
BtnStr1 ->setEnabled(Stream1C->isChecked()&&Stream1->currentIndex()<=3);
BtnStr2 ->setEnabled(Stream2C->isChecked()&&Stream2->currentIndex()<=3);
FilePath1->setEnabled(Stream1C->isChecked()&&Stream1->currentIndex()==4);
FilePath2->setEnabled(Stream2C->isChecked()&&Stream2->currentIndex()==4);
BtnFile1 ->setEnabled(Stream1C->isChecked()&&Stream1->currentIndex()==4);
BtnFile2 ->setEnabled(Stream2C->isChecked()&&Stream2->currentIndex()==4);
LabelF1 ->setEnabled(ena);
Label1 ->setEnabled(ena);
Label2 ->setEnabled(ena);
TimeTagC ->setEnabled(ena);
SwapIntv ->setEnabled(ena);
BtnKey ->setEnabled(ena);
}
//---------------------------------------------------------------------------
|