WIP: combined installation and browser dialog

This commit is contained in:
Matthias Koefferlein 2017-03-25 10:15:24 +01:00
parent d160a5c27c
commit fee806704d
7 changed files with 737 additions and 851 deletions

View File

@ -1,313 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SaltGrainInstallationDialog</class>
<widget class="QDialog" name="SaltGrainInstallationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>692</width>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
<string>Salt Mine Repository Browser</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="rightMargin">
<number>4</number>
</property>
<item>
<widget class="QFrame" name="frame_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</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="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Repository</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_3">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<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="QToolButton" name="mark_button">
<property name="text">
<string>Install</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>126</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="lay::DecoratedLineEdit" name="lineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<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="QListView" name="salt_view">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="selectionRectVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QFrame" name="details_frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Details</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="lay::SaltGrainDetailsTextWidget" name="details_text">
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
<action name="actionNew">
<property name="icon">
<iconset resource="layResources.qrc">
<normaloff>:/add.png</normaloff>:/add.png</iconset>
</property>
<property name="text">
<string>New</string>
</property>
<property name="toolTip">
<string>New package</string>
</property>
</action>
<action name="actionDelete">
<property name="icon">
<iconset resource="layResources.qrc">
<normaloff>:/clear.png</normaloff>:/clear.png</iconset>
</property>
<property name="text">
<string>Delete</string>
</property>
<property name="toolTip">
<string>Delete package</string>
</property>
</action>
<action name="actionImport">
<property name="icon">
<iconset resource="layResources.qrc">
<normaloff>:/import.png</normaloff>:/import.png</iconset>
</property>
<property name="text">
<string>Import</string>
</property>
<property name="toolTip">
<string>Import package</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>lay::DecoratedLineEdit</class>
<extends>QLineEdit</extends>
<header>layWidgets.h</header>
</customwidget>
<customwidget>
<class>lay::SaltGrainDetailsTextWidget</class>
<extends>QTextBrowser</extends>
<header>laySaltGrainDetailsTextWidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>details_text</tabstop>
</tabstops>
<resources>
<include location="layResources.qrc"/>
</resources>
<connections>
<connection>
<sender>button_box</sender>
<signal>rejected()</signal>
<receiver>SaltGrainInstallationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>559</x>
<y>425</y>
</hint>
<hint type="destinationlabel">
<x>576</x>
<y>437</y>
</hint>
</hints>
</connection>
</connections>
</ui>

File diff suppressed because it is too large Load Diff

View File

@ -53,8 +53,7 @@ HEADERS = \
laySaltGrainDetailsTextWidget.h \
laySaltGrainPropertiesDialog.h \
laySaltDownloadManager.h \
laySaltModel.h \
laySaltGrainInstallationDialog.h
laySaltModel.h
FORMS = \
ClipDialog.ui \
@ -102,8 +101,7 @@ FORMS = \
MainConfigPage7.ui \
SaltManagerDialog.ui \
SaltGrainPropertiesDialog.ui \
SaltGrainTemplateSelectionDialog.ui \
SaltGrainInstallationDialog.ui
SaltGrainTemplateSelectionDialog.ui
SOURCES = \
gsiDeclLayApplication.cc \
@ -154,8 +152,7 @@ SOURCES = \
laySaltGrainDetailsTextWidget.cc \
laySaltGrainPropertiesDialog.cc \
laySaltDownloadManager.cc \
laySaltModel.cc \
laySaltGrainInstallationDialog.cc
laySaltModel.cc
RESOURCES = layBuildInMacros.qrc \
layHelpResources.qrc \

View File

