ticket892fix.diff

final patch file - Fernando Pacheco -, 2008-01-07 07:11 AM

Download (14.4 KB)

View differences:

src/app/qgisapp.cpp (copia de trabajo)
3662 3662
void QgisApp::showPluginManager()
3663 3663
{
3664 3664
  QgsPluginManager *pm = new QgsPluginManager(this);
3665
  pm->resizeColumnsToContents(); 
3665 3666
  if (pm->exec())
3666 3667
  {
3667 3668
    // load selected plugins
src/app/qgspluginmanager.cpp (copia de trabajo)
22 22
#include <QApplication>
23 23
#include <QFileDialog>
24 24
#include <QLineEdit>
25
#include <Q3ListView>
26 25
#include <QMessageBox>
27 26
#include <QLibrary>
28 27
#include <QSettings>
......
60 59
     QString libDir = baseDir + "/lib"; */
61 60

  
62 61
  txtPluginDir->setText(pr->libraryDirectory().path());
62
  setTable();
63 63
  getPluginDescriptions();
64 64
  getPythonPluginDescriptions();
65 65
}
......
69 69
{
70 70
}
71 71

  
72
void QgsPluginManager::setTable()
73
{
74
  lstPlugins->setAlternatingRowColors(true);
75
  modelPlugins= new QStandardItemModel(0,4);
76
  modelPlugins->setHorizontalHeaderItem(0,new QStandardItem(tr("Name")));
77
  modelPlugins->setHorizontalHeaderItem(1,new QStandardItem(tr("Version")));
78
  modelPlugins->setHorizontalHeaderItem(2,new QStandardItem(tr("Description")));
79
  modelPlugins->setHorizontalHeaderItem(3,new QStandardItem(tr("Library name")));
80
  lstPlugins->setModel(modelPlugins);
81
  // No vertical headers
82
  lstPlugins->verticalHeader()->hide();
83
}
72 84

  
85
void QgsPluginManager::resizeColumnsToContents()
86
{
87
  // Resize columns to contents.
88
  lstPlugins->resizeColumnsToContents();
89
  QgsDebugMsg("QgsPluginManager::resizeColumnsToContents\n");
90
}
91

  
92
void QgsPluginManager::sortModel(int column)
93
{
94
  // Sort column ascending.
95
  modelPlugins->sort(column);
96
  QgsDebugMsg("QgsPluginManager::sortModel\n");
97
}
98

  
73 99
void QgsPluginManager::getPythonPluginDescriptions()
74 100
{
75 101
#ifdef HAVE_PYTHON
......
94 120
    
95 121
    if (pluginName == "???" || description == "???" || version == "???")
96 122
      continue;
97
    
98
    // add to the list box
99
    Q3CheckListItem *pl = new Q3CheckListItem(lstPlugins, pluginName, Q3CheckListItem::CheckBox);
100
    pl->setText(1, version);
101
    pl->setText(2, description);
102
    pl->setText(3, "python:" + packageName);
103
  
123

  
124
    //create the items
125
    QStandardItem *myName=new QStandardItem(pluginName);
126
    QStandardItem *myVersion=new QStandardItem(version);
127
    QStandardItem *myDesc=new QStandardItem(description);
128
    QStandardItem *myDir=new QStandardItem("python:" + packageName);
129
    // myName have a checkbox
130
    myName->setCheckable(true);
131
    //read only
132
    myName->setEditable(false);
133
    myVersion->setEditable(false);
134
    myDesc->setEditable(false);
135
    myDir->setEditable(false);
136

  
104 137
    // check to see if the plugin is loaded and set the checkbox accordingly
105 138
    QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
106
    
139

  
107 140
    QString libName = pRegistry->library(pluginName);
108 141
    if (libName.length() == 0 || !pRegistry->isPythonPlugin(pluginName))
109 142
    {
......
115 148
      if (libName == packageName)
116 149
      {
117 150
        // set the checkbox
118
        pl->setOn(true);
151
        myName->setCheckState(Qt::Checked);
119 152
      }
120 153
    }
154
    // Add items to model
155
    QList<QStandardItem *> myItems;
156
    myItems << myName << myVersion << myDesc << myDir;
157
    modelPlugins->appendRow(myItems);
121 158
  }
122 159
#endif
123 160
}
......
223 260
      continue;
224 261
    }
225 262

  
226
    Q3CheckListItem *pl = new Q3CheckListItem(lstPlugins, pName(), Q3CheckListItem::CheckBox); //, pDesc(), pluginDir[i])
227
    pl->setText(1, pVersion());
228
    pl->setText(2, pDesc());
229
    pl->setText(3, pluginDir[i]);
263
    //create the items
264
    QStandardItem *myName=new QStandardItem(pName());
265
    QStandardItem *myVersion=new QStandardItem(pVersion());
266
    QStandardItem *myDesc=new QStandardItem(pDesc());
267
    QStandardItem *myDir=new QStandardItem(pluginDir[i]);
268
    // myName have a checkbox
269
    myName->setCheckable(true);
270
    //read only
271
    myName->setEditable(false);
272
    myVersion->setEditable(false);
273
    myDesc->setEditable(false);
274
    myDir->setEditable(false);
230 275

  
231 276
    QgsDebugMsg("Getting an instance of the QgsPluginRegistry");
232 277

  
......
245 290
      if (libName == myLib->library())
246 291
      {
247 292
        // set the checkbox
248
        pl->setOn(true);
293
        myName->setCheckState(Qt::Checked);
249 294
      }
250 295
    }
296
    // Add items to model
297
    QList<QStandardItem *> myItems;
298
    myItems << myName << myVersion << myDesc << myDir;
299
    modelPlugins->appendRow(myItems);
251 300

  
252 301
    delete myLib;
253 302
  }
