1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ImportSinusXDlg.h"
20 #include <QVBoxLayout>
21 #include <QPushButton>
23 #include <HYDROData_SinusX.h>
25 #include <QHeaderView>
26 #include <QSizePolicy>
28 HYDROGUI_ImportSinusXDlg::HYDROGUI_ImportSinusXDlg( QWidget* theParent, const QStringList& theNames,
29 const std::vector<int>& theTypes )
30 : QDialog( theParent )
32 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
33 aMainLayout->setMargin(5);
34 aMainLayout->setSpacing(5);
35 this->resize(600, 500);
37 QLabel* gLabel = new QLabel();
38 gLabel->setText(tr("ENTITIES_TO_IMPORT"));
40 assert (theNames.size() == theTypes.size());
41 myTable = new QTableWidget(theNames.size(), 5);
44 header << tr("NAME") << tr("TYPE") << tr("AS_BATHY") << tr("AS_POLYXY") << tr("AS_PROFILE");
45 myTable->setHorizontalHeaderLabels(header);
47 myTable->setShowGrid(true);
48 myTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
50 for (int i = 0; i < theNames.size(); i++)
52 QTableWidgetItem* item_name = new QTableWidgetItem(theNames[i]);
53 item_name->setFlags(item_name->flags() ^ Qt::ItemIsEditable);
54 myTable->setItem(i, 0, item_name);
58 TypeName = tr("XYZ_CURVE");
59 else if (theTypes[i] == 2)
60 TypeName = tr("XYZ_PROFILE");
61 else if (theTypes[i] == 3)
62 TypeName = tr("ISOCONTOUR");
63 else if (theTypes[i] == 4)
64 TypeName = tr("SCATTER");
66 QTableWidgetItem* item_type = new QTableWidgetItem(TypeName);
67 item_type->setFlags(item_type->flags() ^ Qt::ItemIsEditable);
68 myTable->setItem(i, 1, item_type);
70 QTableWidgetItem* itemCheckbox1 = new QTableWidgetItem(""); //as bathy
71 itemCheckbox1->setFlags(itemCheckbox1->flags() ^ Qt::ItemIsEditable);
72 itemCheckbox1->setCheckState(Qt::Checked);
73 myTable->setItem(i, 2, itemCheckbox1);
75 QTableWidgetItem* itemCheckbox2 = new QTableWidgetItem(""); ; //as polyXY
76 itemCheckbox2->setFlags(itemCheckbox2->flags() ^ Qt::ItemIsEditable);
77 itemCheckbox2->setCheckState(Qt::Checked);
78 myTable->setItem(i, 3, itemCheckbox2);
80 QTableWidgetItem* itemCheckbox3 = new QTableWidgetItem(""); ; //as profile
81 itemCheckbox3->setFlags(itemCheckbox3->flags() ^ Qt::ItemIsEditable);
82 itemCheckbox3->setCheckState(Qt::Checked);
83 myTable->setItem(i, 4, itemCheckbox3);
85 if (theTypes[i] == 1 || theTypes[i] == 3) ///XYZ curve
87 itemCheckbox1->setFlags(item_type->flags() & ~Qt::ItemIsEnabled); //disable bathy
88 itemCheckbox1->setCheckState(Qt::Unchecked);
90 else if (theTypes[i] == 2)
92 itemCheckbox1->setFlags(item_type->flags() & ~Qt::ItemIsEnabled);
93 itemCheckbox2->setFlags(item_type->flags() & ~Qt::ItemIsEnabled);
94 itemCheckbox1->setCheckState(Qt::Unchecked);
95 itemCheckbox2->setCheckState(Qt::Unchecked);
97 else if (theTypes[i] == 4)
100 itemCheckbox2->setFlags(item_type->flags() & ~Qt::ItemIsEnabled);
101 itemCheckbox3->setFlags(item_type->flags() & ~Qt::ItemIsEnabled);
102 itemCheckbox2->setCheckState(Qt::Unchecked);
103 itemCheckbox3->setCheckState(Qt::Unchecked);
107 aMainLayout->addWidget(gLabel);
108 aMainLayout->addWidget(myTable);
110 //QPushButton* CheckAllButton = new QPushButton( tr("CHECK_ALL"), this );
111 //QPushButton* UncheckAllButton = new QPushButton( tr("UNCHECK_ALL"), this );
113 QPushButton* anOkButton = new QPushButton( tr("OK"), this );
114 anOkButton->setDefault( true );
116 //aMainLayout->addWidget( CheckAllButton );
117 //aMainLayout->addWidget( UncheckAllButton );
118 aMainLayout->addWidget( anOkButton );
120 connect( anOkButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
121 //connect( CheckAllButton, SIGNAL( clicked() ), this, SLOT( onCheckAll() ) );
122 //connect( UncheckAllButton, SIGNAL( clicked() ), this, SLOT( onUncheckAll() ) );
124 connect(myTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCheckChecked(int, int)));
126 setLayout(aMainLayout);
129 HYDROGUI_ImportSinusXDlg::~HYDROGUI_ImportSinusXDlg()
133 void HYDROGUI_ImportSinusXDlg::onCheckChecked(int r, int c)
135 ///if it's "as POLYLINE" column and now it's unchecked => disable "as PROFILE" checkbox
136 if (c == 3 && myTable->item(r, 3)->checkState() == Qt::Unchecked)
138 QString text = myTable->item(r, 1)->text();
139 if (text == tr("XYZ_CURVE") || text == tr("ISOCONTOUR"))
140 myTable->item(r, 4)->setCheckState(Qt::Unchecked);
144 std::vector<HYDROData_SinusX::ImportOptions> HYDROGUI_ImportSinusXDlg::GetImportOptions() const
146 std::vector<HYDROData_SinusX::ImportOptions> options;
147 int size = myTable->rowCount();
148 for (int i = 0; i < size; i++)
150 HYDROData_SinusX::ImportOptions option;
151 if (myTable->item(i, 2)->checkState() == Qt::CheckState::Checked)
152 option.ImportAsBathy = true;
153 if (myTable->item(i, 3)->checkState() == Qt::CheckState::Checked)
154 option.ImportAsPolyXY = true;
155 if (myTable->item(i, 4)->checkState() == Qt::CheckState::Checked)
156 option.ImportAsProfile = true;
157 options.push_back(option);