@ -1,101 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "laySaltGrainInstallationDialog.h"
#include "laySaltModel.h"
#include "laySaltGrainPropertiesDialog.h"
#include "laySalt.h"
#include "ui_SaltGrainTemplateSelectionDialog.h"
#include "tlString.h"
#include "tlExceptions.h"
#include <QAbstractItemModel>
#include <QAbstractTextDocumentLayout>
#include <QStyledItemDelegate>
#include <QTextDocument>
#include <QPainter>
#include <QDir>
#include <QTextStream>
#include <QBuffer>
#include <QResource>
#include <QMessageBox>
namespace lay
{
// --------------------------------------------------------------------------------------
// SaltGrainInstallation implementation
SaltGrainInstallationDialog::SaltGrainInstallationDialog (QWidget *parent, lay::Salt *salt)
: QDialog (parent), mp_salt (salt)
{
Ui::SaltGrainInstallationDialog::setupUi (this);
// TODO: cache package list
// @@@
m_salt_mine.load ("/home/matthias/salt.mine");
// @@@
SaltModel *model = new SaltModel (this, &m_salt_mine);
salt_view->setModel (model);
salt_view->setItemDelegate (new SaltItemDelegate (this));
salt_view->setCurrentIndex (model->index (0, 0, QModelIndex ()));
connect (salt_view->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (current_changed ()));
connect (mark_button, SIGNAL (clicked ()), this, SLOT (mark ()));
connect (button_box->button (QDialogButtonBox::Apply), SIGNAL (clicked ()), this, SLOT (apply ()));
current_changed ();
}
void
SaltGrainInstallationDialog::current_changed ()
{
SaltGrain *g = current_grain ();
details_text->set_grain (g);
details_frame->setEnabled (g != 0);
}
lay::SaltGrain *
SaltGrainInstallationDialog::current_grain ()
{
SaltModel *model = dynamic_cast <SaltModel *> (salt_view->model ());
return model ? model->grain_from_index (salt_view->currentIndex ()) : 0;
}
void
SaltGrainInstallationDialog::apply ()
{
// @@@
}
void
SaltGrainInstallationDialog::mark ()
{
// @@@
}
}

View File

@ -1,76 +0,0 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_laySaltGrainInstallationDialog
#define HDR_laySaltGrainInstallationDialog
#include "laySalt.h"
#include <QDialog>
#include "ui_SaltGrainInstallationDialog.h"
namespace lay
{
class Salt;
/**
* @brief The dialog for managing the Salt ("Packages")
*/
class SaltGrainInstallationDialog
: public QDialog, private Ui::SaltGrainInstallationDialog
{
Q_OBJECT
public:
/**
* @brief Constructor
*/
SaltGrainInstallationDialog (QWidget *parent, lay::Salt *salt);
private slots:
/**
* @brief Called when the currently selected package (grain) has changed
*/
void current_changed ();
/**
* @brief Called when the Apply button is clicked
*/
void apply ();
/**
* @brief Called when the Mark button is pressed
*/
void mark ();
private:
lay::Salt *mp_salt;
lay::Salt m_salt_mine;
lay::SaltGrain *current_grain ();
};
}
#endif

View File

