1 #ifndef _vvLinkPanel_CXX
2 #define _vvLinkPanel_CXX
4 /*=========================================================================
8 Author : Pierre Seroul (pierre.seroul@gmail.com)
10 Copyright (C) 200COLUMN_IMAGE_NAME
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
28 #include "vvLinkPanel.h"
29 #include "clitkCommon.h"
33 #include "QTreePushButton.h"
35 //====================================================================
36 vvLinkPanel::vvLinkPanel(QWidget * parent):QWidget(parent)
43 linkTableWidget->resizeColumnsToContents();
44 linkTableWidget->verticalHeader()->hide();
45 linkTableWidget->horizontalHeader()->hide();
46 linkTableWidget->hideColumn(4);
47 linkTableWidget->hideColumn(5);
49 connect(image1ComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateComboBox2(int)));
50 connect(linkButton,SIGNAL(clicked()),this,SLOT(addLink()));
51 connect(linkAllButton,SIGNAL(clicked()),this,SLOT(linkAll()));
54 void vvLinkPanel::addImage(std::string name, std::string id)
56 imageNames.push_back(name);
57 image1Ids.push_back(id);
61 void vvLinkPanel::removeImage(int index)
63 std::string idRemoved = image1Ids[index];
64 std::vector<std::string>::iterator Nameiter = imageNames.begin();
65 std::vector<std::string>::iterator Iditer = image1Ids.begin();
66 for (int i = 0; i < index; i++)
71 imageNames.erase(Nameiter);
72 image1Ids.erase(Iditer);
74 for (int i = linkTableWidget->rowCount() - 1; i >= 0 ;i--)
76 if (linkTableWidget->item(i,4)->text().toStdString() == idRemoved ||
77 linkTableWidget->item(i,5)->text().toStdString() == idRemoved)
79 emit removeLink(linkTableWidget->item(i,4)->text(),linkTableWidget->item(i,5)->text());
80 linkTableWidget->removeRow(i);
81 UpdateComboBox2(image1ComboBox->currentIndex());
86 void vvLinkPanel::UpdateComboBox1()
88 image1ComboBox->clear();
89 for (unsigned int i = 0; i < imageNames.size();i++)
91 image1ComboBox->addItem(imageNames[i].c_str());
95 void vvLinkPanel::UpdateComboBox2(int index)
97 image2ComboBox->clear();
99 if (imageNames.size() > 1 && index >= 0)
101 for (unsigned int i = 0; i < imageNames.size();i++)
105 bool AlreadyLinked = false;
106 for (int row = 0; row < linkTableWidget->rowCount();row++)
108 if ((linkTableWidget->item(row,1)->text().toStdString() == imageNames[index] &&
109 linkTableWidget->item(row,3)->text().toStdString() == imageNames[i]) ||
110 (linkTableWidget->item(row,3)->text().toStdString() == imageNames[index] &&
111 linkTableWidget->item(row,1)->text().toStdString() == imageNames[i]))
113 AlreadyLinked = true;
119 image2ComboBox->addItem(imageNames[i].c_str());
120 image2Ids.push_back(image1Ids[i]);
125 if (image2ComboBox->count() == 0)
126 linkButton->setEnabled(0);
128 linkButton->setEnabled(1);
131 void vvLinkPanel::linkAll()
133 //First remove all links
134 while (linkTableWidget->rowCount())
136 //Now create all possible links
137 int count=image2ComboBox->count();
138 for (int j=0;j<count;j++)
140 image1ComboBox->setCurrentIndex(j);
141 image2ComboBox->setCurrentIndex(0);
142 for (int i=0;i< count-j;i++)
147 void vvLinkPanel::addLink()
149 if (!image1ComboBox->currentText().isEmpty()
150 && !image2ComboBox->currentText().isEmpty())
152 int row = linkTableWidget->rowCount();
153 linkTableWidget->insertRow(row);
155 linkTableWidget->setItem(row,1,new QTableWidgetItem(image1ComboBox->currentText()));
156 linkTableWidget->setItem(row,2,new QTableWidgetItem("&"));
157 linkTableWidget->setItem(row,3,new QTableWidgetItem(image2ComboBox->currentText()));
158 linkTableWidget->setItem(row,4,new QTableWidgetItem(image1Ids[image1ComboBox->currentIndex()].c_str()));
159 linkTableWidget->setItem(row,5,new QTableWidgetItem(image2Ids[image2ComboBox->currentIndex()].c_str()));
160 QTreePushButton* cButton = new QTreePushButton;
161 cButton->setIndex(linkTableWidget->rowCount());
162 cButton->setColumn(0);
163 cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
164 connect(cButton,SIGNAL(clickedInto(int, int)),
165 this,SLOT(removeLink(int, int)));
166 cButton->setToolTip(tr("remove link"));
167 linkTableWidget->setCellWidget(row,0,cButton);
169 linkTableWidget->resizeColumnToContents(0);
170 linkTableWidget->resizeColumnToContents(1);
171 linkTableWidget->resizeColumnToContents(2);
172 linkTableWidget->resizeColumnToContents(3);
173 linkTableWidget->setRowHeight(row,17);
175 emit addLink(image1Ids[image1ComboBox->currentIndex()].c_str(),
176 image2Ids[image2ComboBox->currentIndex()].c_str());
177 UpdateComboBox2(image1ComboBox->currentIndex());
182 void vvLinkPanel::removeLink(int row, int column)
184 emit removeLink(linkTableWidget->item(row-1,4)->text(),linkTableWidget->item(row-1,5)->text());
185 linkTableWidget->removeRow(row-1);
186 UpdateComboBox2(image1ComboBox->currentIndex());
189 #endif /* end #define _vvLinkPanel_CXX */