Added Column dialog for selecting visible columns. Selection is stored to settings.
							parent
							
								
									d99267e488
								
							
						
					
					
						commit
						37d2371148
					
				@ -0,0 +1,59 @@
 | 
			
		||||
#include "columndialog.h"
 | 
			
		||||
#include "ui_columndialog.h"
 | 
			
		||||
 | 
			
		||||
#include <QTableWidgetItem>
 | 
			
		||||
#include <QHeaderView>
 | 
			
		||||
 | 
			
		||||
ColumnDialog::ColumnDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::ColumnDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ColumnDialog::~ColumnDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ColumnDialog::setTable(QTableView *table)
 | 
			
		||||
{
 | 
			
		||||
    ui->tableWidget->clear();
 | 
			
		||||
    ui->tableWidget->setColumnCount(1);
 | 
			
		||||
    ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Column"));
 | 
			
		||||
    ui->tableWidget->setRowCount(table->model()->columnCount());
 | 
			
		||||
    for (int i = 0; i < table->model()->columnCount(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        QVariant data = table->model()->headerData(i, Qt::Horizontal);
 | 
			
		||||
        QTableWidgetItem *item = new QTableWidgetItem(data.toString());
 | 
			
		||||
 | 
			
		||||
        if (table->isColumnHidden(i))
 | 
			
		||||
        {
 | 
			
		||||
            item->setCheckState(Qt::Unchecked);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            item->setCheckState(Qt::Checked);
 | 
			
		||||
        }
 | 
			
		||||
        ui->tableWidget->setItem(i, 0, item);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QHeaderView *horzHdr = ui->tableWidget->horizontalHeader();
 | 
			
		||||
    horzHdr->setStretchLastSection(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QList<int> ColumnDialog::columnsToHide()
 | 
			
		||||
{
 | 
			
		||||
    QList<int> list;
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < ui->tableWidget->rowCount(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (ui->tableWidget->item(i, 0)->checkState() == Qt::Unchecked)
 | 
			
		||||
        {
 | 
			
		||||
            list.append(i);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return list;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,28 @@
 | 
			
		||||
#ifndef COLUMNDIALOG_H
 | 
			
		||||
#define COLUMNDIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QTableView>
 | 
			
		||||
#include <QList>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ColumnDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ColumnDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ColumnDialog(QWidget *parent = 0);
 | 
			
		||||
    ~ColumnDialog();
 | 
			
		||||
 | 
			
		||||
    void setTable(QTableView *table);
 | 
			
		||||
    QList<int> columnsToHide();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ColumnDialog *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // COLUMNDIALOG_H
 | 
			
		||||
@ -0,0 +1,77 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>ColumnDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="ColumnDialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>473</width>
 | 
			
		||||
    <height>390</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Select columns</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QTableWidget" name="tableWidget">
 | 
			
		||||
     <property name="editTriggers">
 | 
			
		||||
      <set>QAbstractItemView::NoEditTriggers</set>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="showGrid">
 | 
			
		||||
      <bool>false</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
     <attribute name="verticalHeaderVisible">
 | 
			
		||||
      <bool>false</bool>
 | 
			
		||||
     </attribute>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QDialogButtonBox" name="buttonBox">
 | 
			
		||||
     <property name="orientation">
 | 
			
		||||
      <enum>Qt::Horizontal</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="standardButtons">
 | 
			
		||||
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>ColumnDialog</receiver>
 | 
			
		||||
   <slot>accept()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>248</x>
 | 
			
		||||
     <y>254</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>157</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>rejected()</signal>
 | 
			
		||||
   <receiver>ColumnDialog</receiver>
 | 
			
		||||
   <slot>reject()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>316</x>
 | 
			
		||||
     <y>260</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>286</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
 </connections>
 | 
			
		||||
</ui>
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue