Skip to content

Commit a9ffeb1

Browse files
author
timlinux
committedFeb 18, 2011
[FEATURE] Not sure how we coped without this till now...we now have a tip presented at startup. You can en/disable tips in the options panel. To contribute more tips, please add them to src/app/qgstipfactory.cpp
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15198 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

6 files changed

+510
-0
lines changed

6 files changed

+510
-0
lines changed
 

‎src/app/qgstip.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/***************************************************************************
2+
* Copyright (C) 2007 by Tim Sutton *
3+
* tim@linfiniti.com *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU General Public License as published by *
7+
* the Free Software Foundation; either version 2 of the License, or *
8+
* (at your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the GNU General Public License *
16+
* along with this program; if not, write to the *
17+
* Free Software Foundation, Inc., *
18+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19+
***************************************************************************/
20+
21+
#ifndef QGSTIP
22+
#define QGSTIP
23+
24+
#include <QObject>
25+
#include <QString>
26+
27+
/** \ingroup app
28+
* \brief An QgsTip represents a tip generated by the
29+
* QgsTipFactory factory class to serve up tips to the user.
30+
* Tips can be generic, in which case they make no mention of
31+
* gui dialogs etc, or gui-secific in which case they may allude
32+
* to features of the graphical user interface.
33+
* @see also QgsTipOfTheDay, QgsTipFactory
34+
*/
35+
36+
class QgsTip
37+
{
38+
public:
39+
/** Constructor */
40+
QgsTip() {};
41+
/**Destructor */
42+
~QgsTip() {};
43+
//
44+
// Accessors
45+
//
46+
/** Get the tip title */
47+
QString title() {return mTitle;};
48+
/** Get the tip content */
49+
QString content() {return mContent;}
50+
51+
//
52+
// Mutators
53+
//
54+
/** Set the tip title */
55+
void setTitle(QString theTitle) {mTitle = theTitle;};
56+
/** Set the tip content*/
57+
void setContent(QString theContent) {mContent = theContent;};
58+
private:
59+
QString mTitle;
60+
QString mContent;
61+
};
62+
63+
#endif //QGSTIP
64+

