Pavel Sanda wrote:
> > I understand correctly, is wrong: in the current approach, the graphics
> > params are changed without the user pressing apply (simply if the group
> > widget's content is changes).
>
> no, they are not changed without apply.

Yes, I misunderstood why the reloading of the params was needed.

The problems should be fixed in the attached patch.

Jürgen
Index: src/frontends/qt4/GuiGraphics.cpp
===================================================================
--- src/frontends/qt4/GuiGraphics.cpp	(Revision 28181)
+++ src/frontends/qt4/GuiGraphics.cpp	(Arbeitskopie)
@@ -15,6 +15,7 @@
 #include <config.h>
 
 #include "GuiGraphics.h"
+#include "frontends/alert.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
@@ -246,10 +247,9 @@
 	connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
 	connect(displayscale, SIGNAL(textChanged(const QString&)),
 		this, SLOT(change_adaptor()));
-	connect(groupId, SIGNAL(currentIndexChanged (const QString&)),
-		this, SLOT(change_group(const QString&)));
-	connect(groupId, SIGNAL(editTextChanged(const QString&)),
-		this, SLOT(change_adaptor()));
+	connect(groupCO, SIGNAL(currentIndexChanged(int)),
+		this, SLOT(change_group(int)));
+
 	displayscale->setValidator(new QIntValidator(displayscale));
 
 	bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
@@ -294,24 +294,61 @@
 }
 
 
-void GuiGraphics::change_group(const QString &text)
+void GuiGraphics::change_group(int index)
 {
-	if (text.isEmpty())
+	QString const group = groupCO->itemData(
+		groupCO->currentIndex()).toString();
+
+	if (group.isEmpty()) {
+		changed();
 		return;
+	}
 
-	groupId->blockSignals(true);
+	string grp = graphics::getGroupParams(buffer(), fromqstr(group));
+	if (grp.empty()) {
+		// group does not exist yet
+		changed();
+		return;
+	}
+	
+	// filename might have been changed
+	QString current_filename = filename->text();
 
-	string grp = graphics::getGroupParams(buffer(), fromqstr(text));
+	// group exists: load params into the dialog
+	groupCO->blockSignals(true);
 	InsetGraphicsParams par;
 	InsetGraphics::string2params(grp, buffer(), par);
 	par.filename = params_.filename;
 	params_ = par;
 	paramsToDialog(par);
+	groupCO->blockSignals(false);
+	
+	// reset filename
+	filename->setText(current_filename);
 
-	groupId->blockSignals(false);
+	changed();
 }
 
 
