mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Missing Files.
This should have been in the last commit - sorry. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
5666f6573e
commit
46a20e7dd8
3 changed files with 198 additions and 0 deletions
90
qt-ui/tableview.cpp
Normal file
90
qt-ui/tableview.cpp
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
#include "tableview.h"
|
||||||
|
#include "ui_tableview.h"
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
TableView::TableView(QWidget *parent) : QWidget(parent), ui(new Ui::TableView){
|
||||||
|
ui->setupUi(this);
|
||||||
|
QFile cssFile(":table-css");
|
||||||
|
cssFile.open(QIODevice::ReadOnly);
|
||||||
|
QTextStream reader(&cssFile);
|
||||||
|
QString css = reader.readAll();
|
||||||
|
ui->tableView->setStyleSheet(css);
|
||||||
|
|
||||||
|
QIcon plusIcon(":plus");
|
||||||
|
plusBtn = new QPushButton(plusIcon, QString(), ui->groupBox);
|
||||||
|
plusBtn->setFlat(true);
|
||||||
|
plusBtn->setToolTip(tr("Add Cylinder"));
|
||||||
|
connect(plusBtn, SIGNAL(clicked(bool)), this, SIGNAL(addButtonClicked()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TableView::~TableView()
|
||||||
|
{
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(objectName());
|
||||||
|
for (int i = 0; i < ui->tableView->model()->columnCount(); i++) {
|
||||||
|
s.setValue(QString("colwidth%1").arg(i), ui->tableView->columnWidth(i));
|
||||||
|
}
|
||||||
|
s.endGroup();
|
||||||
|
s.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::setBtnToolTip(const QString& tooltip)
|
||||||
|
{
|
||||||
|
plusBtn->setToolTip(tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::setTitle(const QString& title)
|
||||||
|
{
|
||||||
|
ui->groupBox->setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::setModel(QAbstractItemModel *model){
|
||||||
|
ui->tableView->setModel(model);
|
||||||
|
connect(ui->tableView, SIGNAL(clicked(QModelIndex)), model, SLOT(remove(QModelIndex)));
|
||||||
|
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(objectName());
|
||||||
|
for (int i = 0; i < ui->tableView->model()->columnCount(); i++) {
|
||||||
|
QVariant width = s.value(QString("colwidth%1").arg(i));
|
||||||
|
if (width.isValid())
|
||||||
|
ui->tableView->setColumnWidth(i, width.toInt());
|
||||||
|
else
|
||||||
|
ui->tableView->resizeColumnToContents(i);
|
||||||
|
}
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
|
ui->tableView->horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);
|
||||||
|
QFontMetrics metrics(defaultModelFont());
|
||||||
|
ui->tableView->verticalHeader()->setDefaultSectionSize( metrics.height() + 8 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::fixPlusPosition()
|
||||||
|
{
|
||||||
|
plusBtn->setGeometry(ui->groupBox->contentsRect().width() - 30, 2, 24,24);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to manually position the 'plus' on cylinder and weight.
|
||||||
|
void TableView::resizeEvent(QResizeEvent* event)
|
||||||
|
{
|
||||||
|
fixPlusPosition();
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::showEvent(QShowEvent* event)
|
||||||
|
{
|
||||||
|
QWidget::showEvent(event);
|
||||||
|
fixPlusPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::edit(const QModelIndex& index){
|
||||||
|
ui->tableView->edit(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTableView *TableView::view(){
|
||||||
|
return ui->tableView;
|
||||||
|
}
|
45
qt-ui/tableview.h
Normal file
45
qt-ui/tableview.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef TABLEVIEW_H
|
||||||
|
#define TABLEVIEW_H
|
||||||
|
|
||||||
|
/* This TableView is prepared to have the CSS,
|
||||||
|
* the methods to restore / save the state of
|
||||||
|
* the column widths and the 'plus' button.
|
||||||
|
*/
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
class QAbstractItemModel;
|
||||||
|
class QModelIndex;
|
||||||
|
class QTableView;
|
||||||
|
namespace Ui{
|
||||||
|
class TableView;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TableView : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TableView(QWidget *parent = 0);
|
||||||
|
virtual ~TableView();
|
||||||
|
void setTitle(const QString& title);
|
||||||
|
/* The model is expected to have a 'remove' slot, that takes a QModelIndex as parameter.
|
||||||
|
* It's also expected to have the column '1' as a trash icon. I most probably should create a
|
||||||
|
* proxy model and add that column, will mark that as TODO. see? marked.
|
||||||
|
*/
|
||||||
|
void setModel(QAbstractItemModel* model);
|
||||||
|
void setBtnToolTip(const QString& tooltip);
|
||||||
|
void fixPlusPosition();
|
||||||
|
void edit(const QModelIndex& index);
|
||||||
|
QTableView *view();
|
||||||
|
protected:
|
||||||
|
virtual void showEvent(QShowEvent* );
|
||||||
|
virtual void resizeEvent(QResizeEvent* );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void addButtonClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::TableView *ui;
|
||||||
|
QPushButton *plusBtn;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
63
qt-ui/tableview.ui
Normal file
63
qt-ui/tableview.ui
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>TableView</class>
|
||||||
|
<widget class="QWidget" name="TableView">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
<property name="title">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="tableView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Add table
Add a link
Reference in a new issue