‎src/app/qgstipfactory.cpp

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/***************************************************************************
2+
* Copyright (C) 2007 by Tim Sutton *
3+
* tim@linfiniti.com *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU General Public License as published by *
7+
* the Free Software Foundation; either version 2 of the License, or *
8+
* (at your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the GNU General Public License *
16+
* along with this program; if not, write to the *
17+
* Free Software Foundation, Inc., *
18+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19+
***************************************************************************/
20+
21+
22+
#include "omgtipfactory.h"
23+
#include <QTime>
24+
//for rand & srand
25+
#include <cstdlib>
26+
27+
28+
OmgTipFactory::OmgTipFactory() : QObject()
29+
{
30+
// Im just doing this in a simple way so
31+
// its easy for translators...later
32+
// it its worth the time Ill move this data
33+
// into a sqlite database...
34+
OmgTip myTip;
35+
myTip.setTitle(tr("openModeller is open source"));
36+
myTip.setContent(tr("openModeller is open source software."
37+
" This means that the software source code can be freely viewed "
38+
" and modified. The GPL places a restriction that any modifications "
39+
" you make must be made available to the openModeller project, and "
40+
" that you can not create a new version of openModeller under a "
41+
" 'closed source' license. Visit <a href=\"http://openModeller.sf.net\">"
42+
" the openModeller home page (http://openModeller.sf.net)</a> for more"
43+
" information."));
44+
addGenericTip(myTip);
45+
//
46+
myTip.setTitle(tr("openModeller Publications"));
47+
myTip.setContent(tr("If you write a scientific paper or any other article"
48+
" that refers to openModeller we would love to include your work"
49+
" in the references section of "
50+
" the openModeller home page (http://openModeller.sf.net).</a>"
51+
));
52+
addGenericTip(myTip);
53+
myTip.setTitle(tr("Become an openModeller Desktop translator"));
54+
myTip.setContent(tr("Would you like to see openModeller Desktop"
55+
" in your native language? We are looking for more translators"
56+
" and would appreciate your help! The translation process is "
57+
" fairly straight forward - instructions are available in the "
58+
" resources section of "
59+
" the openModeller home page (http://openModeller.sf.net).</a>"
60+
));
61+
addGuiTip(myTip);
62+
myTip.setTitle(tr("openModeller Mailing lists"));
63+
myTip.setContent(tr("If you need help using openModeller Desktop"
64+
" we have a mailing list where users help each other with issues"
65+
" related to niche modelling and using openModeller Desktop."
66+
" Details on how to subscribe are in the resources section of"
67+
" the openModeller home page (http://openModeller.sf.net).</a>"
68+
));
69+
addGuiTip(myTip);
70+
myTip.setTitle(tr("Is it 'modelling' or 'modeling'?"));
71+
myTip.setContent(tr("Both spellings are correct. For openModeller"
72+
" we use the former spelling."
73+
));
74+
addGenericTip(myTip);
75+
myTip.setTitle(tr("How do I refer to openModeller?"));
76+
myTip.setContent(tr("openModeller is spelled with a lower case"
77+
" 'o' at the start of the word - even if its the beginning"
78+
" of a sentance. We have various subprojects of the openModeller "
79+
" project and it will help to avoid confusion if you refer to each by"
80+
" its name:"
81+
"<ul>"
82+
"<li>openModeller Library - this is the C++ library that contains"
83+
" the core logic for carrying out niche modelling"
84+
"<li>openModeller Console - these are a collection of command"
85+
" line tools that allow you to run niche models from a unix or"
86+
" DOS shell, or from a scripting environment."
87+
"<li>openModeller Web Service - The openModeller Web Service"
88+
" allows for remote execution of niche models."
89+
"<li>openModeller Desktop - the openModeller Desktop provides"
90+
" a graphical user interface for the openModeller Library. It"
91+
" also includes the capability to run models using the"
92+
" openModeller Web Service (though this is still considered"
93+
" experimental)."
94+
"</ul>"
95+
));
96+
addGenericTip(myTip);
97+
myTip.setTitle(tr("How can I improve model execution times?"));
98+
myTip.setContent(tr("Model processing time is typically determined by"
99+
"<ul>"
100+
"<li>the algorithm you select,</li>"
101+
"<li>the number, extents and spatial resolution of your format and environmental layers,</li>"
102+
"<li>the number of cells excluded by your mask (if any),</li>"
103+
"<li>in some cases the number of presence and absence points (e.g. distance algs),</li>"
104+
"<li>the speed of the computer the model is running on (CPU, disk access etc).</li>"
105+
"</ul>"
106+
"So if you want to improve model processing times you need to adjust "
107+
"one of these variables. One thing noticed quite commonly is that people "
108+
"use extremely high resolution datasets that often carry little "
109+
"additional information over lower resolution equivalents. For example "
110+
"interpolating widely dispersed weather station data to produce a 50cm "
111+
"raster probably carries little additional value over for example using "
112+
"10m2 pixels.<br>"
113+
"Another area of performance improvement you can look at is "
114+
"preselecting environmental variables using techniques such as Chi "
115+
"Square test. Future versions of openModeller will integrate the ability "
116+
"to do this type of preselection."
117+
));
118+
addGenericTip(myTip);
119+
/* Template for adding more tips
120+
myTip.setTitle(tr(""));
121+
myTip.setContent(tr(""
122+
));
123+
addGenericTip(myTip);
124+
*/
125+
}
126+
127+
OmgTipFactory::~OmgTipFactory()
128+
{
129+
130+
}
131+
//private helper method
132+
void OmgTipFactory::addGuiTip(OmgTip theTip)
133+
{
134+
mGuiTips << theTip;
135+
mAllTips << theTip;
136+
}
137+
//private helper method
138+
void OmgTipFactory::addGenericTip(OmgTip theTip)
139+
{
140+
mGenericTips << theTip;
141+
mAllTips << theTip;
142+
}
143+
OmgTip OmgTipFactory::getTip()
144+
{
145+
srand(QTime::currentTime().msec());
146+
int myRand = rand();
147+
int myValue = static_cast<int> (myRand % mAllTips.count()); //range [0,(count-1)]
148+
OmgTip myTip = mAllTips.at(myValue);
149+
return myTip;
150+
}
151+
OmgTip OmgTipFactory::getTip(int thePosition)
152+
{
153+
OmgTip myTip = mAllTips.at(thePosition);
154+
return myTip;
155+
}
156+
OmgTip OmgTipFactory::getGenericTip()
157+
{
158+
srand(QTime::currentTime().msec());
159+
int myRand = rand();
160+
int myValue = static_cast<int> (myRand % mGenericTips.count()); //range [0,(count-1)]
161+
OmgTip myTip = mGenericTips.at(myValue);
162+
return myTip;
163+
}
164+
OmgTip OmgTipFactory::getGuiTip()
165+
{
166+
srand(QTime::currentTime().msec());
167+
int myRand = rand();
168+
int myValue = static_cast<int> (myRand % mGuiTips.count()); //range [0,(count-1)]
169+
OmgTip myTip = mGuiTips.at(myValue);
170+
return myTip;
171+
}
172+
int OmgTipFactory::randomNumber(int theMax)
173+
{
174+
return 0;
175+
}
176+