@ -23,7 +23,6 @@
#include "laySaltManagerDialog.h"
#include "laySaltModel.h"
#include "laySaltGrainPropertiesDialog.h"
#include "laySaltGrainInstallationDialog.h"
#include "laySalt.h"
#include "ui_SaltGrainTemplateSelectionDialog.h"
#include "tlString.h"
@ -119,6 +118,25 @@ void make_salt ()
salt.add_location (tl::to_string (QDir::homePath () + QString::fromUtf8("/.klayout/salt")));
}
}
lay::Salt *get_salt ()
{
salt = lay::Salt (); salt_initialized = false;
make_salt ();
return &salt;
}
// @@@
// @@@
lay::Salt salt_mine;
void make_salt_mine ()
{
salt_mine.load ("/home/matthias/salt.mine");
}
lay::Salt *get_salt_mine ()
{
make_salt_mine();
return &salt_mine;
}
// @@@
SaltManagerDialog::SaltManagerDialog (QWidget *parent)
@ -131,27 +149,46 @@ SaltManagerDialog::SaltManagerDialog (QWidget *parent)
connect (edit_button, SIGNAL (clicked ()), this, SLOT (edit_properties ()));
connect (create_button, SIGNAL (clicked ()), this, SLOT (create_grain ()));
connect (delete_button, SIGNAL (clicked ()), this, SLOT (delete_grain ()));
connect (install_button, SIGNAL (clicked ()), this, SLOT (install_grain ()));
// @@@
salt = lay::Salt (); salt_initialized = false;
make_salt ();
mp_salt = &salt;
// @@@
mp_salt = get_salt ();
mp_salt_mine = get_salt_mine ();
SaltModel *model = new SaltModel (this, mp_salt);
SaltModel *model;
model = new SaltModel (this, mp_salt);
salt_view->setModel (model);
salt_view->setItemDelegate (new SaltItemDelegate (this));
model = new SaltModel (this, mp_salt_mine);
salt_mine_view->setModel (model);
salt_mine_view->setItemDelegate (new SaltItemDelegate (this));
mode_tab->setCurrentIndex (mp_salt->is_empty () ? 1 : 0);
connect (mode_tab, SIGNAL (currentChanged (int)), this, SLOT (mode_changed ()));
connect (mp_salt, SIGNAL (collections_changed ()), this, SLOT (salt_changed ()));
connect (mp_salt_mine, SIGNAL (collections_changed ()), this, SLOT (salt_mine_changed ()));
salt_changed ();
salt_mine_changed ();
connect (salt_view->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (current_changed ()));
connect (salt_mine_view->selectionModel (), SIGNAL (currentChanged (const QModelIndex &, const QModelIndex &)), this, SLOT (mine_current_changed ()));
// @@@
}
void
SaltManagerDialog::mode_changed ()
{
// keeps the splitters in sync
if (mode_tab->currentIndex () == 1) {
splitter_new->setSizes (splitter->sizes ());
} else if (mode_tab->currentIndex () == 0) {
splitter->setSizes (splitter_new->sizes ());
}
}
void
SaltManagerDialog::edit_properties ()
{
@ -159,7 +196,6 @@ SaltManagerDialog::edit_properties ()
if (g) {
if (mp_properties_dialog->exec_dialog (g, mp_salt)) {
current_changed ();
// @@@
}
}
}
@ -218,18 +254,6 @@ BEGIN_PROTECTED
END_PROTECTED
}
void
SaltManagerDialog::install_grain ()
{
BEGIN_PROTECTED
// @@@ TODO: cache this somewhere - don't recreate this dialog always
SaltGrainInstallationDialog inst_dialog (this, mp_salt);
inst_dialog.exec ();
END_PROTECTED
}
void
SaltManagerDialog::salt_changed ()
{
@ -286,4 +310,41 @@ SaltManagerDialog::current_grain ()
return model ? model->grain_from_index (salt_view->currentIndex ()) : 0;
}
void
SaltManagerDialog::salt_mine_changed ()
{
SaltModel *model = dynamic_cast <SaltModel *> (salt_mine_view->model ());
if (! model) {
return;
}
// NOTE: the disabling of the event handler prevents us from
// letting the model connect to the salt's signal directly.
m_current_changed_enabled = false;
model->update ();
m_current_changed_enabled = true;
// select the first grain
if (model->rowCount (QModelIndex ()) > 0) {
salt_mine_view->setCurrentIndex (model->index (0, 0, QModelIndex ()));
}
mine_current_changed ();
}
void
SaltManagerDialog::mine_current_changed ()
{
SaltGrain *g = mine_current_grain ();
details_new_text->set_grain (g);
details_new_frame->setEnabled (g != 0);
}
lay::SaltGrain *
SaltManagerDialog::mine_current_grain ()
{
SaltModel *model = dynamic_cast <SaltModel *> (salt_mine_view->model ());
return model ? model->grain_from_index (salt_mine_view->currentIndex ()) : 0;
}
}

View File

@ -54,11 +54,21 @@ private slots:
*/
void salt_changed ();
/**
* @brief Called when the repository (salt mine) has changed
*/
void salt_mine_changed ();
/**
* @brief Called when the currently selected package (grain) has changed
*/
void current_changed ();
/**
* @brief Called when the currently selected package from the salt mine has changed
*/
void mine_current_changed ();
/**
* @brief Called when the "edit" button is pressed
*/
@ -79,12 +89,18 @@ private slots:
*/
void install_grain ();
/**
* @brief Called when the mode tab changed
*/
void mode_changed ();
private:
lay::Salt *mp_salt;
lay::Salt *mp_salt, *mp_salt_mine;
bool m_current_changed_enabled;
lay::SaltGrainPropertiesDialog *mp_properties_dialog;
lay::SaltGrain *current_grain ();
lay::SaltGrain *mine_current_grain ();
};
}