Loading isis/src/qisis/objs/TableMainWindow/TableMainWindow.cpp +81 −5 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <QStatusBar> #include <QDockWidget> #include <QFileDialog> #include <QHeaderView> #include <QMenuBar> #include <QMessageBox> #include <QSettings> Loading @@ -28,14 +29,15 @@ namespace Isis { p_visibleColumns = -1; p_currentRow = 0; p_currentIndex = 0; createTable(); setObjectName(title); createTable(); readSettings(QSize(500, 300)); readColumnSettings(); } TableMainWindow::~TableMainWindow() { writeSettings(); } Loading @@ -57,6 +59,23 @@ namespace Isis { return result; } void TableMainWindow::resizeColumn(int columnIndex) { QHeaderView* header = p_table->horizontalHeader(); QString columnName(p_table->model()->headerData(columnIndex, Qt::Horizontal).toString()); if (columnName.isEmpty()) { return; } if (header->sectionResizeMode(columnIndex) == QHeaderView:: ResizeToContents) { header->setSectionResizeMode(columnIndex, QHeaderView::Interactive); } else { header->setSectionResizeMode(columnIndex, QHeaderView::ResizeToContents); } } /** * This creates the table main window. The table and docking Loading @@ -77,6 +96,12 @@ namespace Isis { // Create the table widget p_table = new QTableWidget(this); p_table->setAlternatingRowColors(true); // QHeaderView* columnHeader = p_table->horizontalHeader(); columnHeader->setSectionResizeMode(QHeaderView::ResizeToContents); connect ( columnHeader, SIGNAL( sectionPressed(int) ), this, SLOT( resizeColumn(int) ) ); setCentralWidget(p_table); // Create the dock area Loading Loading @@ -151,7 +176,6 @@ namespace Isis { cols->setText("Columns"); connect(cols, SIGNAL(triggered()), p_dock, SLOT(show())); viewMenu->addAction(cols); this->setMenuBar(menuBar); installEventFilter(this); } Loading Loading @@ -255,6 +279,7 @@ namespace Isis { readItemSettings(heading, item, setOn); } readColumnSettings(); } Loading Loading @@ -550,6 +575,41 @@ namespace Isis { item->setCheckState(state); } /** * This method reads the columns in the table and sets their size * to the appropriate size, or the size to auto based on what they were * stored as. * * @param heading * @param item */ void TableMainWindow::readColumnSettings() { QHeaderView* header = p_table->horizontalHeader(); QSettings settings(settingsFileName(), QSettings::NativeFormat); for(int columnIndex = 0; columnIndex < p_table->model()->columnCount(); columnIndex++) { QString headerName = p_table->model()->headerData(columnIndex, Qt::Horizontal).toString(); QString settingName = "column-" + headerName; QString value = settings.value(settingName, "auto").toString(); if (value == "auto" || value == "0") { header->setSectionResizeMode(columnIndex, QHeaderView::ResizeToContents); } else { int width = value.toInt(); header->setSectionResizeMode(columnIndex, QHeaderView::Interactive); p_table->setColumnWidth(columnIndex, width); } } } /** * This overriden method is called when the Tablemainwindow Loading @@ -566,6 +626,22 @@ namespace Isis { QString itemTitle = "item-" + item->text(); settings.setValue(itemTitle, item->checkState()); } QHeaderView *header = p_table->horizontalHeader(); for(int columnIndex = 0; columnIndex < p_table->model()->columnCount(); columnIndex++) { QString headerName = p_table->model()->headerData(columnIndex, Qt::Horizontal).toString(); QString settingName = "column-" + headerName; if (header->sectionResizeMode(columnIndex) == QHeaderView::ResizeToContents) { settings.setValue(settingName, "auto"); } else { settings.setValue( settingName, header->sectionSize(columnIndex) ); } } } } Loading isis/src/qisis/objs/TableMainWindow/TableMainWindow.h +8 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,11 @@ namespace Isis { * @history 2017-10-06 Adam Goins - showTable() now calls syncColumns() after it calls * this->show() so that it hides the unselected columns appropriately. * Fixes #5141. * @history 2017-11-13 Adam Goins - modified createTable() to set the resize property of the * columns to resize automatically based on the content inside of the * column. Added resizeColumn() slot and readColumnSettings(). * modifie writeSettings() to write updated settings on destroy. * Added Fixes #5142. */ class TableMainWindow : public MainWindow { Q_OBJECT Loading Loading @@ -129,6 +134,7 @@ namespace Isis { bool trackListItems(); void loadTable(); void writeSettings() const; void resizeColumn(int columnIndex); signals: /** Loading @@ -143,6 +149,8 @@ namespace Isis { void readItemSettings(QString heading, QListWidgetItem *item, bool defaultChecked); void readColumnSettings(); private: std::string p_appName; //!< The application name QWidget *p_parent; //!< The parent widget Loading Loading
isis/src/qisis/objs/TableMainWindow/TableMainWindow.cpp +81 −5 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <QStatusBar> #include <QDockWidget> #include <QFileDialog> #include <QHeaderView> #include <QMenuBar> #include <QMessageBox> #include <QSettings> Loading @@ -28,14 +29,15 @@ namespace Isis { p_visibleColumns = -1; p_currentRow = 0; p_currentIndex = 0; createTable(); setObjectName(title); createTable(); readSettings(QSize(500, 300)); readColumnSettings(); } TableMainWindow::~TableMainWindow() { writeSettings(); } Loading @@ -57,6 +59,23 @@ namespace Isis { return result; } void TableMainWindow::resizeColumn(int columnIndex) { QHeaderView* header = p_table->horizontalHeader(); QString columnName(p_table->model()->headerData(columnIndex, Qt::Horizontal).toString()); if (columnName.isEmpty()) { return; } if (header->sectionResizeMode(columnIndex) == QHeaderView:: ResizeToContents) { header->setSectionResizeMode(columnIndex, QHeaderView::Interactive); } else { header->setSectionResizeMode(columnIndex, QHeaderView::ResizeToContents); } } /** * This creates the table main window. The table and docking Loading @@ -77,6 +96,12 @@ namespace Isis { // Create the table widget p_table = new QTableWidget(this); p_table->setAlternatingRowColors(true); // QHeaderView* columnHeader = p_table->horizontalHeader(); columnHeader->setSectionResizeMode(QHeaderView::ResizeToContents); connect ( columnHeader, SIGNAL( sectionPressed(int) ), this, SLOT( resizeColumn(int) ) ); setCentralWidget(p_table); // Create the dock area Loading Loading @@ -151,7 +176,6 @@ namespace Isis { cols->setText("Columns"); connect(cols, SIGNAL(triggered()), p_dock, SLOT(show())); viewMenu->addAction(cols); this->setMenuBar(menuBar); installEventFilter(this); } Loading Loading @@ -255,6 +279,7 @@ namespace Isis { readItemSettings(heading, item, setOn); } readColumnSettings(); } Loading Loading @@ -550,6 +575,41 @@ namespace Isis { item->setCheckState(state); } /** * This method reads the columns in the table and sets their size * to the appropriate size, or the size to auto based on what they were * stored as. * * @param heading * @param item */ void TableMainWindow::readColumnSettings() { QHeaderView* header = p_table->horizontalHeader(); QSettings settings(settingsFileName(), QSettings::NativeFormat); for(int columnIndex = 0; columnIndex < p_table->model()->columnCount(); columnIndex++) { QString headerName = p_table->model()->headerData(columnIndex, Qt::Horizontal).toString(); QString settingName = "column-" + headerName; QString value = settings.value(settingName, "auto").toString(); if (value == "auto" || value == "0") { header->setSectionResizeMode(columnIndex, QHeaderView::ResizeToContents); } else { int width = value.toInt(); header->setSectionResizeMode(columnIndex, QHeaderView::Interactive); p_table->setColumnWidth(columnIndex, width); } } } /** * This overriden method is called when the Tablemainwindow Loading @@ -566,6 +626,22 @@ namespace Isis { QString itemTitle = "item-" + item->text(); settings.setValue(itemTitle, item->checkState()); } QHeaderView *header = p_table->horizontalHeader(); for(int columnIndex = 0; columnIndex < p_table->model()->columnCount(); columnIndex++) { QString headerName = p_table->model()->headerData(columnIndex, Qt::Horizontal).toString(); QString settingName = "column-" + headerName; if (header->sectionResizeMode(columnIndex) == QHeaderView::ResizeToContents) { settings.setValue(settingName, "auto"); } else { settings.setValue( settingName, header->sectionSize(columnIndex) ); } } } } Loading
isis/src/qisis/objs/TableMainWindow/TableMainWindow.h +8 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,11 @@ namespace Isis { * @history 2017-10-06 Adam Goins - showTable() now calls syncColumns() after it calls * this->show() so that it hides the unselected columns appropriately. * Fixes #5141. * @history 2017-11-13 Adam Goins - modified createTable() to set the resize property of the * columns to resize automatically based on the content inside of the * column. Added resizeColumn() slot and readColumnSettings(). * modifie writeSettings() to write updated settings on destroy. * Added Fixes #5142. */ class TableMainWindow : public MainWindow { Q_OBJECT Loading Loading @@ -129,6 +134,7 @@ namespace Isis { bool trackListItems(); void loadTable(); void writeSettings() const; void resizeColumn(int columnIndex); signals: /** Loading @@ -143,6 +149,8 @@ namespace Isis { void readItemSettings(QString heading, QListWidgetItem *item, bool defaultChecked); void readColumnSettings(); private: std::string p_appName; //!< The application name QWidget *p_parent; //!< The parent widget Loading