‎src/app/qgstipfactory.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/***************************************************************************
2+
* Copyright (C) 2007 by Tim Sutton *
3+
* tim@linfiniti.com *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU General Public License as published by *
7+
* the Free Software Foundation; either version 2 of the License, or *
8+
* (at your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the GNU General Public License *
16+
* along with this program; if not, write to the *
17+
* Free Software Foundation, Inc., *
18+
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19+
***************************************************************************/
20+
21+
#ifndef OMGTIPFACTORY
22+
#define OMGTIPFACTORY
23+
24+
#include "omgtip.h"
25+
#include <QList>
26+
27+
/** \ingroup lib
28+
* \brief A factory class to serve up tips to the user.
29+
* Tips can be generic, in which case they make no mention of
30+
* gui dialogs etc, or gui-secific in which case they may allude
31+
* to features of the graphical user interface.
32+
* @see also OmgTipOfTheDay, OmgTip
33+
*/
34+
35+
class OMG_LIB_EXPORT OmgTipFactory : public QObject
36+
{
37+
Q_OBJECT; //used for tr() so we dont need to do QObject::tr()
38+
public:
39+
/** Constructor */
40+
OmgTipFactory();
41+
/** Destructor */
42+
~OmgTipFactory();
43+
/** Get a random tip (generic or gui-centric)
44+
* @return An OmgTip containing the tip
45+
*/
46+
OmgTip getTip();
47+
/** Get a specific tip (generic or gui-centric).
48+
* @param thePosition The tip returned will be based on the
49+
* number passed in as thePosition. If the
50+
* position is invalid, an empty string will be
51+
* returned.
52+
* @return An OmgTip containing the tip
53+
*/
54+
OmgTip getTip(int thePosition);
55+
/** Get a random generic tip
56+
* @return An OmgTip containing the tip
57+
*/
58+
OmgTip getGenericTip();
59+
/** Get a random gui-centric tip
60+
* @return An OmgTip containing the tip
61+
*/
62+
OmgTip getGuiTip();
63+
64+
private:
65+
void addGenericTip(OmgTip);
66+
void addGuiTip(OmgTip);
67+
int randomNumber(int theMax);
68+
//@TODO move tipts into a sqlite db
69+
QList <OmgTip> mGenericTips;
70+
QList <OmgTip> mGuiTips;
71+
QList <OmgTip> mAllTips;
72+
};
73+
#endif //OMGTIPFACTORY
74+

‎src/app/qgstipgui.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/***************************************************************************
2+
qgstipgui.cpp - description
3+
-------------------
4+
begin : Sat Aug 10 2002
5+
copyright : (C) 2002 by Gary E.Sherman
6+
email : sherman at mrcc.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id$ */
18+
19+
#include <QSettings>
20+
#include "qgstipgui.h"
21+
#include "qgsapplication.h"
22+
#include <qgstip.h>
23+
#include <qgstipfactory.h>
24+
25+
#ifdef Q_OS_MACX
26+
QgsTipGui::QgsTipGui()
27+
: QDialog( NULL, Qt::WindowSystemMenuHint ) // Modeless dialog with close button only
28+
#else
29+
QgsTipGui::QgsTipGui()
30+
: QDialog( NULL ) // Normal dialog in non Mac-OS
31+
#endif
32+
{
33+
setupUi( this );
34+
init();
35+
}
36+
37+
QgsTipGui::~QgsTipGui()
38+
{
39+
}
40+
41+
void QgsTipGui::init()
42+
{
43+
44+
// set the 60x60 icon pixmap
45+
QPixmap icon( QgsApplication::iconsPath() + "qgis-icon-60x60.png" );
46+
qgisIcon->setPixmap( icon );
47+
QgsTipFactory myFactory;
48+
QgsTip myTip = myFactory.getTip();
49+
lblTitle->setText(myTip.title());
50+
txtTip->setHtml(myTip.content());
51+
52+
}
53+
54+
void QgsTipGui::on_cbxDisableTips_toggled(bool theFlag)
55+
{
56+
QSettings settings;
57+
//note the ! below as when the cbx is checked (true) we want to
58+
//change the setting to false
59+
settings.setValue( "/qgis/showTips", !theFlag );
60+
hide();
61+
}

