Skip to content

Commit

Permalink
Widget framework
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 17, 2023
1 parent 58e52ed commit c332267
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -261,6 +261,7 @@ set(QGIS_GUI_SRCS
layout/qgslayoutattributetablewidget.cpp
layout/qgslayoutcombobox.cpp
layout/qgslayoutcustomdrophandler.cpp
layout/qgslayoutelevationprofilewidget.cpp
layout/qgslayoutguidewidget.cpp
layout/qgslayouthtmlwidget.cpp
layout/qgslayoutimageexportoptionsdialog.cpp
Expand Down Expand Up @@ -1143,6 +1144,7 @@ set(QGIS_GUI_HDRS
layout/qgslayoutcombobox.h
layout/qgslayoutcustomdrophandler.h
layout/qgslayoutdesignerinterface.h
layout/qgslayoutelevationprofilewidget.h
layout/qgslayoutguidewidget.h
layout/qgslayouthtmlwidget.h
layout/qgslayoutimageexportoptionsdialog.h
Expand Down
74 changes: 74 additions & 0 deletions src/gui/layout/qgslayoutelevationprofilewidget.cpp
@@ -0,0 +1,74 @@
/***************************************************************************
qgslayoutelevationprofilewidget.cpp
----------------------
begin : January 2023
copyright : (C) 2023 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#include "qgslayoutelevationprofilewidget.h"
#include "qgslayoutitemelevationprofile.h"
#include "qgslayoutitemwidget.h"
#include "qgslayoutitemregistry.h"

QgsLayoutElevationProfileWidget::QgsLayoutElevationProfileWidget( QgsLayoutItemElevationProfile *profile )
: QgsLayoutItemBaseWidget( nullptr, profile )
, mProfile( profile )
{
Q_ASSERT( mProfile );

setupUi( this );
setPanelTitle( tr( "Elevation Profile Properties" ) );

//add widget for general composer item properties
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, profile );
mainLayout->addWidget( mItemPropertiesWidget );
}

void QgsLayoutElevationProfileWidget::setMasterLayout( QgsMasterLayoutInterface *masterLayout )
{
if ( mItemPropertiesWidget )
mItemPropertiesWidget->setMasterLayout( masterLayout );
}

QgsExpressionContext QgsLayoutElevationProfileWidget::createExpressionContext() const
{
return mProfile->createExpressionContext();
}

bool QgsLayoutElevationProfileWidget::setNewItem( QgsLayoutItem *item )
{
if ( item->type() != QgsLayoutItemRegistry::LayoutElevationProfile )
return false;

if ( mProfile )
{
disconnect( mProfile, &QgsLayoutObject::changed, this, &QgsLayoutElevationProfileWidget::setGuiElementValues );
}

mProfile = qobject_cast< QgsLayoutItemElevationProfile * >( item );
mItemPropertiesWidget->setItem( mProfile );

if ( mProfile )
{
connect( mProfile, &QgsLayoutObject::changed, this, &QgsLayoutElevationProfileWidget::setGuiElementValues );
}

setGuiElementValues();

return true;
}

void QgsLayoutElevationProfileWidget::setGuiElementValues()
{

}
62 changes: 62 additions & 0 deletions src/gui/layout/qgslayoutelevationprofilewidget.h
@@ -0,0 +1,62 @@
/***************************************************************************
qgslayoutelevationprofilewidget.h
----------------------
begin : January 2023
copyright : (C) 2023 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/

#ifndef QGSLAYOUTELEVATIONPROFILEWIDGET_H
#define QGSLAYOUTELEVATIONPROFILEWIDGET_H

// We don't want to expose this in the public API
#define SIP_NO_FILE

#include "qgis_gui.h"
#include "ui_qgslayoutelevationprofilewidgetbase.h"
#include "qgslayoutitemwidget.h"
#include "qgslayoutitemelevationprofile.h"
#include <functional>
#include <QPointer>

/**
* \ingroup gui
* \brief A widget for layout elevation profile item settings.
*
* \note This class is not a part of public API
* \since QGIS 3.30
*/
class GUI_EXPORT QgsLayoutElevationProfileWidget: public QgsLayoutItemBaseWidget, public QgsExpressionContextGenerator, private Ui::QgsLayoutElevationProfileWidgetBase
{
Q_OBJECT
public:
//! constructor
explicit QgsLayoutElevationProfileWidget( QgsLayoutItemElevationProfile *profile );
void setMasterLayout( QgsMasterLayoutInterface *masterLayout ) override;
QgsExpressionContext createExpressionContext() const override;

protected:

bool setNewItem( QgsLayoutItem *item ) override;

private slots:

void setGuiElementValues();

private:

QPointer< QgsLayoutItemElevationProfile > mProfile = nullptr;

QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
};

#endif //QGSLAYOUTELEVATIONPROFILEWIDGET_H
4 changes: 2 additions & 2 deletions src/gui/layout/qgslayoutguiutils.cpp
Expand Up @@ -15,7 +15,6 @@

#include "qgslayoutguiutils.h"
#include "qgsgui.h"
#include "qgslayout.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutitemregistry.h"
#include "qgslayoutviewrubberband.h"
Expand Down Expand Up @@ -45,6 +44,7 @@
#include "qgslayoutattributetablewidget.h"
#include "qgslayoutitemmanualtable.h"
#include "qgslayoutmanualtablewidget.h"
#include "qgslayoutelevationprofilewidget.h"
#include "qgsmapcanvas.h"

/**
Expand Down Expand Up @@ -526,7 +526,7 @@ void QgsLayoutGuiUtils::registerGuiForKnownItemTypes( QgsMapCanvas *mapCanvas )
auto elevationProfileItemMetadata = std::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutElevationProfile, QObject::tr( "Elevation Profile" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionLabel.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return nullptr; //return new QgsLayoutLabelWidget( qobject_cast< QgsLayoutItemLabel * >( item ) );
return new QgsLayoutElevationProfileWidget( qobject_cast< QgsLayoutItemElevationProfile * >( item ) );
}, createRubberBand );
elevationProfileItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem *
{
Expand Down
92 changes: 92 additions & 0 deletions src/ui/layout/qgslayoutelevationprofilewidgetbase.ui
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsLayoutElevationProfileWidgetBase</class>
<widget class="QWidget" name="QgsLayoutElevationProfileWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>705</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Label Options</string>
</property>
<layout class="QVBoxLayout" name="_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="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">padding: 2px; font-weight: bold; background-color: rgb(200, 200, 200);</string>
</property>
<property name="text">
<string>Elevation Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QgsScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>358</width>
<height>681</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout"/>
</widget>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>
</tabstops>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

0 comments on commit c332267

Please sign in to comment.