1 #ifndef _vvLinkPanel_CXX
2 #define _vvLinkPanel_CXX
4 /*=========================================================================
7 Module: $RCSfile: vvLinkPanel.cxx,v $
9 Date: $Date: 2010/01/06 13:31:57 $
10 Version: $Revision: 1.1 $
11 Author : Pierre Seroul (pierre.seroul@gmail.com)
13 Copyright (C) 200COLUMN_IMAGE_NAME
14 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
15 CREATIS-LRMN http://www.creatis.insa-lyon.fr
17 This program is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, version 3 of the License.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 =========================================================================*/
31 #include "vvLinkPanel.h"
32 #include "clitkCommon.h"
36 #include "QTreePushButton.h"
38 //====================================================================
39 vvLinkPanel::vvLinkPanel(QWidget * parent):QWidget(parent)
46 linkTableWidget->resizeColumnsToContents();
47 linkTableWidget->verticalHeader()->hide();
48 linkTableWidget->horizontalHeader()->hide();
49 linkTableWidget->hideColumn(4);
50 linkTableWidget->hideColumn(5);
52 connect(image1ComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateComboBox2(int)));
53 connect(linkButton,SIGNAL(clicked()),this,SLOT(addLink()));
54 connect(linkAllButton,SIGNAL(clicked()),this,SLOT(linkAll()));
57 void vvLinkPanel::addImage(std::string name, std::string id)
59 imageNames.push_back(name);
60 image1Ids.push_back(id);
64 void vvLinkPanel::removeImage(int index)
66 std::string idRemoved = image1Ids[index];
67 std::vector<std::string>::iterator Nameiter = imageNames.begin();
68 std::vector<std::string>::iterator Iditer = image1Ids.begin();
69 for (int i = 0; i < index; i++)
74 imageNames.erase(Nameiter);
75 image1Ids.erase(Iditer);
77 for (int i = linkTableWidget->rowCount() - 1; i >= 0 ;i--)
79 if (linkTableWidget->item(i,4)->text().toStdString() == idRemoved ||
80 linkTableWidget->item(i,5)->text().toStdString() == idRemoved)
82 emit removeLink(linkTableWidget->item(i,4)->text(),linkTableWidget->item(i,5)->text());
83 linkTableWidget->removeRow(i);
84 UpdateComboBox2(image1ComboBox->currentIndex());
89 void vvLinkPanel::UpdateComboBox1()
91 image1ComboBox->clear();
92 for (unsigned int i = 0; i < imageNames.size();i++)
94 image1ComboBox->addItem(imageNames[i].c_str());
98 void vvLinkPanel::UpdateComboBox2(int index)
100 image2ComboBox->clear();
102 if (imageNames.size() > 1 && index >= 0)
104 for (unsigned int i = 0; i < imageNames.size();i++)
108 bool AlreadyLinked = false;
109 for (int row = 0; row < linkTableWidget->rowCount();row++)
111 if ((linkTableWidget->item(row,1)->text().toStdString() == imageNames[index] &&
112 linkTableWidget->item(row,3)->text().toStdString() == imageNames[i]) ||
113 (linkTableWidget->item(row,3)->text().toStdString() == imageNames[index] &&
114 linkTableWidget->item(row,1)->text().toStdString() == imageNames[i]))
116 AlreadyLinked = true;
122 image2ComboBox->addItem(imageNames[i].c_str());
123 image2Ids.push_back(image1Ids[i]);
128 if (image2ComboBox->count() == 0)
129 linkButton->setEnabled(0);
131 linkButton->setEnabled(1);
134 void vvLinkPanel::linkAll()
136 //First remove all links
137 while (linkTableWidget->rowCount())
139 //Now create all possible links
140 int count=image2ComboBox->count();
141 for (int j=0;j<count;j++)
143 image1ComboBox->setCurrentIndex(j);
144 image2ComboBox->setCurrentIndex(0);
145 for (int i=0;i< count-j;i++)
150 void vvLinkPanel::addLink()
152 if (!image1ComboBox->currentText().isEmpty()
153 && !image2ComboBox->currentText().isEmpty())
155 int row = linkTableWidget->rowCount();
156 linkTableWidget->insertRow(row);
158 linkTableWidget->setItem(row,1,new QTableWidgetItem(image1ComboBox->currentText()));
159 linkTableWidget->setItem(row,2,new QTableWidgetItem("&"));
160 linkTableWidget->setItem(row,3,new QTableWidgetItem(image2ComboBox->currentText()));
161 linkTableWidget->setItem(row,4,new QTableWidgetItem(image1Ids[image1ComboBox->currentIndex()].c_str()));
162 linkTableWidget->setItem(row,5,new QTableWidgetItem(image2Ids[image2ComboBox->currentIndex()].c_str()));
163 QTreePushButton* cButton = new QTreePushButton;
164 cButton->setIndex(linkTableWidget->rowCount());
165 cButton->setColumn(0);
166 cButton->setIcon(QIcon(QString::fromUtf8(":/new/prefix1/icons/exit.png")));
167 connect(cButton,SIGNAL(clickedInto(int, int)),
168 this,SLOT(removeLink(int, int)));
169 cButton->setToolTip(tr("remove link"));
170 linkTableWidget->setCellWidget(row,0,cButton);
172 linkTableWidget->resizeColumnToContents(0);
173 linkTableWidget->resizeColumnToContents(1);
174 linkTableWidget->resizeColumnToContents(2);
175 linkTableWidget->resizeColumnToContents(3);
176 linkTableWidget->setRowHeight(row,17);
178 emit addLink(image1Ids[image1ComboBox->currentIndex()].c_str(),
179 image2Ids[image2ComboBox->currentIndex()].c_str());
180 UpdateComboBox2(image1ComboBox->currentIndex());
185 void vvLinkPanel::removeLink(int row, int column)
187 emit removeLink(linkTableWidget->item(row-1,4)->text(),linkTableWidget->item(row-1,5)->text());
188 linkTableWidget->removeRow(row-1);
189 UpdateComboBox2(image1ComboBox->currentIndex());
192 #endif /* end #define _vvLinkPanel_CXX */