254 303
}
255 304

  
256

  
257 305
void QgsPluginManager::on_btnOk_clicked()
258 306
{
259 307
  unload();
......
266 314
#ifdef QGISDEBUG
267 315
  std::cout << "Checking for plugins to unload" << std::endl;
268 316
#endif
269
  Q3CheckListItem *lvi = (Q3CheckListItem *) lstPlugins->firstChild();
270
  while (lvi != 0)
317
  for (int row=0;row < modelPlugins->rowCount();row++)
318
  {
319
    // FPV - I want to use index. You can do evrething with item.
320
    QModelIndex myIndex=modelPlugins->index(row,0);
321
    if (modelPlugins->data(myIndex,Qt::CheckStateRole).toInt() == 0)
271 322
    {
272
      if (!lvi->isOn())
273
        {
274
          // its off -- see if it is loaded and if so, unload it
275
          QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
323
      // its off -- see if it is loaded and if so, unload it
324
      QgsPluginRegistry *pRegistry = QgsPluginRegistry::instance();
276 325
#ifdef QGISDEBUG
277
          std::cout << "Checking to see if " << lvi->text(0).toLocal8Bit().data() << " is loaded" << std::endl;
326
      std::cout << "Checking to see if " << modelPlugins->data(myIndex).toString().toLocal8Bit().data() << " is loaded" << std::endl;
278 327
#endif
279
          
280
          QString pluginName = lvi->text(0);
281

  
282
          if (pRegistry->isPythonPlugin(pluginName))
283
          {
328
      QString pluginName = modelPlugins->data(myIndex).toString();
329
      if (pRegistry->isPythonPlugin(pluginName))
330
      {
284 331
#ifdef HAVE_PYTHON
285
            QString packageName = pRegistry->library(pluginName);
286
            QgsPythonUtils::unloadPlugin(packageName);
287

  
288
            //disable it to the qsettings file
289
            settings.writeEntry("/PythonPlugins/" + packageName, false);
332
        QString packageName = pRegistry->library(pluginName);
333
        QgsPythonUtils::unloadPlugin(packageName);
334
          //disable it to the qsettings file
335
        settings.setValue("/PythonPlugins/" + packageName, false);
290 336
#endif
291
          }
292
          else // C++ plugin
293
          {
294
            QgisPlugin *plugin = pRegistry->plugin(pluginName);
295
            if (plugin)
296
            {
297
              plugin->unload();
298
            }
299
            //disable it to the qsettings file [ts]
300
            settings.writeEntry("/Plugins/" + pluginName, false);
301
          }
302

  
303
          // remove the plugin from the registry
304
          pRegistry->removePlugin(pluginName);
337
      }
338
      else // C++ plugin
339
      {
340
        QgisPlugin *plugin = pRegistry->plugin(pluginName);
341
        if (plugin)
342
        {
343
          plugin->unload();
305 344
        }
306
      lvi = (Q3CheckListItem *) lvi->nextSibling();
345
        //disable it to the qsettings file [ts]
346
        settings.setValue("/Plugins/" + pluginName, false);
347
      }
348
      // remove the plugin from the registry
349
      pRegistry->removePlugin(pluginName);
307 350
    }
351
  }
308 352
}
309 353

  
310 354
std::vector < QgsPluginItem > QgsPluginManager::getSelectedPlugins()
311 355
{
312 356
  std::vector < QgsPluginItem > pis;
313
  Q3CheckListItem *lvi = (Q3CheckListItem *) lstPlugins->firstChild();
314
  while (lvi != 0)
357
  // FPV - I want to use item here. You can do everything with index if you want.
358
  for (int row=0;row < modelPlugins->rowCount();row++)
315 359
  {
316
    if (lvi->isOn())
360
    QStandardItem *myItem=modelPlugins->item(row,0);
361
    if (modelPlugins->item(row,0)->checkState() == Qt::Checked)
317 362
    {
318
      QString pluginName = lvi->text(0);
363
      QString pluginName = modelPlugins->item(row,0)->text();
319 364
      bool pythonic = false;
320
      
321
      QString library = lvi->text(3);
365

  
366
      QString library = modelPlugins->item(row,3)->text();
322 367
      if (library.left(7) == "python:")
323 368
      {
324 369
        library = library.mid(7);
......
328 373
      {
329 374
        library = txtPluginDir->text() + "/" + library;
330 375
      }
331
      
332
      pis.push_back(QgsPluginItem(pluginName, lvi->text(2), library, 0, pythonic));
376
      pis.push_back(QgsPluginItem(pluginName, modelPlugins->item(row,2)->text(), library, 0, pythonic));
333 377
    }
334
    lvi = (Q3CheckListItem *) lvi->nextSibling();
378

  
335 379
  }
336 380
  return pis;
337 381
}
......
339 383
void QgsPluginManager::on_btnSelectAll_clicked()
340 384
{
341 385
  // select all plugins
342
  Q3CheckListItem *child = dynamic_cast<Q3CheckListItem *>(lstPlugins->firstChild());
343
  while(child)
386
  for (int row=0;row < modelPlugins->rowCount();row++)
344 387
  {
345
    child->setOn(true);
346
    child = dynamic_cast<Q3CheckListItem *>(child->nextSibling());
388
    QStandardItem *myItem=modelPlugins->item(row,0);
389
    myItem->setCheckState(Qt::Checked);
347 390
  }
348

  
349 391
}
350 392

  
351 393
void QgsPluginManager::on_btnClearAll_clicked()
352 394
{
353
  // clear all selection checkboxes 
354
  Q3CheckListItem *child = dynamic_cast<Q3CheckListItem *>(lstPlugins->firstChild());
355
  while(child)
395
  // clear all selection checkboxes
396
  for (int row=0;row < modelPlugins->rowCount();row++)
356 397
  {
357
    child->setOn(false);
358
    child = dynamic_cast<Q3CheckListItem *>(child->nextSibling());
398
    QStandardItem *myItem=modelPlugins->item(row,0);
399
    myItem->setCheckState(Qt::Unchecked);
359 400
  }
360 401
}
361 402

  
src/app/qgspluginmanager.h (copia de trabajo)
19 19
#ifndef QGSPLUGINMANAGER_H
20 20
#define QGSPLUGINMANAGER_H
21 21
#include <vector>
22
#include <QTableView>
23
#include <QStandardItemModel>
24
#include <QStandardItem>
25
#include <QHeaderView>
22 26
#include "ui_qgspluginmanagerbase.h"
23 27
#include "qgisgui.h"
24 28

  
25 29
class QgsPluginItem;
30
class QTableView;
31

  
26 32
/*!
27 33
 * \brief Plugin manager for loading/unloading plugins
28 34
@author Gary Sherman
......
43 49
    void unload();
44 50
    //! Gets the selected plugins
45 51
    std::vector<QgsPluginItem> getSelectedPlugins();
46
    public slots:
52
    //! Set lstPlugins table GUI
53
    void setTable();
54
    //! Resize columns to contents
55
    void resizeColumnsToContents();
56
    //! Sort model by column ascending
57
    void sortModel(int );
58
  public slots:
47 59
    //! Load selected plugins and close the dialog
48 60
    void on_btnOk_clicked();
49 61
    //! Select all plugins by setting their checkbox on
......
52 64
    void on_btnClearAll_clicked();
53 65
    //! Close the dialog
54 66
    void on_btnClose_clicked();
55

  
67
  private:
68
    QStandardItemModel *modelPlugins;
56 69
};
57 70

  
58 71
#endif
src/ui/qgspluginmanagerbase.ui (copia de trabajo)
16 16
   <bool>true</bool>
17 17
  </property>
18 18
  <layout class="QGridLayout" >
19
   <property name="margin" >
19
   <property name="leftMargin" >
20 20
    <number>11</number>
21 21
   </property>
22
   <property name="spacing" >
22
   <property name="topMargin" >
23
    <number>11</number>
24
   </property>
25
   <property name="rightMargin" >
26
    <number>11</number>
27
   </property>
28
   <property name="bottomMargin" >
29
    <number>11</number>
30
   </property>
31
   <property name="horizontalSpacing" >
23 32
    <number>6</number>
24 33
   </property>
34
   <property name="verticalSpacing" >
35
    <number>6</number>
36
   </property>
25 37
   <item row="0" column="0" >
26 38
    <layout class="QHBoxLayout" >
27
     <property name="margin" >
28
      <number>11</number>
29
     </property>
30 39
     <property name="spacing" >
31 40
      <number>6</number>
32 41
     </property>
42
     <property name="leftMargin" >
43
      <number>11</number>
44
     </property>
45
     <property name="topMargin" >
46
      <number>11</number>
47
     </property>
48
     <property name="rightMargin" >
49
      <number>11</number>
50
     </property>
51
     <property name="bottomMargin" >
52
      <number>11</number>
53
     </property>
33 54
     <item>
34 55
      <widget class="QLabel" name="textLabel1" >
35 56
       <property name="text" >
......
52 73
     </item>
53 74
    </layout>
54 75
   </item>
55
   <item row="2" column="0" >
56
    <widget class="Q3ListView" name="lstPlugins" >
57
     <property name="font" >
58
      <font>
59
       <family>Arial</family>
60
       <pointsize>10</pointsize>
61
       <weight>50</weight>
62
       <italic>false</italic>
63
       <bold>false</bold>
64
       <underline>false</underline>
65
       <strikeout>false</strikeout>
66
      </font>
67
     </property>
68
     <column>
69
      <property name="text" >
70
       <string>Name</string>
71
      </property>
72
     </column>
73
     <column>
74
      <property name="text" >
75
       <string>Version</string>
76
      </property>
77
     </column>
78
     <column>
79
      <property name="text" >
80
       <string>Description</string>
81
      </property>
82
     </column>
83
     <column>
84
      <property name="text" >
85
       <string>Library Name</string>
86
      </property>
87
     </column>
88
    </widget>
89
   </item>
90 76
   <item row="1" column="0" >
91 77
    <widget class="QLabel" name="textLabel1_2" >
92 78
     <property name="text" >
......
94 80
     </property>
95 81
    </widget>
96 82
   </item>
97
   <item row="3" column="0" >
83
   <item row="4" column="0" >
98 84
    <layout class="QHBoxLayout" >
99
     <property name="margin" >
100
      <number>11</number>
101
     </property>
102 85
     <property name="spacing" >
103 86
      <number>6</number>
104 87
     </property>
88
     <property name="leftMargin" >
89
      <number>11</number>
90
     </property>
91
     <property name="topMargin" >
92
      <number>11</number>
93
     </property>
94
     <property name="rightMargin" >
95
      <number>11</number>
96
     </property>
97
     <property name="bottomMargin" >
98
      <number>11</number>
99
     </property>
105 100
     <item>
106 101
      <spacer>
107 102
       <property name="orientation" >
......
176 171
     </item>
177 172
    </layout>
178 173
   </item>
174
   <item row="2" column="0" >
175
    <widget class="QTableView" name="lstPlugins" >
176
     <property name="alternatingRowColors" >
177
      <bool>true</bool>
178
     </property>
179
     <property name="sortingEnabled" >
180
      <bool>true</bool>
181
     </property>
182
    </widget>
183
   </item>
179 184
  </layout>
180 185
 </widget>
181 186
 <layoutdefault spacing="6" margin="11" />
182 187
 <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
183
 <customwidgets>
184
  <customwidget>
185
   <class>Q3ListView</class>
186
   <extends>Q3Frame</extends>
187
   <header>q3listview.h</header>
188
  </customwidget>
189
 </customwidgets>
190 188
 <resources/>
191 189
 <connections/>
192 190
</ui>