1#include "ImageFileListWidget.h"
7#include <QContextMenuEvent>
10#include <QInputDialog>
21#include <QXmlStreamWriter>
25#include "IException.h"
27#include "ImageTreeWidget.h"
28#include "ImageTreeWidgetItem.h"
30#include "ProgressBar.h"
49 QHBoxLayout *layout =
new QHBoxLayout();
52 m_tree->setObjectName(
"Tree");
55 layout->setContentsMargins(0, 0, 0, 0);
57 setWhatsThis(
"This is the image file list. Opened "
58 "cubes show up here. You can arrange your cubes into groups (that you "
59 "name) to help keep track of them. Also, you can configure multiple "
60 "files at once. Finally, you can sort your files by any of the visible "
61 "columns (use the view menu to show/hide columns of data).");
63 treeWidget->setLayout(layout);
70 m_searchToolbar->setWhatsThis(
"This contains all the fields for searching the active file list");
72 m_searchLineEdit =
new QLineEdit();
73 QPushButton *okButton =
new QPushButton(
"Search");
74 connect(okButton, SIGNAL(clicked()),
this, SLOT(filterFileList()));
75 QPushButton *clearButton =
new QPushButton(
"Clear");
76 connect(clearButton, SIGNAL(clicked()),
this, SLOT(clear()));
77 QHBoxLayout *actionLayout =
new QHBoxLayout();
78 m_fileCount =
new QLabel(
"File Matches: 0");
79 actionLayout->addWidget(m_searchLineEdit);
80 actionLayout->addWidget(okButton);
81 actionLayout->addWidget(clearButton);
82 actionLayout->addWidget(m_fileCount);
83 actionLayout->addStretch(1);
84 actionLayout->setMargin(0);
86 toolBarWidget->setLayout(actionLayout);
88 QVBoxLayout *fileListWidgetLayout =
new QVBoxLayout();
90 fileListWidgetLayout->addWidget(treeWidget);
91 setLayout(fileListWidgetLayout);
119 if (pvl.
name() ==
"ImageFileList") {
121 ImageTreeWidgetItem::TreeColumn col =
122 ImageTreeWidgetItem::FootprintColumn;
123 while (col < ImageTreeWidgetItem::BlankColumn) {
124 IString key = ImageTreeWidgetItem::treeColumnToString(col) +
"Visible";
138 col = (ImageTreeWidgetItem::TreeColumn)(col + 1);
142 m_tree->sortItems(pvl[
"SortColumn"], Qt::AscendingOrder);
147 while (
m_tree->topLevelItemCount() > 0) {
149 allCubes.append(group->takeChildren());
156 for (
int cubeGrp = 0; cubeGrp < pvl.
objects(); cubeGrp ++) {
162 bool expanded = (cubes[
"Expanded"][0] !=
"No");
163 newCubeGrp->setExpanded(expanded);
167 if (allCubes.size()) {
168 m_tree->addGroup(
"",
"Unknown")->addChildren(allCubes);
173 "list widget settings from Pvl", _FILEINFO_);
185 ImageTreeWidgetItem::TreeColumn col =
186 ImageTreeWidgetItem::FootprintColumn;
187 while (col < ImageTreeWidgetItem::BlankColumn) {
188 IString key = ImageTreeWidgetItem::treeColumnToString(col) +
"Visible";
190 bool visible = !
m_tree->isColumnHidden(col);
193 col = (ImageTreeWidgetItem::TreeColumn)(col + 1);
199 for (
int i = 0; i <
m_tree->topLevelItemCount(); i++) {
202 group->text(ImageTreeWidgetItem::NameColumn));
203 cubeGroup +=
PvlKeyword(
"Expanded", group->isExpanded() ?
"Yes" :
"No");
205 for (
int j = 0; j < group->childCount(); j++) {
208 if (item->type() == QTreeWidgetItem::UserType) {
211 cubeGroup +=
PvlKeyword(
"Image", cubeItem->image()->
id());
240 return m_tree->getViewActions();
254 "Save Entire Cube List (ordered by &file list/groups)...");
268 QScrollArea *longHelpWidgetScrollArea =
new QScrollArea;
271 longHelpWidgetScrollArea->setWidget(longHelpWidget);
273 QVBoxLayout *longHelpLayout =
new QVBoxLayout;
274 longHelpLayout->setSizeConstraint(QLayout::SetFixedSize);
275 longHelpWidget->setLayout(longHelpLayout);
277 QLabel *title =
new QLabel(
"<h2>Image File List</h2>");
278 longHelpLayout->addWidget(title);
281 if (!fileListContainer) {
287 tmp->resize(QSize(500, 200));
288 preview = tmp->grab();
292 QPixmap previewPixmap = fileListContainer->grab().scaled(
293 QSize(500, 200), Qt::KeepAspectRatio, Qt::SmoothTransformation);
295 QLabel *previewWrapper =
new QLabel;
296 previewWrapper->setPixmap(previewPixmap);
297 longHelpLayout->addWidget(previewWrapper);
300 QLabel *previewWrapper =
new QLabel;
301 previewWrapper->setPixmap(preview);
302 longHelpLayout->addWidget(previewWrapper);
304 QLabel *overview =
new QLabel(tr(
"The mosaic file list is designed to help "
305 "to organize your files within the %1 project. The file list supports changing multiple "
306 "files simultaneously using the right-click menus after selecting "
307 "several images or groups.<br>"
309 "<p>Every cube must be inside of a group. These groups can be "
310 "renamed by double clicking on them. To move a cube between groups, "
311 "click and drag it to the group you want it in. This works "
312 "for multiple cubes also. You can change all of the cubes in a "
313 "group by right clicking on the group name. You can add a group "
314 "by right clicking in the white space below the last cube or on "
315 "an existing group.</p>"
317 "Show and hide columns by using the view menu. These "
318 "columns show relevant data about the cube, including statistical "
319 "information. Some of this information will be blank if you do "
320 "not run the application, <i>camstats</i>, before opening the cube."
322 "Sort cubes within each group in ascending or descending order "
323 "by clicking on the column "
324 "title of the column that you want to sort on. Clicking on the "
325 "title again will reverse the sorting order. You can also drag and "
326 "drop a cube between two other cubes to change where it is in the "
327 "list.").arg(QApplication::applicationName()));
328 overview->setWordWrap(
true);
330 longHelpLayout->addWidget(overview);
331 longHelpLayout->addStretch();
333 return longHelpWidgetScrollArea;
360 while (
m_tree->topLevelItemCount()) {
361 groups.append(
m_tree->takeTopLevelItem(0));
366 foreach (
Image *image, *images) {
367 if (alreadyViewedImages.indexOf(image) == -1) {
370 if (!m_serialized.isNull()) {
376 if (!pos.isValid()) {
377 if (
m_tree->groupInList(selected)) {
378 QListIterator<QTreeWidgetItem *> it(selected);
379 while (it.hasNext() && !selectedGroup) {
381 if (item->data(0, Qt::UserRole).toInt() == ImageTreeWidget::ImageGroupType) {
382 selectedGroup = item;
387 if (!selectedGroup) {
391 if (images->
name().isEmpty()) {
392 imageListNameItem =
m_tree->invisibleRootItem();
393 groupName = QString(
"Group %1").arg(groups.count() + 1);
396 for (
int i = 0; !imageListNameItem && i < groups.count(); i++) {
398 if (group->data(0, Qt::UserRole).toInt() == ImageTreeWidget::ImageListNameType &&
399 group->text(0) == images->
name()) {
400 imageListNameItem = group;
404 if (!imageListNameItem) {
405 imageListNameItem =
m_tree->createImageListNameItem(images->
name());
406 groups.append(imageListNameItem);
410 selectedGroup =
m_tree->createGroup(imageListNameItem, groupName);
413 selectedGroup->addChild(newImageItem);
417 if (groupItem->childCount() < pos.index())
418 groupItem->addChild(newImageItem);
420 groupItem->insertChild(pos.index(), newImageItem);
428 m_tree->addTopLevelItem(group);
433 selectedGroup->setSelected(
true);
446 foreach (
Image* image, *images) {
448 for (
int i = 0; i <
m_tree->topLevelItemCount(); i++) {
451 for (
int j = 0; j < group->childCount(); j++) {
454 if (item->type() == QTreeWidgetItem::UserType && !item->isHidden()) {
456 if (cubeItem->image() == image){
457 item->setHidden(
true);
487 menu.exec(event->globalPos());
495 QFileDialog::getSaveFileName((
QWidget *)parent(),
496 "Choose output file",
497 QDir::currentPath() +
"/files.lis",
498 QString(
"List File (*.lis);;Text File (*.txt);;All Files (*.*)"));
499 if (output.isEmpty())
return;
503 for (
int i = 0; i <
m_tree->topLevelItemCount(); i++) {
506 for (
int j = 0; j < group->childCount(); j++) {
509 if (item->type() == QTreeWidgetItem::UserType) {
525 QString
id = image->
id();
528 for (
int objIndex = 0; !result.isValid() && objIndex < m_serialized->objects(); objIndex++) {
531 int imageKeyOffset = 0;
532 for (
int fileKeyIndex = 0;
533 !result.isValid() && fileKeyIndex < obj.
keywords();
560 if (states.contains(
"Expanded")) {
561 item->setExpanded(states[
"Expanded"].
toBool());
564 item->setExpanded(
true);
570 while (i < item->childCount() && i < childrenStates.count()) {
575 while (i < item->childCount()) {
591 result[
"Expanded"] = item->isExpanded();
593 if (item->childCount()) {
596 for (
int i = 0; i < item->childCount(); i++) {
600 result[
"Children"] = childrenStates;
618 stream.writeStartElement(
"imageFileList");
619 stream.writeAttribute(
"objectName", objectName());
649 ImageTreeWidgetItem::TreeColumn col =
650 ImageTreeWidgetItem::FootprintColumn;
651 while (col < ImageTreeWidgetItem::BlankColumn) {
652 bool visible = !
m_tree->isColumnHidden(col);
653 bool sorted = (
m_tree->sortColumn() == col);
655 stream.writeStartElement(
"column");
656 stream.writeAttribute(
"name", ImageTreeWidgetItem::treeColumnToString(col));
657 stream.writeAttribute(
"visible", (visible?
"true" :
"false"));
658 stream.writeAttribute(
"sorted", (sorted?
"true" :
"false"));
659 stream.writeEndElement();
661 col = (ImageTreeWidgetItem::TreeColumn)(col + 1);
667 stream.writeEndElement();
683 stream.writeStartElement(
"treeLayout");
685 else if (itemToWrite->type() == QTreeWidgetItem::UserType) {
688 stream.writeStartElement(
"image");
689 stream.writeAttribute(
"id", imageItemToWrite->image()->
id());
692 bool groupIsImageList =
693 (itemToWrite->data(0, Qt::UserRole).
toInt() == ImageTreeWidget::ImageListNameType);
695 stream.writeStartElement(
"group");
696 stream.writeAttribute(
"name", itemToWrite->text(ImageTreeWidgetItem::NameColumn));
697 stream.writeAttribute(
"expanded", itemToWrite->isExpanded() ?
"true" :
"false");
698 stream.writeAttribute(
"isImageList", groupIsImageList?
"true" :
"false");
706 if (itemToWrite == NULL && i < m_tree->topLevelItemCount()) {
707 childItemToWrite =
m_tree->topLevelItem(i);
709 else if (itemToWrite != NULL && i < itemToWrite->childCount()) {
710 childItemToWrite = itemToWrite->child(i);
713 if (childItemToWrite) {
714 save(stream, childItemToWrite);
717 done = (childItemToWrite == NULL);
722 stream.writeEndElement();
726 void ImageFileListWidget::filterFileList() {
727 QString filterString = m_searchLineEdit->text();
730 for (
int i = 0; i <
m_tree->topLevelItemCount(); i++) {
733 for (
int j = 0; j < group->childCount(); j++) {
735 group->setSelected(
false);
736 if (item->type() == QTreeWidgetItem::UserType) {
739 if (cubeItem->image()->
fileName().contains(filterString)){
740 cubeItem->setSelected(
true);
741 m_tree->scrollToItem(cubeItem);
745 cubeItem->setSelected(
false);
750 m_fileCount->setText(
"File Matches: " + QString::number(numMatches));
754 void ImageFileListWidget::clear() {
755 m_searchLineEdit->setText(
"");
756 m_fileCount->setText(
"File Matches: 0");
758 for (
int i = 0; i <
m_tree->topLevelItemCount(); i++) {
759 QTreeWidgetItem *group =
m_tree->topLevelItem(i);
761 for (
int j = 0; j < group->childCount(); j++) {
762 QTreeWidgetItem *item = group->child(j);
763 group->setSelected(
false);
764 if (item->type() == QTreeWidgetItem::UserType) {
765 item->setSelected(
false);
File name manipulation and expansion.
@ Io
A type of error that occurred when performing an actual I/O operation.
Adds specific functionality to C++ strings.
IString Convert(const std::string &listofchars, const char &to)
Returns the string with all occurrences of any character in the "from" argument converted to the "to"...
QString ToQt() const
Retuns the object string as a QString.
This represents a cube in a project-based GUI interface.
QString fileName() const
Get the file name of the cube that this image represents.
QString id() const
Get a unique, identifying string associated with this image.
Internalizes a list of images and allows for operations on the entire list.
QString name() const
Get the human-readable name of this image list.
The main project for ipce.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
QString name() const
Returns the container name.
A single keyword-value pair.
bool isNamed(QString name) const
Determines whether two PvlKeywords have the same name or not.
Contains Pvl Groups and Pvl Objects.
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
int objects() const
Returns the number of objects.
PvlObject & object(const int index)
Return the object at the specified index.
Provides access to sequential ASCII stream I/O.
void PutLine(const QString &line)
Writes string to file and appends a 'newline' string.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
int toInt(const QString &string)
Global function to convert from a string to an integer.
bool toBool(const QString &string)
Global function to convert from a string to a boolean.