‎src/app/qgstipgui.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/***************************************************************************
2+
qgstipgui.h - description
3+
-------------------
4+
begin : Fri 18 Feb 2011
5+
copyright : (C) 2011 by Tim Sutton
6+
email : tim@linfiniti.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id:$ */
18+
#ifndef QGSTIPGUI_H
19+
#define QGSTIPGUI_H
20+
21+
#include "ui_qgstipguibase.h"
22+
23+
class QgsTipGui : public QDialog, private Ui::QgsTipGuiBase
24+
{
25+
Q_OBJECT
26+
public:
27+
QgsTipGui();
28+
~QgsTipGui();
29+
30+
private:
31+
void init();
32+
33+
private slots:
34+
void on_cbxDisableTips_toggled(bool theFlag);
35+
};
36+
37+
#endif

‎src/ui/qgstipguibase.ui

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsTipGuiBase</class>
4+
<widget class="QDialog" name="QgsTipGuiBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>492</width>
10+
<height>283</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>QGIS Tips!</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<widget class="QLabel" name="qgisIcon">
19+
<property name="text">
20+
<string>TextLabel</string>
21+
</property>
22+
</widget>
23+
</item>
24+
<item row="0" column="1" colspan="2">
25+
<widget class="QTextBrowser" name="txtTip">
26+
<property name="sizePolicy">
27+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
28+
<horstretch>0</horstretch>
29+
<verstretch>0</verstretch>
30+
</sizepolicy>
31+
</property>
32+
<property name="html">
33+
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
34+
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
35+
p, li { white-space: pre-wrap; }
36+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
37+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;A nice tip goes here...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
38+
</property>
39+
<property name="openExternalLinks">
40+
<bool>true</bool>
41+
</property>
42+
</widget>
43+
</item>
44+
<item row="1" column="1" colspan="2">
45+
<widget class="QCheckBox" name="checkBox">
46+
<property name="text">
47+
<string>I've had enough tips, don't show this on start up any more!</string>
48+
</property>
49+
</widget>
50+
</item>
51+
<item row="2" column="2">
52+
<widget class="QDialogButtonBox" name="buttonBox">
53+
<property name="orientation">
54+
<enum>Qt::Horizontal</enum>
55+
</property>
56+
<property name="standardButtons">
57+
<set>QDialogButtonBox::Ok</set>
58+
</property>
59+
</widget>
60+
</item>
61+
</layout>
62+
</widget>
63+
<resources/>
64+
<connections>
65+
<connection>
66+
<sender>buttonBox</sender>
67+
<signal>accepted()</signal>
68+
<receiver>QgsTipGuiBase</receiver>
69+
<slot>accept()</slot>
70+
<hints>
71+
<hint type="sourcelabel">
72+
<x>248</x>
73+
<y>254</y>
74+
</hint>
75+
<hint type="destinationlabel">
76+
<x>157</x>
77+
<y>274</y>
78+
</hint>
79+
</hints>
80+
</connection>
81+
<connection>
82+
<sender>buttonBox</sender>
83+
<signal>rejected()</signal>
84+
<receiver>QgsTipGuiBase</receiver>
85+
<slot>reject()</slot>
86+
<hints>
87+
<hint type="sourcelabel">
88+
<x>316</x>
89+
<y>260</y>
90+
</hint>
91+
<hint type="destinationlabel">
92+
<x>286</x>
93+
<y>274</y>
94+
</hint>
95+
</hints>
96+
</connection>
97+
</connections>
98+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.