+void GuiGraphics::on_newGroupPB_clicked()
+{
+	docstring newgroup;
+	if (!Alert::askForText(newgroup, _("Enter unique group name:")))
+		return;
+	if (newgroup.empty())
+		return;
+	if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
+		Alert::warning(_("Group already defined!"), 
+			bformat(_("A graphics group with the name '%1$s' already exists."),
+				newgroup));
+		return;
+	}
+	groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
+	groupCO->setCurrentIndex(
+		groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
+}
+
+
 void GuiGraphics::change_bb()
 {
 	bbChanged = true;
@@ -557,16 +594,17 @@
 	graphics::getGraphicsGroups(buffer(), grp);
 	set<string>::const_iterator it = grp.begin();
 	set<string>::const_iterator end = grp.end();
-	groupId->blockSignals(true);
-	groupId->clear();
-	groupId->addItem("");
+	groupCO->blockSignals(true);
+	groupCO->clear();
 	for (; it != end; it++)
-		groupId->addItem(toqstr(*it));
+		groupCO->addItem(toqstr(*it), toqstr(*it));
+	groupCO->insertItem(0, qt_("None"), QString());
 	if (igp.groupId.empty())
-		groupId->setCurrentIndex(-1);
+		groupCO->setCurrentIndex(0);
 	else
-		groupId->setCurrentIndex(groupId->findText(toqstr(igp.groupId), Qt::MatchExactly));
-	groupId->blockSignals(false);
+		groupCO->setCurrentIndex(
+			groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
+	groupCO->blockSignals(false);
 
 	if (igp.width.value() == 0)
 		lengthToWidgets(Width, widthUnit, _(autostr), unitDefault);
@@ -708,7 +746,8 @@
 	// more latex options
 	igp.special = fromqstr(latexoptions->text());
 
-	igp.groupId = fromqstr(groupId->currentText());
+	igp.groupId = fromqstr(groupCO->itemData(
+		groupCO->currentIndex()).toString());
 }
 
 
Index: src/frontends/qt4/GuiGraphics.h
===================================================================
--- src/frontends/qt4/GuiGraphics.h	(Revision 28181)
+++ src/frontends/qt4/GuiGraphics.h	(Arbeitskopie)
@@ -40,8 +40,9 @@
 
 private Q_SLOTS:
 	void change_adaptor();
-	void change_group(const QString &);
+	void change_group(int);
 	void change_bb();
+	void on_newGroupPB_clicked();
 	void on_browsePB_clicked();
 	void on_getPB_clicked();
 	void on_scaleCB_toggled(bool);
Index: src/frontends/qt4/ui/GraphicsUi.ui
===================================================================
--- src/frontends/qt4/ui/GraphicsUi.ui	(Revision 28181)
+++ src/frontends/qt4/ui/GraphicsUi.ui	(Arbeitskopie)
@@ -10,7 +10,9 @@
    </rect>
   </property>
   <property name="sizePolicy" >
-   <sizepolicy vsizetype="Minimum" hsizetype="Minimum" >
+   <sizepolicy>
+    <hsizetype>0</hsizetype>
+    <vsizetype>0</vsizetype>
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
@@ -28,93 +30,6 @@
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item row="1" column="0" >
-    <layout class="QHBoxLayout" >
-     <property name="spacing" >
-      <number>6</number>
-     </property>
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <item>
-      <widget class="QPushButton" name="restorePB" >
-       <property name="text" >
-        <string>&amp;Restore</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>false</bool>
-       </property>
-       <property name="default" >
-        <bool>false</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeType" >
-        <enum>QSizePolicy::MinimumExpanding</enum>
-       </property>
-       <property name="sizeHint" stdset="0" >
-        <size>
-         <width>20</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="okPB" >
-       <property name="text" >
-        <string>&amp;OK</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>true</bool>
-       </property>
-       <property name="default" >
-        <bool>true</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="applyPB" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="text" >
-        <string>&amp;Apply</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>false</bool>
-       </property>
-       <property name="default" >
-        <bool>false</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="closePB" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="text" >
-        <string>Close</string>
-       </property>
-       <property name="autoDefault" >
-        <bool>false</bool>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
    <item row="0" column="0" >
     <widget class="QTabWidget" name="tabWidget" >
      <property name="toolTip" >
@@ -171,7 +86,9 @@
              <bool>true</bool>
             </property>
             <property name="sizePolicy" >
-             <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
+             <sizepolicy>
+              <hsizetype>0</hsizetype>
+              <vsizetype>0</vsizetype>
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
@@ -186,7 +103,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" stdset="0" >
+            <property name="sizeHint" >
              <size>
               <width>61</width>
               <height>20</height>
@@ -203,7 +120,9 @@
              <bool>true</bool>
             </property>
             <property name="sizePolicy" >
-             <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
+             <sizepolicy>
+              <hsizetype>0</hsizetype>
+              <vsizetype>0</vsizetype>
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
@@ -310,7 +229,9 @@
           <item row="0" column="1" >
            <widget class="QLineEdit" name="angle" >
             <property name="sizePolicy" >
-             <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
+             <sizepolicy>
+              <hsizetype>0</hsizetype>
+              <vsizetype>0</vsizetype>
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
@@ -374,7 +295,7 @@
          <property name="orientation" >
           <enum>Qt::Vertical</enum>
          </property>
-         <property name="sizeHint" stdset="0" >
+         <property name="sizeHint" >
           <size>
            <width>20</width>
            <height>40</height>
@@ -398,7 +319,9 @@
           <bool>true</bool>
          </property>
          <property name="sizePolicy" >
-          <sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
+          <sizepolicy>
+           <hsizetype>0</hsizetype>
+           <vsizetype>0</vsizetype>
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
@@ -500,7 +423,7 @@
          <property name="orientation" >
           <enum>Qt::Horizontal</enum>
          </property>
-         <property name="sizeHint" stdset="0" >
+         <property name="sizeHint" >
           <size>
            <width>181</width>
            <height>20</height>
@@ -525,23 +448,41 @@
        <string>LaTe&amp;X and LyX options</string>
       </attribute>
       <layout class="QGridLayout" >
-       <item row="0" column="0" >
-        <widget class="QLabel" name="latexoptionsLA" >
+       <property name="margin" >
+        <number>9</number>
+       </property>
+       <property name="spacing" >
+        <number>6</number>
+       </property>
+       <item row="2" column="0" colspan="3" >
+        <widget class="QCheckBox" name="unzipCB" >
          <property name="toolTip" >
-          <string>Additional LaTeX options</string>
+          <string>Don't uncompress image before exporting to LaTeX</string>
          </property>
          <property name="text" >
-          <string>LaTeX &amp;options:</string>
+          <string>Don't un&amp;zip on export</string>
          </property>
-         <property name="buddy" >
-          <cstring>latexoptions</cstring>
-         </property>
         </widget>
        </item>
+       <item row="0" column="2" >
+        <spacer>
+         <property name="orientation" >
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" >
+          <size>
+           <width>161</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
        <item row="0" column="1" >
         <widget class="QLineEdit" name="latexoptions" >
          <property name="sizePolicy" >
-          <sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
+          <sizepolicy>
+           <hsizetype>0</hsizetype>
+           <vsizetype>0</vsizetype>
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
@@ -551,27 +492,33 @@
          </property>
         </widget>
        </item>
-       <item row="1" column="0" colspan="2" >
-        <widget class="QCheckBox" name="draftCB" >
+       <item row="0" column="0" >
+        <widget class="QLabel" name="latexoptionsLA" >
          <property name="toolTip" >
-          <string>Draft mode</string>
+          <string>Additional LaTeX options</string>
          </property>
          <property name="text" >
-          <string>&amp;Draft mode</string>
+          <string>LaTeX &amp;options:</string>
          </property>
+         <property name="buddy" >
+          <cstring>latexoptions</cstring>
+         </property>
         </widget>
        </item>
-       <item row="2" column="0" colspan="2" >
-        <widget class="QCheckBox" name="unzipCB" >
-         <property name="toolTip" >
-          <string>Don't uncompress image before exporting to LaTeX</string>
+       <item row="5" column="0" colspan="3" >
+        <spacer>
+         <property name="orientation" >
+          <enum>Qt::Vertical</enum>
          </property>
-         <property name="text" >
-          <string>Don't un&amp;zip on export</string>
+         <property name="sizeHint" >
+          <size>
+           <width>354</width>
+           <height>81</height>
+          </size>
          </property>
-        </widget>
+        </spacer>
        </item>
-       <item row="3" column="0" colspan="2" >
+       <item row="3" column="0" colspan="3" >
         <widget class="QGroupBox" name="displayGB" >
          <property name="focusPolicy" >
           <enum>Qt::StrongFocus</enum>
@@ -595,12 +542,43 @@
           <property name="spacing" >
            <number>6</number>
           </property>
-          <item row="0" column="4" >
+          <item row="0" column="1" >
+           <widget class="QLineEdit" name="displayscale" >
+            <property name="enabled" >
+             <bool>true</bool>
+            </property>
+            <property name="sizePolicy" >
+             <sizepolicy>
+              <hsizetype>0</hsizetype>
+              <vsizetype>0</vsizetype>
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="toolTip" >
+             <string>Percentage to scale by in LyX</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="0" >
+           <widget class="QLabel" name="scaleLA" >
+            <property name="toolTip" >
+             <string>Percentage to scale by in LyX</string>
+            </property>
+            <property name="text" >
+             <string>Sca&amp;le on Screen (%):</string>
+            </property>
+            <property name="buddy" >
+             <cstring>displayscale</cstring>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="2" >
            <spacer>
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" stdset="0" >
+            <property name="sizeHint" >
              <size>
               <width>40</width>
               <height>20</height>
@@ -608,10 +586,46 @@
             </property>
            </spacer>
           </item>
-          <item row="1" column="0" >
+         </layout>
+        </widget>
+       </item>
+       <item row="4" column="0" colspan="3" >
+        <widget class="QGroupBox" name="graphicsGroupGB" >
+         <property name="toolTip" >
+          <string>Assign the graphic to a group of graphics that share the same settings</string>
+         </property>
+         <property name="title" >
+          <string>Graphics Group</string>
+         </property>
+         <property name="flat" >
+          <bool>true</bool>
+         </property>
+         <layout class="QGridLayout" >
+          <property name="margin" >
+           <number>9</number>
+          </property>
+          <property name="spacing" >
+           <number>6</number>
+          </property>
+          <item rowspan="2" row="0" column="2" >
+           <spacer>
+            <property name="orientation" >
+             <enum>Qt::Horizontal</enum>
+            </property>
+            <property name="sizeHint" >
+             <size>
+              <width>121</width>
+              <height>51</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+          <item row="0" column="0" >
            <widget class="QLabel" name="label" >
             <property name="sizePolicy" >
-             <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+             <sizepolicy>
+              <hsizetype>0</hsizetype>
+              <vsizetype>0</vsizetype>
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
@@ -620,72 +634,141 @@
              <string>Graphics having the same group name will share the same parameters</string>
             </property>
             <property name="text" >
-             <string>Grou&amp;p Name:</string>
+             <string>Assigned to grou&amp;p:</string>
             </property>
             <property name="buddy" >
-             <cstring>groupId</cstring>
+             <cstring>groupCO</cstring>
             </property>
            </widget>
           </item>
-          <item row="0" column="1" >
-           <widget class="QLineEdit" name="displayscale" >
-            <property name="enabled" >
-             <bool>true</bool>
-            </property>
-            <property name="sizePolicy" >
-             <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
-              <horstretch>0</horstretch>
-              <verstretch>0</verstretch>
-             </sizepolicy>
-            </property>
+          <item row="1" column="1" >
+           <widget class="QPushButton" name="newGroupPB" >
             <property name="toolTip" >
-             <string>Percentage to scale by in LyX</string>
+             <string>Click to define a new graphics group</string>
             </property>
-           </widget>
-          </item>
-          <item row="0" column="0" >
-           <widget class="QLabel" name="scaleLA" >
-            <property name="toolTip" >
-             <string>Percentage to scale by in LyX</string>
-            </property>
             <property name="text" >
-             <string>Sca&amp;le on Screen (%):</string>
+             <string>De&amp;fine new group...</string>
             </property>
-            <property name="buddy" >
-             <cstring>displayscale</cstring>
-            </property>
            </widget>
           </item>
-          <item row="1" column="1" >
-           <widget class="QComboBox" name="groupId" >
+          <item row="0" column="1" >
+           <widget class="QComboBox" name="groupCO" >
             <property name="toolTip" >
-             <string>Group Name to be set up from the current parameters. Use context menu to assign the existing one.</string>
+             <string>Select an existing group for the current graphics.</string>
             </property>
             <property name="editable" >
-             <bool>true</bool>
+             <bool>false</bool>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
-       <item row="5" column="1" >
-        <spacer>
-         <property name="orientation" >
-          <enum>Qt::Vertical</enum>
+       <item row="1" column="0" colspan="3" >
+        <widget class="QCheckBox" name="draftCB" >
+         <property name="toolTip" >
+          <string>Draft mode</string>
          </property>
-         <property name="sizeHint" stdset="0" >
-          <size>
-           <width>354</width>
-           <height>81</height>
-          </size>
+         <property name="text" >
+          <string>&amp;Draft mode</string>
          </property>
-        </spacer>
+        </widget>
        </item>
       </layout>
      </widget>
     </widget>
    </item>
+   <item row="1" column="0" >
+    <layout class="QHBoxLayout" >
+     <property name="margin" >
+      <number>0</number>
+     </property>
+     <property name="spacing" >
+      <number>6</number>
+     </property>
+     <item>
+      <widget class="QPushButton" name="restorePB" >
+       <property name="text" >
+        <string>&amp;Restore</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>false</bool>
+       </property>
+       <property name="default" >
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer>
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType" >
+        <enum>QSizePolicy::MinimumExpanding</enum>
+       </property>
+       <property name="sizeHint" >
+        <size>
+         <width>20</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="okPB" >
+       <property name="text" >
+        <string>&amp;OK</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>true</bool>
+       </property>
+       <property name="default" >
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="applyPB" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text" >
+        <string>&amp;Apply</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>false</bool>
+       </property>
+       <property name="default" >
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="closePB" >
+       <property name="sizePolicy" >
+        <sizepolicy>
+         <hsizetype>0</hsizetype>
+         <vsizetype>0</vsizetype>
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text" >
+        <string>Close</string>
+       </property>
+       <property name="autoDefault" >
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
  <customwidgets>

Reply via email to